486 - English-Number Translator

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

Moderator: Board moderators

ei01036
New poster
Posts: 12
Joined: Wed Jan 15, 2003 1:13 am

486 - English-Number Translator

Post by ei01036 »

i've WA!!! :roll: and i've tested my prog with this input, and all worked right:

zero hundred
zero hundred million
hundred million
negative nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine
nine hundred ninety nine thousand nine hundred ninety nine
nine hundred ninety
zero
six
negative seven hundred twenty nine
one million one hundred one
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
twenty
twenty two
eighty eight
eighty
hundred
thousand

can the input have wrong cases?

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Try these inputs :

-----------------
negative one hundred fifty thousand
--------------------
one thousand fifty
--------------------
negative twelve million twelve thousand
-------------------
eight hundred eighty eight million
------------------
two million two thousand twelve
-------------------------
eight hundred eighty eight million eight hundred eighty eight thousand eight hundred eighty eight
--------------------------
nine hundred million one hundred two thousand one hundred eleven
-----------------------
one hundred eleven million eleven
----------------------
seven hundred nine million nine hundred
-----------------------
nine hundred nine thousand nine
------------------------
eight hundred eighty eight
----------------------
eighty eight million eighty eight thousand eighty eight
------------------------
nine hundred nine thousand nine hundred

------- means : separation between different input.


And the outputs should be :
-150000
1050
-12012000
888000000
2002012
888888888
900102111
111000011
709000900
909009
888
88088088
90990

Also my AC program outputs all 0 for your first 3 inputs and last 2 inputs. And I don't think those are valid inputs that the judge use. :wink:

Good Luck ! :D

RuiFerreira
New poster
Posts: 23
Joined: Mon Dec 16, 2002 8:01 pm
Location: Portugal
Contact:

correction

Post by RuiFerreira »

I think the last input should be 909900
Please visit my webpage!! I've got a lot of UVA statistics scripts
http://www.fe.up.pt/~ei01081/scripts/

pakiyabhai
New poster
Posts: 1
Joined: Sat Feb 08, 2003 2:38 pm
Location: India
Contact:

486 - English-Number Translator , Answer ??

Post by pakiyabhai »

could i get the source ??
I Stand Alone

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

try to write your own solution, not cheat others code ....
if you will be in trouble - some people help you :)))

Dominik

jahangirk
New poster
Posts: 5
Joined: Sat Jun 26, 2004 11:15 pm

486. English Number Translator. WHy runtime error ? plz help

Post by jahangirk »

I have tested my problem with every possible input but still it is giving my runtime error . i dont know how to correct it . i have also tested this problem on gnu complier. plz help



[cpp]#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;




string a[]={"zero", "one", "two", "three", "four",

"five","six","seven","eight","nine", "ten","eleven", "twelve", "thirteen",
"fourteen",

"fifteen", "sixteen","seventeen", "eighteen", "nineteen",

"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};




int

v[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,
70,80,90};


int search(string b)
{

int h=-1;
int c;

for(c=0;c<=28;c++)
{
if(b==a[c])
{
h=1;
break;
}
}
if(h==1)
{
return c;
}
else
return -1;


}




int main()
{



char word[101];




int k=1;
int g;
char ch;
char a;




while(k!=0)
{


int neg = 0;
int acc = 0;
int unit = 0;
int number = 0;



int i=0;

k=scanf("%c",&ch);

while(ch!='\n')
{
word[i++]=ch;

if(1!=scanf("%c",&ch))
{
break;
}

}




string s="";

for(int j=0;j<=i;j++)
{

if((word[j]==' ')|| j==i)
{




if (s=="negative")
{
neg = 1;
}
else if (s=="hundred")
{
acc += unit * 100;
unit = 0;
}
else if (s=="thousand")
{
acc += unit;
number += acc * 1000;
acc = 0;
unit = 0;
}
else if (s=="million")
{
acc += unit;
number += acc * 1000000;
acc = 0;
unit = 0;
}

else
{
g=search(s);
if (v[g] < 10)
{
unit += v[g];
}
else
{
acc += v[g];
}



}



s="";

}
else
{
a=tolower(word[j]);
s+=a;
}



}
number += unit + acc;

if(neg==1)
{
cout<<'-';
}
cout<<number;
cout<<endl;

}

return 0;


}
[/cpp]

lolo
New poster
Posts: 2
Joined: Thu Mar 03, 2005 11:09 pm

486 - English-Number Translator

Post by lolo »

i don't know what's happend with this problem
here is my code

#include <iostream.h>

char arr[32][10] = {"negative", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen",
"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred",
"thousand", "million"};
int ke[32] = {-1, 0, 1,2, 3,4, 5, 6, 7, 8, 9, 10,11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 30, 40, 50, 60, 70, 80, 90, 100, 1000, 1000000};

char cadena[100000] ={'\0'} , espera[10] = {'\0'};
int largo , resultado = 0 , anterior , million , miles , cientos;


int buscar(char *p)
{
for(int i = 0 ; i < 32; i ++)
if(!strcmp(p,arr))
return i;
return -1;
}

int main()
{


while(gets(cadena)){

largo = strlen(cadena);
int i = 0;
bool negative = false , m = false;

while(largo-- > 0){

char mientras[10] = {'\0'};
int v = 0;

while(cadena != ' ' && largo-- >= 0){

mientras[v++] = cadena[i++];
}
i++;

int posActual = buscar(mientras);

if(posActual == 0)
negative = true;

else if(posActual >= 1 && posActual <= 20){

resultado += ke[posActual];
anterior = ke[posActual];
}
else if(posActual >= 21 && posActual <= 28){

resultado += ke[posActual];
anterior = ke[posActual];
}
else if(posActual >= 29 && posActual <= 31){

if(ke[posActual] < resultado){

resultado -= anterior;
anterior = ke[posActual] * anterior;
resultado += anterior;
anterior = 0;
}
else
resultado = resultado * ke[posActual];
}
if(resultado >= 1000000){

million = resultado;
resultado = 0;
m = true;
}
}
if(negative)
cout << "-";
if(m)
resultado += million;
cout << resultado << endl;
resultado = 0;
negative = false;
m = false;
}
return 0;
}

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

you are using functions like strlen() and strcmp() which requires the header file <string.h> .
Perhaps you did not get compile error on your local machine because it was included by default.

One other issue, if you ever post source code, it is better that you disable smilies, otherwise section of your code may become smily faces.

murkho
New poster
Posts: 33
Joined: Mon Mar 28, 2005 6:41 pm

today i got AC for 486

Post by murkho »

In your code u used strlen which needs string.h header file. Again you used [for(int i =0; ..; ..) ] this format that is inside for loop declaration
of a variable which give compile error. Correct this and try again.
wish your best.

chinmoy kanti dhar
New poster
Posts: 19
Joined: Fri Jun 22, 2007 6:17 pm
Location: bangladesh

help me for 486

Post by chinmoy kanti dhar »

hi,
plz help me.i am new in acm.i cannot find any pb but this gives WA.here the code----

#include<stdio.h>
#include<string.h>
#include<math.h>

void main()
{
long a1,a,m,n,i,k,p,d,n1;
char c[100],b[10];
while(gets(c))
{
a1=d=a=m=k=0;p=0;
n=strlen(c);

for(i=0;i<=n;i++)
{
if(c!=' '){b[k++]=c;m=1;}
if((c==' '&&m==1)||c=='\0')
{
b[k]='\0';n1=p=0;
if(strcmp(b,"negative")==0)d=1;
if(strcmp(b,"one")==0)p=p+1;
else if(strcmp(b,"two")==0)p=p+2;
else if(strcmp(b,"three")==0)p=p+3;
else if(strcmp(b,"four")==0)p=p+4;
else if(strcmp(b,"five")==0)p=p+5;
else if(strcmp(b,"six")==0)p=p+6;
else if(strcmp(b,"seven")==0)p=p+7;
else if(strcmp(b,"eight")==0)p=p+8;
else if(strcmp(b,"nine")==0)p=p+9;
else if(strcmp(b,"ten")==0)p=p+10;
else if(strcmp(b,"zero")==0)p=p+0;
else if(strcmp(b,"eleven")==0)p=p+11;
else if(strcmp(b,"twelve")==0)p=p+12;
else if(strcmp(b,"thirteen")==0)p=p+13;
else if(strcmp(b,"fourteen")==0)p=p+14;
else if(strcmp(b,"fifteen")==0)p=p+15;
else if(strcmp(b,"sixteen")==0)p=p+16;
else if(strcmp(b,"seventeen")==0)p=p+17;
else if(strcmp(b,"eightteen")==0)p=p+18;
else if(strcmp(b,"nineteen")==0)p=p+19;
else if(strcmp(b,"twenty")==0)p=p+20;
else if(strcmp(b,"thirty")==0)p=p+30;
else if(strcmp(b,"fourty")==0)p=p+40;
else if(strcmp(b,"fifty")==0)p=p+50;
else if(strcmp(b,"sixty")==0)p=p+60;
else if(strcmp(b,"seventy")==0)p=p+70;
else if(strcmp(b,"eighty")==0)p=p+80;
else if(strcmp(b,"ninety")==0)p=p+90;
else if(strcmp(b,"hundred")==0){a=a*100;if(a==0)a=100;n1=1;}
else if(strcmp(b,"thousand")==0){a=a*1000;if(a==0)a=1000;n1=1;a1=a1+a;a=0;}
else if(strcmp(b,"million")==0)
{if(a!=0)a=a*1000000;n1=1;a1=a1+a;a=0;}
k=0;m=0;
if(n1==0) a=a+p;
}
}
if(d==1)printf("-");
printf("%ld\n",a+a1);
}
}

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Search the board first. Don't open a new thread if there is one already.
Ami ekhono shopno dekhi...
HomePage

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 486 need test cases

Post by Articuno »

My program is getting WA. Please someone give me some test cases. I tried various inputs but my code is giving correct output. Someone pls help
May be tomorrow is a better day............ :)

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 486 Compiler Error

Post by Obaida »

i got wrong answer for this case:---> "when there is a blank that is length is 0 then exit".
but i haven't seen such thing in description!!!! :oops:
try_try_try_try_&&&_try@try.com
This may be the address of success.

aliahmed
New poster
Posts: 24
Joined: Fri Oct 24, 2008 8:37 pm
Location: CUET, Chittagong, Bangladesh
Contact:

Re: 486 - English-Number Translator

Post by aliahmed »

some input:
  • nine hundred ninety nine million
    nine hundred nine million
    nine hundred million
    nine million
    ninety million
    ninety nine million
    nine hundred ninety nine million ninety nine thousand ninety nine
    nine hundred ninety nine million nine hundred ninety nine thousand ninety nine
    nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine
    nine hundred ninety nine million nine hundred ninety
    nine
    ninety
    ninety nine
    nine hundred nine
    nine hundred
    nine hundred ninety nine
    nine hundred thousand
    nine hundred ninety nine thousand
    nine hundred nine thousand
    nine thousand
    nine thousand ninety nine
    nine hundred ninety nine thousand ninety nine
    nine hundred ninety nine thousand nine hundred ninety nine
    six
    negative seven hundred twenty nine
    one million one hundred one

@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

486 - English-Number Translator WA

Post by @mjad »

:o why wrong answer please help me

Code: Select all


// English-Number Translator 
// problem no 486

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

#define M 1000000
//typedef __int64 ll;

int main()
{
	char taka[32][15]={	"negative","zero","one", "two","three","four","five","six","seven","eight","nine",
						"ten","eleven", "twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
						"eighteen","nineteen","twenty","thirty","forty","fifty","sixty","seventy","eighty",
						"ninety","hundred","thousand","million"
	};
	long value[32]={-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90,100,1000,1000000};
	char text[M],*t;
	int i=1,j,sufix;
	long long  sum,tem,tt;
	//ll sum,tem,tt;
	//freopen("486.txt","r",stdin);
	while(gets(text))
	{
		tt=tem=sum=0;
		queue<char *>s;
		t=strtok(text," ");
		while(t)
		{
			s.push(t); 
			t=strtok(NULL," ");
		}
		sufix=1;
		while(!s.empty())
		{
			
			t=s.front();
			for(i=0;i<32;i++)
			{
				if(strcmp(t,taka[i])==0)
				{
					if(i==0)
					{	
						sufix=-1;
						break;
					}
					else if(i>28)
					{
						if(sum<value[i])
						{
							sum+=tt;
							sum*=value[i];
						}
						else
						{
							tt*=value[i];
							sum+=tt;
						}
						tt=0;
				 
						break;
					}
					else
					{
						tt+=value[i];
						 
						break;
					}
				}

			}
			
			s.pop();
		}
		sum+=tt;
		sum*=sufix;
	 printf("%lld\n",sum);
	//	printf("%I64d\n",sum);
	}
	return 0;
}

Post Reply

Return to “Volume 4 (400-499)”