Advertisement
saira12tabassum19

Untitled

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