简言之就是排序,将不含0的区间进行从大到小的排序,然后输出即可。
Run Time: 0sec
Run Memory: 304KB
Code length: 631Bytes
SubmitTime: 2012-01-30 20:08:46
// Problem#: 1783
// Submission#: 1202694
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <cstdio>
#include <algorithm>
using namespace std;
bool cmp( char c1, char c2 ) { return c1 > c2; }
int main()
{
int L;
char s[ 101 ];
int i, j;
scanf( "%d", &L );
while ( L-- ) {
scanf( "%s", s );
for ( i = 0; s[ i ] != '\0'; i = j ) {
for ( j = i + 1; s[ j ] != '\0'; j++ ) {
if ( s[ j ] == '0' )
break;
}
sort( s + i, s + j, cmp );
if ( s[ j ] == '0' ) {
while ( s[ j ] == '0' )
j++;
}
}
printf( "%s\n", s );
}
return 0;
}