sicily 1783 Large is Better

题目不难,但是有些细节还是要注意的.....很容易wrong answer,如果你碰到WA,试试123012400198和1234这两个测试用例吧!

 

// source code of submission 766632, Zhongshan University Online Judge System #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int cmp(int a,int b) { return a > b; } int main() { int t,i,k,len,zero[106]; char s[106]; scanf("%d",&t); while(t--) { scanf("%s",s); k = 0,len = strlen(s); for(i = 0;i < len;i++) if(s[i] == '0') zero[k++] = i; if(k==0) { sort(s,s+len,cmp); printf("%s\n",s); } else { if(zero[0]>=2) sort(s,s+zero[0],cmp); for(i = 0;i < k-1;i++) if(zero[i+1]-zero[i] > 2) sort(s+zero[i]+1,s+zero[i+1],cmp); if(zero[k-1]<len-2) sort(s+zero[k-1]+1,s+len,cmp); printf("%s\n",s); } } return 0; }

你可能感兴趣的:(测试)