Home > Back-end >  Why I input a large integer output fixed si liu, it is wrong, a stack is used to implement the PAT s
Why I input a large integer output fixed si liu, it is wrong, a stack is used to implement the PAT s

Time:11-12

Read in a positive integer n, calculate the sum of its digits, use Chinese pinyin to write and every digital,
#include
#include
using namespace std;
Long getsum (n) {
Int sum=0;
While (n> 0 {
Sum=sum + n % 10;
N=n/10;
}
Return the sum.
}
Void show (n) {
StackLong a;
Do {
A=n % 10;
Supachai panitchpakdi ush (a);
N=n/10;
} while (n> 0);
while(! S.e mpty ()) {
Long b=s.t op ();

The switch (b) {
Case 0: cout<" Ling "& lt; <"'; break;
Case 1: cout<" Yi "& lt; <"'; break;
Case 2: cout<" Er "& lt; <"'; break;
Case 3: cout<" SAN "& lt; <"'; break;
Case 4: cout<" Si "& lt; <"'; break;
Case 5: cout<" Wu "& lt; <"'; break;
Case 6: cout<" Liu "& lt; <"'; break;
Case 7: cout<" Qi "& lt; <"'; break;
Case 8: cout<" Ba "& lt; <"'; break;
Case 9: cout<" Jiu "& lt; <"'; break;
}
Supachai panitchpakdi op ();
}
}

Int main () {
Long a;
Cin> a;
Long b=getsum (a);
Show (b);
return 0;
}
  • Related