cf C. George and Number

时间:2024-04-11 11:33:59

http://codeforces.com/problemset/problem/387/C

题意:给你一个大数,让你求个集合,可以通过操作得到这个数,求集合中个数最大值,操作 :从集合中任意取两个数,大的数放在前面小的数放在后面组成一个数在重新放入集合中,经过重复的操作,集合中只剩一个数,这个数就是给你的数。

思路:要求个数最大,可以让这个大数的每一个数字为集合中的一个数,但是集合中不能有0,所以在连续的0前面要连着一个非零的数。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; char str[]; int main()
{
while(scanf("%s",str)!=EOF)
{
int k=strlen(str);
int ans=;
for(int i=k-; i>=; i--)
{
int j=i;
while(str[i]=='') i--;
if(j-i+<i) ans++;
else if(j-i+==i)
{
bool flag=false;
for(int k=; k<i; k++)
{
if(str[k]>str[k+i]&&str[k]!=str[k+i])
{
flag=true;
ans++;
break;
}
else if(str[k]<str[k+i]&&str[k]!=str[k+i])
{
ans++;
i=;
flag=true;
break;
}
}
if(!flag) ans++;
}
else if(j-i+>i)
{
i=;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}