Page 1 of 1

12289 - One-Two-Three

Posted: Tue May 15, 2012 6:43 pm
by Strangle Faisal
#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;
}

Re: 12289 Why wa

Posted: Tue May 15, 2012 6:44 pm
by Strangle Faisal
#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;
}

Re: Why wa

Posted: Tue May 15, 2012 10:45 pm
by brianfry713
You should print a newline at the end.

12289 - Runtime Error

Posted: Mon Oct 08, 2012 10:01 pm
by chc919
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;
	
}
}

Re: 12289 - Runtime Error

Posted: Tue Oct 09, 2012 10:18 pm
by brianfry713

Re: Why wa

Posted: Sun Dec 09, 2012 8:47 pm
by sith
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

Re: Why wa

Posted: Mon Dec 10, 2012 9:55 pm
by brianfry713
Try input:

Code: Select all

3
one
two
three

Re: Why wa

Posted: Sun Dec 23, 2012 9:11 pm
by sith
Thank you, small mistake :)

Got AC

Re: Why wa

Posted: Fri Dec 06, 2013 3:52 pm
by waled_salah
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);


}
}


}


}

Re: Why wa

Posted: Fri Dec 06, 2013 10:03 pm
by brianfry713
This thread is about problem 12289 - One-Two-Three
Use class Main

Re: Why wa

Posted: Sat Dec 07, 2013 8:14 am
by waled_salah
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);


}
}


}


}

Re: Why wa

Posted: Wed Dec 11, 2013 12:20 am
by brianfry713
That code won't compile.

Re: Why wa

Posted: Fri Dec 13, 2013 8:15 am
by uDebug
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