Describe
LN wants to know if everyone is good at elementary school math.
Now he wants you to figure out a few numbers and.
Can you handle it?
-
-
Input
-
-
multiple sets of test data
A set of test data rows.
Output
A number sum representing the result. (Guaranteed within the Int range)
Sample input
2 3 55 6 7 81 2 3 4 5 6 7 8 9 10
Sample output
102655
The code is as followsThe point of this problem is very clear, is the processing of input data. If the number of n for each set of test data is obtained, the sum is very simple and guaranteed to be within the int range. If you enter with a normal integer, there is no apparent distinction between each set of test data. So we should have an instinct to translate the strings into a string and then sum them.
#include <stdio.h> #include <string.h>int main () {char a[100000];int i,sum,t;while (gets (a)) {Sum=0;t=0;for (i=0;a[i];i++) {if (a[i]== ') {t+=sum;sum=0;} elsesum=sum*10+ (a[i]-' 0 ');} t+=sum;printf ("%d\n", t);} return 0;}
Sum to soft mercy