Page 1 of 2

11878 - Homework Checker

Posted: Wed Dec 01, 2010 9:34 am
by yatsen
I always got "Runtime Error".
What's wrong? It seem not a diffcult problem. :(
Can anyone help?

Re: 11878 - Homework Checker

Posted: Wed Dec 01, 2010 1:06 pm
by naseef_07cuet
Post your code..

Re: 11878 - Homework Checker

Posted: Wed Dec 01, 2010 6:21 pm
by yatsen
The following is my code:

Code: Select all

/*11878 - Homework Checker*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
	int ans=0,i,j,a,b,c,k,plus,minus;
	char s[1000],t[30];
	while(scanf("%s",s)==1)
	{
		
		
		/* AC, cut..... */
	}
	printf("%d\n",ans);
}


Re: 11878 - Homework Checker

Posted: Mon Dec 13, 2010 9:39 am
by yatsen
I have found what's wrong.
The main program should end with : rturn 0, else it will cause a runtime wrror.

Re: 11878 - Homework Checker

Posted: Fri Dec 17, 2010 8:25 pm
by Pro.metal
i am getting WA for this problem.
here's my code,large though. please help!!

Code: Select all

removed after AC :D

Re: 11878 - Homework Checker

Posted: Sat Dec 18, 2010 9:17 am
by rujialiu
try this: printf("%d",count); ==> printf("%d\n",count);

Re: 11878 - Homework Checker

Posted: Sat Dec 18, 2010 9:22 am
by sohel
Try this case

Code: Select all

1+1=?

1878 - Homework Checker

Posted: Fri Dec 02, 2011 6:21 pm
by fabres21s
could someone help me?
I always get RE
I use java, here I leave my code, thanks!


Code: Select all

import java.io.IOException;
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner input=new Scanner(System.in);
	        String linea;
		int a,b,rc=0,c;		
		boolean suma;
		
		while(true)
		{
			linea=input.nextLine();
			if(linea.length()==0)
			{
				System.out.println(rc);
				System.exit(0);
			}
			suma=false;
			linea=linea.replace("+", "q");
			String tokens[];
			if(linea.contains("q"))
			{
				 tokens=linea.split("q");
				 linea=tokens[1];
				 suma=true;
				 a=Integer.valueOf(tokens[0].trim());
			}
			else if(linea.contains("-"))
			{
				tokens=linea.split("-");
				linea=tokens[1];
				a=Integer.valueOf(tokens[0].trim());
			}
			else
			{
				continue;
			}
			tokens=linea.split("=");
			try
			{
				c=Integer.valueOf(tokens[1].trim());
			}
			catch(Exception e)
			{
				continue;
			}
			b=Integer.valueOf(tokens[0].trim());
			if(suma)
			{
				if((a+b)==c)
				{
					rc++;
				}
			}
			else
			{
				if((a-b)==c)
				{
					rc++;
				}
			}
			
		}
		
		// TODO Auto-generated method stub
	}
}

Re: 11878 - Homework Checker

Posted: Sat Apr 12, 2014 7:49 am
by uDebug
Replying to follow the thread.

Re: 1878 - Homework Checker

Posted: Sat Apr 12, 2014 7:58 am
by uDebug
fabres21s wrote:could someone help me?
I always get RE
I use java, here I leave my code, thanks!
Try replacing the following line

Code: Select all

while(true)
with

Code: Select all

while (input.hasNext())
Also, remove the following lines

Code: Select all

if(linea.length()==0)
{
System.out.println(rc);
System.exit(0);
}
and add this line outside the while loop

Code: Select all

System.out.println(rc);

Re: 11878 - Homework Checker

Posted: Sat Sep 06, 2014 4:12 pm
by nasim.ruet
I cannot find why wrong and please help me... :oops:

Code: Select all

#include<stdio.h>
#include<string.h>
int main()
{
 
    char s[12],sign;
    int count=0,ara[12],sum[3],test=0,i,m,j;
    while(gets(s)){
            sum[0]=0;sum[1]=0;sum[2]=0;j=0;
        for(i=0;s[i]!='\0';i++){
            if(s[i]=='?')
                ara[i]=-88888;
            else if(s[i]=='+'||s[i]=='-'||s[i]=='=')
                ara[i]=999;
            else
                ara[i]=s[i]-48;
            if(s[i]=='+')
                sign='+';
            else if(s[i]=='-')
                sign='-';
        }m=1;
        for(i=0;s[i]!='\0';i++){
            if(ara[i]==999){
                j++;m=1;
            }
            else{
                sum[j]=sum[j]*m+ara[i];
                m*=10;
            }
        }if(sign=='+'){
            if(sum[0]+sum[1]==sum[2])
                count++;
        }if(sign=='-'){
            if(sum[0]-sum[1]==sum[2])
                count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Re: 11878 - Homework Checker

Posted: Sat Sep 06, 2014 5:26 pm
by lighted
Use code tags. You don't need variable m. Change lines to

Code: Select all

else{
  sum[j]=sum[j]*10+ara[i];
  m*=10;
}

Re: 11878 - Homework Checker

Posted: Sat Sep 06, 2014 7:55 pm
by nasim.ruet
:D :D thanks i got AC :lol: :lol:

Re: 11878 - Homework Checker

Posted: Sat Sep 13, 2014 1:31 pm
by Shahidul.CSE
problem was that i didn't control when c<0

Code: Select all

Removed after accepted

Re: 11878 - Homework Checker

Posted: Sat Sep 13, 2014 7:18 pm
by Shahidul.CSE
Thanks, brianfry713, got Accepted now !! :D :D