Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //G6
- #include <cstdlib>
- #include <cstdio>
- int valid(int num, int base);
- long base10(long num, int base);
- long conv(long num,int base);
- int main(int argc, char** argv) {
- long num,acu;
- int cont,base;
- while (1){
- cont=scanf("(%d)%ld",&base,&num);
- if (cont==2){
- if (valid(num,base)){
- acu+=base10(num,base);
- printf("(%d)%ld\t",base,num);
- }
- scanf("%d",&num);
- }else if (cont==-1) {break;
- }else{
- acu=conv(acu,base);
- printf("(%d)%ld\n",base,acu);
- acu=0;
- }
- }
- return 0;
- }
- int valid(int num, int base){
- int b=1;
- while ((num%10)<base && num!=0){
- num=num/10;
- }
- if (num!=0) b=0;
- return b;
- }
- long base10(long num, int base){
- long aux=0; int mul=1,cif;
- do {
- cif=num%base;
- aux+=cif*mul;
- mul*=base;
- }while (num=num/10);
- return aux;
- }
- long conv(long num,int base){
- long aux=0,res;
- int mul=1;
- do {
- res=num%base;
- aux+=mul*res;
- mul*=10;
- }while (num=num/base);
- return aux;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement