Miyu original, post Please note: Reprinted from __________ White House
Question address:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1230
Description:
Purely simulated questions ........
Code:
Code
# Include < Iostream >
# Include < String >
# Include < Algorithm >
# Include < Cstdlib >
# Include < Cstdio >
# Include < Cstring >
Using Namespace STD;
String A, B;
Int Prim [ 40 ] = { 1 , 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 , 107 , 109 , 113 };
Int X [ 30 ], Y [ 30 ];
Int Main (){
While (CIN > A > B, ! = " 0 " && B ! = " 0 " ){
Memset (X, 0 , Sizeof (X ));
Memset (Y, 0 , Sizeof (Y ));
Int J = 1 , K = 1 ;
For ( Int I = 0 ; I < A. Size (); ++ I ){
If (A [I] ! = ' , ' ){
X [J] = X [J] * 10 + A [I] - ' 0 ' ;
} Else {
++ J;
}
}
For ( Int I = 0 ; I < B. Size (); ++ I ){
If (B [I] ! = ' , ' ){
Y [k] = Y [k] * 10 + B [I] - ' 0 ' ;
} Else {
++ K;
}
}
Reverse (x + 1 , X + J + 1 );
Reverse (Y + 1 , Y + K + 1 );
Int F = 0 ;
Int M = J;
Int Mm = K;
Int T = 0 ;
If (M > Mm ){
Swap (M, mm );
T = 1 ;
}
// Cout <m <"<mm <Endl;
Int Z [ 30 ];
For ( Int I = 1 ; I <= M; ++ I ){
Z [I] = X [I] + Y [I] + F;
F = Z [I] / Prim [I];
Z [I] % = Prim [I];
}
Z [m + 1 ] = 0 ;
For ( Int I = M + 1 ; I <= Mm; ++ I ){
Int Temp = 0 ;
If ( ! T) temp = Y [I];
Else Temp = X [I];
Z [I] = Temp + F;
F = Z [I] / Prim [I];
Z [I] % = Prim [I];
}
If (F ){
Z [ ++ Mm] = F;
}
For ( Int I = Mm; I > 0 ; -- I ){
Printf (I = Mm ? " % D " : " , % D " , Z [I]);
}
Putchar ( 10 );
}
Return 0 ;
}