-
Title Description:
-
Given A and n, computes the A+AA+AAA+A...A (n a).
-
Input:
-
There are several groups of test data, input a,n (1<=a<=9,1<=n<=100).
-
Output:
-
For each set of inputs, output the results.
-
Sample input:
-
1 10
-
-
Sample output:
-
1234567900
The difficulty of this problem is to deal with a long, long number of sums
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <string>5#include <cmath>6 #defineMAX 3027 8 intSum[max];9 intTemp[max];Ten One voidcalsum () { A intCI =0; - for(inti =0; I < max;i++) { - intBen = (Sum[i] + temp[i] + ci)%Ten; theCI = (Sum[i] + temp[i] + ci)/Ten; -Sum[i] =ben; - } - } + intMainintargcChar Const*argv[]) - { + inta, n; A while(SCANF ("%d%d", &a,&n)! =EOF) { at for(inti =0; i < MAX; i++) { -Sum[i] =0; - } - for(inti =1; I <= N; i++) { - for(intj =0; J < MAX; J + +) { -TEMP[J] =0; in } - for(intj =0; J < I; J + +) { toTEMP[J] =A; + } - calsum (); the } * BOOLIsbegin =false; $ for(inti = MAX; I >=0; i--) {Panax Notoginseng if(Isbegin = =false&& Sum[i]! =0) { -Isbegin =true; theprintf"%d", Sum[i]); + } A Else if(isbegin) { theprintf"%d", Sum[i]); + } - } $printf"\ n"); $ } - return 0; -}
Nine degrees OJ topic 1051: Digital Ladder summation