RTE in SPOJ problem ABSYS

Link to my Code : http://ideone.com/4cAId8

1 Like

@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…:smiley:

3 Likes

@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 ?

@castle27 :

  • 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 : http://ideone.com/DwuWEA (Accepted).
  • If you have any further problem, just ask :slight_smile:
10 Likes

// learned atoi() & strchr(str, int) function :slight_smile:
// 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;
    }
}