POJ 2305 Basic remains

http://poj.org/problem?id=2305

和2105一样的,练习库函数,注意itoa在g++下面是不存在的。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <stack>
 5 using namespace std;
 6 int main()
 7 {
 8     int b;
 9     char p[1020],m[10];
10     while(scanf("%d",&b)!=EOF) {
11         if(b==0)    return 0;
12         scanf("%s%s",p,m);
13         int __m=strtol(m,0,b);
14         int res=0;
15         int len=strlen(p);
16         int i;
17         for(i=0;i<len;i++) {
18             res=res*b+p[i]-'0';
19             res%=__m;
20         }
21         if(res==0) {
22             printf("0\n");
23         } else {
24             stack<int> S;
25             while(res) { 
26                 S.push(res%b);
27                 res/=b;
28             }
29             while(!S.empty()) {
30                 printf("%d",S.top());
31                 S.pop();
32             }
33             putchar('\n');
34         }
35 
36     }
37     return 0;
38 }
原文地址:https://www.cnblogs.com/yangce/p/2893079.html