fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. string onceInATram(int x) {
  6. // Complete this function
  7.  
  8.  
  9.  
  10.  
  11. int a,x1,y,z,i,i1,z1,z2;
  12. string s,s1,s3;
  13. a=x/1000;
  14. y=x%1000;
  15. x1=a;
  16.  
  17. while(x1>0){
  18. z=z+x1%10;
  19. x1=x1/10;
  20. }cout<<"z="<<a<<" "<<y<<" "<<z;
  21.  
  22. for(int i=y+1;i<1000;i++)
  23. {
  24. int i2=i;
  25.  
  26. while(i2>0)
  27. {
  28. z1=z1+i2%10;
  29. i2=i2/10;
  30. if( z1 ==z ){
  31. z2=z1;
  32. cout << "total="<<z1<<" num "<<i1<< endl;
  33.  
  34. } i1=i;
  35.  
  36. if( z1 ==z){break;
  37. } }z1=0;i2=0; if(z2==z){break;
  38. }} s = to_string(i1);
  39. s1 = to_string(x);
  40. s3=s1+s;
  41. string result=stoi(s3);
  42. cout << "\n"<<x;
  43.  
  44. }
  45.  
  46. int main() {
  47. int x=555555;
  48. // cin >> x;
  49. // string result = onceInATram(x);
  50. cout << "result"<<result << endl;
  51. return 0;
  52. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘std::__cxx11::string onceInATram(int)’:
prog.cpp:41:41: error: conversion from ‘int’ to non-scalar type ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ requested
                       string result=stoi(s3);
                                     ~~~~^~~~
prog.cpp: In function ‘int main()’:
prog.cpp:50:23: error: ‘result’ was not declared in this scope
     cout << "result"<<result << endl;
                       ^~~~~~
stdout
Standard output is empty