12289 - One-Two-Three

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

Moderator: Board moderators

Post Reply
Strangle Faisal
New poster
Posts: 2
Joined: Sat Apr 28, 2012 11:14 am
Location: BUET , Dhaka , Bangladesh
Contact:

12289 - One-Two-Three

Post by Strangle Faisal » Tue May 15, 2012 6:43 pm

#include <iostream>
#include <string>
#include<cstdio>
#include<cmath>
using namespace std;

int main ()
{
int i,j,n,l,k;
string a;
string th="three";
scanf("%d",&n);
for(i=1; i<=n; i++)
{
cin>>a;
k=0;
l=a.length();
if(l==5)
{
for(j=0;j<5;j++)
{
if(a[j]==th[j])
k++;
}
if(k==4) printf("3");
}
else if(l==3)
{
if((a[0]=='o'&&a[1]=='n')||(a[0]=='o'&&a[2]=='e')||(a[1]=='o'&&a[2]=='e'))
printf("1");
else if((a[0]=='t'&&a[1]=='w')||(a[0]=='t'&&a[2]=='o')||(a[1]=='w'&&a[2]=='o'))
printf("2");
}
if(i!=n) printf("\n");
}
return 0;
}
Strangle Faisal

Strangle Faisal
New poster
Posts: 2
Joined: Sat Apr 28, 2012 11:14 am
Location: BUET , Dhaka , Bangladesh
Contact:

Re: 12289 Why wa

Post by Strangle Faisal » Tue May 15, 2012 6:44 pm

#include <iostream>
#include <string>
#include<cstdio>
#include<cmath>
using namespace std;

int main ()
{
int i,j,n,l,k;
string a;
string th="three";
scanf("%d",&n);
for(i=1; i<=n; i++)
{
cin>>a;
k=0;
l=a.length();
if(l==5)
{
for(j=0;j<5;j++)
{
if(a[j]==th[j])
k++;
}
if(k==4) printf("3");
}
else if(l==3)
{
if((a[0]=='o'&&a[1]=='n')||(a[0]=='o'&&a[2]=='e')||(a[1]=='o'&&a[2]=='e'))
printf("1");
else if((a[0]=='t'&&a[1]=='w')||(a[0]=='t'&&a[2]=='o')||(a[1]=='w'&&a[2]=='o'))
printf("2");
}
if(i!=n) printf("\n");
}
return 0;
}
Strangle Faisal

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why wa

Post by brianfry713 » Tue May 15, 2012 10:45 pm

You should print a newline at the end.
Check input and AC output for thousands of problems on uDebug!

chc919
New poster
Posts: 1
Joined: Mon Oct 08, 2012 9:53 pm

12289 - Runtime Error

Post by chc919 » Mon Oct 08, 2012 10:01 pm

Hello,

I just started practicing JAVA. I've tried this problem many times but online-judge always says Runtime Error.
My question is why can I run it well on my own platform but not on online-judge?
How can I change the code to fit the online-judge's platform?
Thanks for everyone's help!

Code: Select all

import java.io.*;
import java.util.Scanner;

public class Main {
public static void main (String[] args) throws IOException
{
	Scanner input = new Scanner (System.in);
	InputStreamReader is = new InputStreamReader(System.in);
	BufferedReader br = new BufferedReader(is);
	
	int n=0;
	String s;
		
	for (n = input.nextInt(); n > 0; n--)
	{
		s=br.readLine(); 
		System.out.printf("%d\n", num(s));		
	}	
}

private static int num(String s)
{
	int c=0;
	
	if (s.length()==5) return 3;	
	if (s.charAt(0)=='o') c++;
	if (s.charAt(1)=='n') c++;
	if (s.charAt(2)=='e') c++;
	
	if (c >= 2) return 1;
	else return 2;
	
}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12289 - Runtime Error

Post by brianfry713 » Tue Oct 09, 2012 10:18 pm

Check input and AC output for thousands of problems on uDebug!

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: Why wa

Post by sith » Sun Dec 09, 2012 8:47 pm

Hi, I got WA,
But I believe that my solution has to be good.


Could anybody provide some cases for which my solution doesn't work

Code: Select all

AC
Last edited by sith on Sun Dec 23, 2012 9:12 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why wa

Post by brianfry713 » Mon Dec 10, 2012 9:55 pm

Try input:

Code: Select all

3
one
two
three
Check input and AC output for thousands of problems on uDebug!

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: Why wa

Post by sith » Sun Dec 23, 2012 9:11 pm

Thank you, small mistake :)

Got AC

waled_salah
New poster
Posts: 7
Joined: Fri Dec 06, 2013 3:38 pm

Re: Why wa

Post by waled_salah » Fri Dec 06, 2013 3:52 pm

gives me WA too

java code

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Prob_32 {
public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);

Reader.init(System.in);

int test = Reader.nextInt();String b="";
while(test-->0)
{
b=Reader.next();

if(b.length()==3)
{
if(b.charAt(0)=='o'||b.charAt(1)=='n'||b.charAt(2)=='e')
{
System.out.println(1);
}
else if(b.charAt(0)=='t'&&b.charAt(b.length()-1)=='o'||b.charAt(1)=='w')
{
System.out.println(2);

}


}


if(b.length()==5)
{

System.out.println(3);


}
}


}


}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why wa

Post by brianfry713 » Fri Dec 06, 2013 10:03 pm

This thread is about problem 12289 - One-Two-Three
Use class Main
Check input and AC output for thousands of problems on uDebug!

waled_salah
New poster
Posts: 7
Joined: Fri Dec 06, 2013 3:38 pm

Re: Why wa

Post by waled_salah » Sat Dec 07, 2013 8:14 am

new code



import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);

Reader.init(System.in);

int test = sc.nextInt();String b="";
while(test-->0)
{
b=sc.next();

if(b.length()==3)
{
if(b.charAt(0)=='o'||b.charAt(1)=='n'||b.charAt(2)=='e')
{
System.out.println(1);
}
else if(b.charAt(0)=='t'&&b.charAt(b.length()-1)=='o'||b.charAt(1)=='w')
{
System.out.println(2);

}


}


if(b.length()==5)
{

System.out.println(3);


}
}


}


}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why wa

Post by brianfry713 » Wed Dec 11, 2013 12:20 am

That code won't compile.
Check input and AC output for thousands of problems on uDebug!

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

Re: Why wa

Post by uDebug » Fri Dec 13, 2013 8:15 am

Here is some test input / output.

Input:

Code: Select all

14
owe
too
theee
ote
owe
tne
txo
ont
wwo
wne
twx
one
two
three
AC output:

Code: Select all

1
2
3
1
1
1
2
1
2
1
2
1
2
3
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 122 (12200-12299)”