CodeForces 1009B(思路)

本来打算打打cf找找自信的,结果,死在了一个2000多人都做出来的B上,写了170多行wr在t4,大佬十几行代码就过了,难受啊。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
string ss;
int main()
{
    cin >> ss;
    int ans=0;
    string hh="";
    for(int i=0;i<ss.length();i++)
    {
        if(ss[i]=='1') ans++;//关键就在于,只有1是可以随便移动的,而且最小字典序,必出现在2之前,否则就在0之后
        else hh.push_back(ss[i]);
    }
    for(int i=0;i<hh.length();i++)
    {
        if(hh[i]=='2')
        {
            for(int j=1;j<=ans;j++)
                printf("1");
            ans=0;
        }
        printf("%c",hh[i]);
    }
    for(int i=1;i<=ans;i++)
        printf("1");
    printf("\n");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Wangwanxiang/p/9341460.html