1,0 2,1 4,2,0 1,2,0 1 10,6,4,2,1 0 0
1,0,1 1,1,1,0 1,0,0,0,0,0
#include <stdio.h> #include <string.h> int sam[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103}; int arr[3][26], id, id2, id3, len; char s1[200], s2[200], *p; int main(){ while(scanf("%s%s", s1, s2) == 2 && s1[0] != '0'){ memset(arr, 0, sizeof(arr)); p = strtok(s1, ","); id2 = id = 0; while(p != NULL){ sscanf(p, "%d", &arr[0][++id]); p = strtok(NULL, ","); } p = strtok(s2, ","); while(p != NULL){ sscanf(p, "%d", &arr[1][++id2]); p = strtok(NULL, ","); } len = id3 = id > id2 ? id : id2; while(id && id2) arr[2][id3--] = arr[0][id--] + arr[1][id2--]; while(id) arr[2][id3--] = arr[0][id--]; while(id2) arr[2][id3--] = arr[1][id2--]; for(int i = len, j = 1; i; --i, ++j){ if(arr[2][i] >= sam[j]){ ++arr[2][i-1]; arr[2][i] -= sam[j]; } } int i; if(arr[2][0] == 0){printf("%d", arr[2][1]); i = 2;} else {printf("%d", arr[2][0]); i = 1;} while(i <= len) printf(",%d", arr[2][i++]); printf("\n"); } return 0; }
原文:http://blog.csdn.net/u012846486/article/details/27806741