b.minimumternarystringtimelimitpertest1secondmemorylimitpertest 256 megabytesinputstandardinputoutputstandardoutputyouaregiven
youcanswapanytwoadjacent (consecutive ) characters'0'and'1) ) I.e.replace ' 01 ' with ' 10 ' or vice versa ) oranytwa
For example,forstring ' 010210 ' wecanperformthefollowingmoves 3360
' 010210''100210 '; ' 010210''001210 '; ' 010210''010120 '; ' 010210 '' 010201 '.notethanyoucannotswap ' 02 '' 20 ' and vice versa.youcannotperformanyotheroperationswitheght
youtaskistoobtaintheminimumpossible (lexico图形) stringbyusingtheseswapsarbitrarynumberoftimes (possibly,zero )。
stringaaislexicographicallylessthanstringbb (ifthereexistssomepositionii (1I| a|www
inputthefirstlineoftheinputcontainsthestringssconsistingonlyofcharacters '0'、'1' and '2'、ITSlengthisbetween11and105111
outputprintasinglestring-theminimumpossible (lexico graphically ) stringyoucanobtainbyusingtheswapsdescribedabovearbitrarynurynus
examplesinputcopy 100210 output copy 001120 input copy 1122121 output copy 111222 input copy 20 output copy 20q wq;
这个问题是在字符串中插入1; 两年前一定是一年
代码,例如fzdmp
# include bits/stdc.htypedeflonglongll; 用户命名空间STD; int main () { string s; cin s; ll one=0; for(intI=0; i s.length (; I ) if(s(I )=='1' ) one; }for(intI=0; i s.length (; I ) if(s(I )=='0' ) cout 0; if(s[I]=='2' ) while(one ) ) { one--; 出局1; } cout 2; }while(one ) ) one----; 出局1; } cout endl; 返回0; }