fork download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string>
  4. #include<stdlib.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. int test;
  11. scanf("%d\n",&test);
  12. while(test--)
  13. {
  14. char str[10000];//removes string as "atoi" function works on c-equivalent strings
  15. //cin>>str;
  16. //I think the endl operation mightalso be causing some trouble
  17.  
  18. gets(str);
  19. //Main part causing RTE
  20. getchar();//takes care of extra space sfter the input
  21. char s1[1000],s2[1000],s3[1000];
  22. int j=0,k=0,l=0,p=0,occ_of_plus,occ_of_equal,occ_of_m;
  23. for(int i=0;str[i]!='+';i++)//finding occurence of + in the string
  24. {
  25. s1[j]=str[i];
  26. j++;
  27. }
  28. s1[j]='\0';
  29.  
  30. j++;
  31. for(int i=j;str[i]!='=';i++)//finding occurence of '=' in string
  32. {
  33. s2[k]=str[i];
  34. k++;
  35. p=i;
  36. }
  37. s2[k]='\0';
  38.  
  39. k++;
  40. for(int i=p+2;str[i]!='\0';i++)
  41. {
  42. s3[l]=str[i];
  43. l++;
  44. }
  45. s3[l]='\0';
  46. l++;
  47. //cout<<s1<<s2<<s3<<"\n";
  48. for(int i=0;str[i]!='\0';i++)
  49. {
  50. if(str[i]=='m')
  51. occ_of_m=i+1;
  52. if(str[i]=='+')
  53. occ_of_plus=i+1;
  54. if(str[i]=='=')
  55. occ_of_equal=i+1;
  56. }
  57. if(occ_of_m>occ_of_equal)
  58. {
  59. int a=atoi(s1);
  60. int b=atoi(s2);
  61. cout<<a<<" + "<<b<<" = "<<a+b;
  62. }
  63. else if(occ_of_m>occ_of_plus&&occ_of_m<occ_of_equal)
  64. {
  65. int a=atoi(s1);
  66. int b=atoi(s3);
  67. cout<<a<<" + "<<b-a<<" = "<<b;
  68. }
  69. else if(occ_of_m<occ_of_plus)
  70. {
  71. int a=atoi(s2);
  72. int b=atoi(s3);
  73. cout<<b-a<<" + "<<a<<" = "<<b;
  74. }
  75. printf("\n");
  76. }
  77. return 0;
  78. }
Success #stdin #stdout 0s 3344KB
stdin
3

23 + 47 = machula

3247 + 5machula2 = 3749

machula13 + 75425 = 77038
stdout
23 + 47 = 70
3247 + 502 = 3749
1613 + 75425 = 77038