Link to my Code : 4cAId8 - Online C++0x Compiler & Debugging Tool - Ideone.com
@castle27âŚYou are getting RTE because you are using scanf to read a multi-word input. To read a multiword input, you have to use gets(s).I have used getchar() before gets() so that the gets(s) function doesnot consider âno of testcasesâ as a part of the string.
You have not left space between no and â=â sign for the 1st and 2nd test case,which will lead to WA.So make sure you get it corrected.
I have updated your code: http://ideone.com/LTYFvx
Remember,indent your code well,it helps in debuggingâŚ
@rahul_nexus : thanks for the solutionâŚbut it still gives runtime error on SPOJ. Does it rquire any other alteration if i consider the spaces ?
- Input is preceded by blank line means you have to input that blank line too but it doesnot means that you need to print a newline.
- Also you need a getchar() just after inputiing T, the number of test cases to ignore âenterâ press.
- Output format was wrong, you need to separate all three objects in output by a space.
- Here is your corrected code : DwuWEA - Online C++ Compiler & Debugging Tool - Ideone.com (Accepted).
- If you have any further problem, just ask
// learned atoi() & strchr(str, int) function
// atoi(a) converts string a to integer
//strchr(s, âmâ) returns the pointer of the location of m in string a
// by amitt001
#include<iostream>
#include<cstdlib>
#include<string.h>
using namespace std;
int main(){
int _;
cin>>_;
while(_--){
char a[100], op[2], opp[2], b[100], c[200];
cin>>a>>op>>b>>opp>>c;
int i, j, k;
if(strchr(a, 'm')!=NULL){
j = atoi(b);
k = atoi(c);
i = k - j;
}
else if(strchr(b, 'm')!=NULL){
i = atoi(a);
k = atoi(c);
j = k - i;
}
else{
i = atoi(a);
j = atoi(b);
k = i + j;
}
cout<<i<<" "<<op<<" "<<j<<" = "<<k<<endl;
}
}