codeforces 387C George and Number

直接从后面往前面扫,如果前面大,就把后面丢掉

再把前面剩下的进行类似的处理就行;

#include<cstdio>
#include<iostream>
#include<cstring>
#define maxn 100005
using namespace std;

char s[maxn];

int main()
{
    cin>>s;
    int l=strlen(s);
    int head=l-1,tail=l-1;
    int cnt=1;
    while(1)
    {
        while(s[head]=='0')head--;
        if(head>(tail-head+1))
        {
            cnt++;
            head--;
            tail=head;
        }
        else if(head==(tail-head+1))
        {
            bool flag=1;
            for(int i=0; i<head; i++)
            {
                if(s[i]<s[head+i])
                {
                    flag=0;
                    break;
                }
            }
            if(flag==1)
            {
                cnt++;
                head--;
                tail=head;
            }
            else break;
        }
        else break;
        if(head==0)break;
    }
    printf("%d
",cnt);
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3564396.html