Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用字符串输入了怎么还是不行呢??#include <stdio.h> int num(char a[],int n) {int i,j,s=0; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(a[i]>a[j]) s++; return s;} void swap(char *a,char *b) {char c; c=*a; *a=*b; *b=c;} main() { char input[100][53]; int i,j,m,n,t; scanf("%d %d",&n,&m); for(i=0;i<m;i++) {scanf("%s",input[i]); input[i][n+1]=num(input[i],n); input[i][n+2]=i;} for(j=0;j<m;j++) for(i=j+1;i<m;i++) if(input[j][n+1]>input[i][n+1]) {swap(&input[j][n+1],&input[i][n+1]); swap(&input[j][n+2],&input[i][n+2]);} for(j=0;j<m;j++) for(i=j+1;input[j][n+1]==input[i][n+1];i++) if(input[j][n+2]>input[i][n+2]) {swap(&input[j][n+1],&input[i][n+1]); swap(&input[j][n+2],&input[i][n+2]);} for(i=0;i<m;i++) printf("%s\n",input[input[i][n+2]]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator