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 |
郁闷不知道为什么老是wronganswer哪个好心的帮我看看啊#include <stdio.h> #include <string.h> #define MAX 100000 int calculate(char *string,int n){ int i,j,sort; char c; sort=0; for(i=0;i<n+1;i++){ c=string[i]; for(j=i+1;j<n;j++){ if(c>string[j])++sort; } } return sort; } void main(){ int n,m,i,*sorts; int min,j; char **strings,buf; scanf("%d%d",&n,&m); scanf("%f",&buf); strings =new char*[m]; for(i=0;i<m;i++){ strings[i]=new char [n]; strcpy(strings[i],""); for(j=0;j<n;j++) scanf("%c",&strings[i][j]); scanf("%c",&buf); } sorts =new int [m]; for(i=0;i<m;i++){ sorts[i]=calculate(strings[i],n); } for(i=0;i<m;i++){ min=0; for(j=0;j<m;j++){ if(sorts[j]<sorts[min]){ min=j; } } printf("%s\n",strings[min]); sorts[min]=MAX; } for(i=0;i<m;i++)delete [] strings[i]; delete[] strings; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator