UVA 11258 - String Partition

注意用long long就可以了

#include<stdio.h>

#include<string.h>

#define INF 0x7fffffff



char s[210];

int n;

long long f[210];



void solve()

{

    memset(f,0,sizeof(f));

    int len = strlen(s);

    for(int i = 0; i < len; i ++)

    {

        if(s[i] == '0')

        {

            if(f[i] > f[i+1])

                f[i+1] = f[i];

        }

        else

        {

            long long t = 0;

            for(int j = i; j < len; j ++)

            {

                t = t*10+s[j]-'0';

                if(t > INF) break;

                if(f[i] + t > f[j+1])

                    f[j+1] = f[i] + t;

            }

        }

    }    

    printf("%lld\n",f[len]);

}



int main()

{

    while(~scanf("%d",&n))

    while(n --)

    {

        scanf("%s",s);

        solve();

    }

    return 0;

}

你可能感兴趣的:(partition)