标签:
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAX = 1000; int t1[MAX][MAX],t2[MAX][MAX]; int x[MAX],y[MAX]; int main() { //freopen ("K.in", "r", stdin); int T; scanf("%d",&T); int xy = 1; while(T--){ memset(t1,0,sizeof(t1)); memset(t2,0,sizeof(t2)); int n,m; scanf("%d%d",&n,&m); int temp1 = 1; while(n){ x[temp1++] = n%10; n/=10; } int temp2 = 1; while(m){ y[temp2++] = m%10; m/=10; } sort(x+1,x+temp1); sort(y+1,y+temp2); int x0 = 1; temp1 --; temp2 --; do{ for(int i = 1; i <= temp1;i++){ t1[x0][i] = x[i]; } x0++; } while(next_permutation(x+1,x+temp1+1)); int y0 = 1; do{ for(int i = 1; i <= temp2; i++) t2[y0][i] = y[i]; y0++; }while(next_permutation(y+1,y+temp2+1)); //printf ("x0: %d y0: %d\n", x0, y0); int sum1 = 0; for(int i = 1; i <= x0;i++){ for(int j = 1; j <= y0;j++){ int sum = 0; if(t1[i][1] == 0 || t2[j][1] == 0) continue; int k = 1; int temp3 = temp1; int temp4 = temp2; if (temp3 > temp4) { while(temp3 > temp4){ sum = sum*10 + t1[i][k]; temp4++; k++; } } if (temp4 > temp3) { while(temp4 > temp3){ sum = sum*10 + t2[j][k]; temp3++; k++; } } if(temp1 > temp2){ for(int m1 = k,m2 = 1; m1 <=temp3;m1++,m2++) sum = (t1[i][m1] + t2[j][m2])%10 + sum * 10; sum1 = max(sum1,sum); } else { for(int m1 = 1,m2 = k; m2 <= temp4; m1++,m2++) sum = (t1[i][m1] + t2[j][m2])%10 + sum *10; sum1 = max(sum1,sum); } } } printf("Case #%d:",xy++); printf(" %d\n",sum1); } return 0; }
HUST信心大涨迎省赛之《我要冲银牌》K——字符串——Kia's Calculation
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4439888.html