今天秒掉此题,运气比较好,特此纪念一下,当然,这是一道水题,代码如下:
#include <iostream>#include <cmath>using namespace std;const int n = 110;int a[n];int s = 0;void prim(int *a){ bool b[n]; memset(b,true,sizeof(b)); for (int i = 4; i<= n; i+=2){ b[i]=false; } for (int i = 3; i <= sqrt(n); i +=2){ if (b[i]){ for (int j = 2*i; j <= n; j +=i){ b[j] = false; } } } s = 0; for (int i = 2; i <= n; i ++){ if (b[i]){ a[s++] = i; } } }int isNum(char x){ if (x >= '0' && x <= '9')return 1; return 0; }int main(){ prim(a); char x[100], y[100]; while (EOF != scanf("%s",x)){ scanf("%s",y); if (!(strcmp("0",y) + strcmp("0",x)))break; int lenx = strlen(x)-1, leny = strlen(y)-1; int h[100]={0}; int kk = 0; while(lenx !=-1 && leny != -1){ if (isNum(x[lenx]) && isNum(y[leny])){ h[kk++] = x[lenx]-'0' + y[leny]-'0'; if (isNum(y[leny-1])){h[kk-1]+=10*(y[leny-1]-'0');leny--;} if (isNum(x[lenx-1])){h[kk-1]+=10*(x[lenx-1]-'0');lenx--;} } lenx--;leny--; } while(lenx !=-1){ if (isNum(x[lenx])){ h[kk++] = x[lenx]-'0'; if (isNum(x[lenx-1])){h[kk-1]+=10*(x[lenx-1]-'0');lenx--;} } lenx--; } while(leny !=-1){ if (isNum(y[leny])){ h[kk++] = y[leny]-'0'; if (isNum(y[leny-1])){h[kk-1]+=10*(y[leny-1]-'0');leny--;} } leny--; } for (int i = 0;i < kk; i ++){ if (h[i] >= a[i]){ int temp = h[i]/a[i]; h[i]%=a[i]; h[i+1]+=temp; } } while (h[kk])kk++; for (int i = kk-1;i >= 0;i --){ printf("%d",h[i]); if(i!=0)printf(","); } printf("/n"); } return 0; }