fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <stdlib.h>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8. string ans;
  9. int counter = 0;
  10. bool Alpha_check(int val){
  11. if(val>9){
  12. return true;
  13. }
  14. else{
  15. return false;
  16. }
  17. }
  18. char Al_conv(int val){
  19. if(Alpha_check(val)){
  20. return char(val+55);
  21. }
  22. else {
  23. return char((val-48)+'0');
  24. }
  25. }
  26. void add_On(int c){
  27. ans += (Al_conv(c));
  28. counter++;
  29. }
  30.  
  31. int div_loop(int num, int base){
  32. int temp = int(num/base);
  33. int temp2 = int(num%base);
  34. add_On(temp2);
  35. return temp;
  36. }
  37.  
  38. void add_line(int number){
  39. ans[number] = '\n';
  40. }
  41.  
  42. int main(){
  43. int init_base, in_num = 0;
  44. cin >> init_base;
  45. cin >> in_num;
  46. do{
  47. string rem;
  48. int init_count = counter;
  49. while(in_num!=0){
  50. in_num = div_loop(in_num,init_base);
  51. }
  52. int helper = int(floor((counter-init_count)/2));
  53. for(int y = 0; y < helper; y++){
  54. int temp = ans[y+init_count];
  55. ans[y+init_count] = ans[(counter-1)-y];
  56. ans[(counter-1)-y] = temp;
  57. }
  58. add_line(counter);
  59. counter++;
  60. cin >> in_num;
  61. }while(in_num!=-1);
  62. ans[counter] = '\0';
  63. for(int gh = 0; gh < ans.length(); gh++){
  64. cout << ans[gh];
  65. }
  66. cout << endl;
  67.  
  68.  
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0s 16064KB
stdin
2
42
1
-1
stdout