Advertisement
saira12tabassum19

Untitled

Oct 4th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string trans(int b,int n)
  4. {
  5.  
  6. string s="";
  7. while(n!=0)
  8. { char l=(n%b)+'0'; int c=n%b;
  9.  
  10. if(c==10)s='A'+s;
  11. else if(c==11)s='B'+s;
  12. else if(c==12)s='C'+s;
  13. else if(c==13)s='D'+s;
  14. else if(c==14)s='E'+s;
  15. else if(c==15)s='F'+s;
  16. else {s=l+s;}
  17. n=n/b;
  18. }
  19.  
  20. return s;
  21.  
  22.  
  23. }
  24. int main()
  25. {
  26.  
  27.  
  28. int t;
  29. cin>>t; int b,n;
  30. for(int i=1;i<=t;i++)
  31. {
  32.  
  33. cin>>b>>n;
  34. if(b>n)cout<<"Case "<<i<<": "<<trans(n,b)<<endl;
  35. else {cout<<"Case "<<i<<": "<<trans(b,n)<<endl;}
  36.  
  37.  
  38.  
  39.  
  40. }
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement