11878 - Homework Checker

All about problems in Volume 118. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

11878 - Homework Checker

Post by yatsen » Wed Dec 01, 2010 9:34 am

I always got "Runtime Error".
What's wrong? It seem not a diffcult problem. :(
Can anyone help?

naseef_07cuet
Learning poster
Posts: 62
Joined: Sat Nov 21, 2009 10:17 pm
Location: CUET,Chittagong,Bangladesh

Re: 11878 - Homework Checker

Post by naseef_07cuet » Wed Dec 01, 2010 1:06 pm

Post your code..
If you have determination, you can do anything you want....:)

yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

Re: 11878 - Homework Checker

Post by yatsen » Wed Dec 01, 2010 6:21 pm

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);
}

Last edited by yatsen on Mon Dec 13, 2010 9:41 am, edited 1 time in total.

yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

Re: 11878 - Homework Checker

Post by yatsen » Mon Dec 13, 2010 9:39 am

I have found what's wrong.
The main program should end with : rturn 0, else it will cause a runtime wrror.

Pro.metal
New poster
Posts: 9
Joined: Fri Dec 17, 2010 8:13 pm

Re: 11878 - Homework Checker

Post by Pro.metal » Fri Dec 17, 2010 8:25 pm

i am getting WA for this problem.
here's my code,large though. please help!!

Code: Select all

removed after AC :D
Last edited by Pro.metal on Fri Mar 25, 2011 10:05 am, edited 1 time in total.

rujialiu
New poster
Posts: 37
Joined: Mon Mar 05, 2007 2:42 am

Re: 11878 - Homework Checker

Post by rujialiu » Sat Dec 18, 2010 9:17 am

try this: printf("%d",count); ==> printf("%d\n",count);
:-)

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11878 - Homework Checker

Post by sohel » Sat Dec 18, 2010 9:22 am

Try this case

Code: Select all

1+1=?

fabres21s
New poster
Posts: 1
Joined: Fri Dec 02, 2011 6:14 pm

1878 - Homework Checker

Post by fabres21s » Fri Dec 02, 2011 6:21 pm

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
	}
}
Last edited by brianfry713 on Thu Nov 20, 2014 9:16 pm, edited 1 time in total.
Reason: Added code blocks

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11878 - Homework Checker

Post by uDebug » Sat Apr 12, 2014 7:49 am

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 1878 - Homework Checker

Post by uDebug » Sat Apr 12, 2014 7:58 am

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);
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

nasim.ruet
New poster
Posts: 10
Joined: Sat Sep 06, 2014 12:44 pm

Re: 11878 - Homework Checker

Post by nasim.ruet » Sat Sep 06, 2014 4:12 pm

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;
}
Last edited by brianfry713 on Thu Nov 20, 2014 9:15 pm, edited 1 time in total.
Reason: Added code blocks

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11878 - Homework Checker

Post by lighted » Sat Sep 06, 2014 5:26 pm

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;
}
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

nasim.ruet
New poster
Posts: 10
Joined: Sat Sep 06, 2014 12:44 pm

Re: 11878 - Homework Checker

Post by nasim.ruet » Sat Sep 06, 2014 7:55 pm

:D :D thanks i got AC :lol: :lol:

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11878 - Homework Checker

Post by Shahidul.CSE » Sat Sep 13, 2014 1:31 pm

problem was that i didn't control when c<0

Code: Select all

Removed after accepted
Last edited by Shahidul.CSE on Sat Sep 13, 2014 7:22 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11878 - Homework Checker

Post by Shahidul.CSE » Sat Sep 13, 2014 7:18 pm

Thanks, brianfry713, got Accepted now !! :D :D
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

Post Reply

Return to “Volume 118 (11800-11899)”