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 |
哥哥们 本机测试没错误啊 算法可能有点烂 小弟刚学完C 给看看为什么WA#include<stdio.h> #include<string.h> int main() { char str[102][55],temp[55]; int m,n,q[102],min,s,i,k,a,b,c,d,e; scanf("%d%d",&n,&m); for(i=0;i<=m-1;i++) scanf("%s",str[i]); for(k=0;k<=m-1;k++) { q[k]=0; for(a=0;a<=n-2;a++) for(b=a+1;b<=n-1;b++) if(str[k][a]>str[k][b]) q[k]++; } for(c=0;c<=n-1;c++) for(d=0;d<=m-2;d++) if(q[d]>q[d+1]) { strcpy(temp,str[d]); strcpy(str[d],str[d+1]); strcpy(str[d+1],temp); s=q[d]; q[d]=q[d+1]; q[d+1]=s; } for(e=0;e<=m-1;e++) { printf("%s\n",str[e]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator