Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

cuo de

Posted by 2012xie at 2012-10-20 17:44:00 on Problem 1007
#include<stdio.h>
void strcpy(char a1[],char a2[])
{
    int i;
    char t;
    for(i=0;i<50;i++)
    {
        t=a1[i];
        a1[i]=a2[i];
        a2[i]=t;
    }
}
void swap(char a1[],char a2[])
{
    char t[100]={0};
    strcpy(t,a1);
    strcpy(a1,a2);
    strcpy(a2,t);
}
int sort(char a[50],int n)
{
    int i,t,j=0;
    for(i=0;i<n;i++)
    {
        t=(int)a[i]-a[i+1];
        if(t>0)
        {t=(int)a[i]-a[i+1];
        j+=t;}
    }
    return j;
}
main()
{
    int m,n,i,j;
    char a[100][50]={0};
    int b[50]={0};
    scanf("%d %d",&m,&n);
   for(i=0;i<n;i++)
    scanf("%s",a[i]);
    for(i=0;i<n;i++)
    b[i]=sort(a[i],n);
    for(i=0;i<n;i++)
    printf("%d\n",b[i]);
    for(i=0;i<m-1;i++)
    for(j=0;j<m-1;j++)
    if(b[i]>b[i+1])
    swap(a[i],a[i+1]);
    for(i=0;i<=m;i++)
    printf("%s\n",a[i]);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator