## 12289 - One-Two-Three

Moderator: Board moderators

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

### 12289 - One-Two-Three

#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=='o'&&a=='n')||(a=='o'&&a=='e')||(a=='o'&&a=='e'))
printf("1");
else if((a=='t'&&a=='w')||(a=='t'&&a=='o')||(a=='w'&&a=='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

#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=='o'&&a=='n')||(a=='o'&&a=='e')||(a=='o'&&a=='e'))
printf("1");
else if((a=='t'&&a=='w')||(a=='t'&&a=='o')||(a=='w'&&a=='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

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

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

int n=0;
String s;

for (n = input.nextInt(); n > 0; n--)
{
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

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

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

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

Thank you, small mistake Got AC

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

### Re: Why wa

gives me WA too

java code

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

Scanner sc = new Scanner(System.in);

while(test-->0)
{

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

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

new code

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

public class Main {

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

Scanner sc = new Scanner(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

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

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

### Re: Why wa

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!