10101 - Bangla Numbers

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

Moderator: Board moderators

bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

Post by bugzpodder »

okay, well i found the problem
there is a case where the input is 0 (i check using infinite loop and double checked using division by 0 error). however in the problem description i was assured that all inputs are "positive"

"The input file may contain several test cases. Each case will contain a positive number <= 999999999999999. "

1902745 2003/09/20 02:20:16.041 Runtime Error (SIGFPE) 0:00.002 64 28684 C++ 10101 - Bangla Numbers
1902742 2003/09/20 02:19:15.183 Wrong Answer 0:00.143 468 28684 C++ 10101 - Bangla Numbers
1902739 2003/09/20 02:18:00.734 Time Limit Exceeded 0:10.047 472 28684 C++ 10101 - Bangla Numbers
1902737 2003/09/20 02:15:20.400 Wrong Answer 0:00.148 476 28684 C++ 10101 - Bangla Numbers

i got AC now, thanks for the clarification, everyone

gawi
New poster
Posts: 3
Joined: Sun Jul 13, 2003 10:19 am
Location: Taiwan

10101 - Bangla Numbers - WA

Post by gawi »

I cant find the bug in my code. :(
plz help me and give me more test case , thx

<pre>
input
---------------------------------------
23764
45897458973958
40000000040000
0
000000
0000
000000003
900000000000033
00000012121212
090000000999000
12100000000300

output
---------------------------------------------
1. 23 hajar 7 shata 64
2. 45 lakh 89 hajar 7 shata 45 kuti 89 lakh 73 hajar 9 shata 58
3. 40 lakh kuti 40 hajar
4. 0
5. 0
6. 0
7. 3
8. 9 kuti kuti 33
9. 1 kuti 21 lakh 21 hajar 2 shata 12
10. 90 lakh kuti 9 lakh 99 hajar
11. 12 lakh 10 hajar kuti 3 shata
</pre>

bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

Post by bugzpodder »

judging from your situation, i am willing to bet that you did not catch the empty lines and spaces at the end of the output, which causes WA

gawi
New poster
Posts: 3
Joined: Sun Jul 13, 2003 10:19 am
Location: Taiwan

Post by gawi »

Thank you, it's my fault.

I know why my code is WA because of the case number.

:oops:

kenneth_cwc
New poster
Posts: 9
Joined: Sat Oct 18, 2003 2:08 pm

10101 WA

Post by kenneth_cwc »

Code: Select all

#include<iostream>
using namespace std;

void main()
{
	char number[255];
	int number_end;
	int count=0;
	bool zero;
	bool need_space;
	bool kuti;
	
	while(true)
	{
		need_space=0;
		kuti=0;
		
		for(number_end=0;number_end<255;number_end++)
		{
			number[number_end]=0;
		}
		
		count++;
		
		if(cin>>number)
		{
			number_end=254;
			while(number[number_end]==0)
			{
				number_end--;
			}
			
			cout.width(4);
			cout.setf(ios::right);
			cout<<count<<". ";
			
			zero=0;
			for(int k=0;k<=number_end;k++)
			{
				if(number[k]!='0' && number[k]!='\0')
				{
					zero=1;
					break;
				}
			}
			
			if(zero==0)
			{
				cout<<"0";
			}
			else
			{
				if(number[number_end-14]>'0' && number[number_end-14]<='9')
				{
					kuti=1;
					need_space=1;
					cout<<number[number_end-14]<<" kuti";
				}
				if(number[number_end-13]>'0' && number[number_end-13]<='9')
				{
					if(need_space)
						cout<<" ";
					kuti=1;
					need_space=1;
					cout<<number[number_end-13]<<number[number_end-12]<<" lakh";
				}
				else if(number[number_end-12]>'0' && number[number_end-12]<='9')
				{
					if(need_space)
						cout<<" ";
					kuti=1;
					need_space=1;
					cout<<number[number_end-12]<<" lakh";
				}
				if(number[number_end-11]>'0' && number[number_end-11]<='9')
				{
					if(need_space)
						cout<<" ";
					kuti=1;
					need_space=1;
					cout<<number[number_end-11]<<number[number_end-10]<<" hajar";
				}
				else if(number[number_end-10]>'0' && number[number_end-10]<='9')
				{
					if(need_space)
						cout<<" ";
					kuti=1;
					need_space=1;
					cout<<number[number_end-10]<<" hajar";
				}
				if(number[number_end-9]>'0' && number[number_end-9]<='9')
				{
					if(need_space)
						cout<<" ";
					kuti=1;
					need_space=1;
					cout<<number[number_end-9]<<" shata";
				}
				if(number[number_end-8]>'0' && number[number_end-8]<='9')
				{
					if(need_space)
						cout<<" ";
					kuti=1;
					need_space=1;
					cout<<number[number_end-8]<<number[number_end-7];
				}
				else if(number[number_end-7]>'0' && number[number_end-7]<='9')
				{
					if(need_space)
						cout<<" ";
					kuti=1;
					need_space=1;
					cout<<number[number_end-7];
				}
				if(kuti==1)
				{
					if(need_space)
						cout<<" ";
					cout<<"kuti";
					need_space=1;
				}
				if(number[number_end-6]>'0' && number[number_end-6]<='9')
				{
					if(need_space)
						cout<<" ";
					need_space=1;
					cout<<number[number_end-6]<<number[number_end-5]<<" lakh";
				}
				else if(number[number_end-5]>'0' && number[number_end-5]<='9')
				{
					if(need_space)
						cout<<" ";
					need_space=1;
					cout<<number[number_end-5]<<" lakh";
				}
				if(number[number_end-4]>'0' && number[number_end-4]<='9')
				{
					if(need_space)
						cout<<" ";
					need_space=1;
					cout<<number[number_end-4]<<number[number_end-3]<<" hajar";
				}
				else if(number[number_end-3]>'0' && number[number_end-3]<='9')
				{
					if(need_space)
						cout<<" ";
					need_space=1;
					cout<<number[number_end-3]<<" hajar";
				}
				if(number[number_end-2]>'0' && number[number_end-2]<='9')
				{
					if(need_space)
						cout<<" ";
					need_space=1;
					cout<<number[number_end-2]<<" shata";
				}
				if(number[number_end-1]>'0' && number[number_end-1]<='9')
				{
					if(need_space)
						cout<<" ";
					cout<<number[number_end-1]<<number[number_end];
				}
				else if(number[number_end-0]>'0' && number[number_end]<='9')
				{
					if(need_space)
						cout<<" ";
					cout<<number[number_end];
				}
			}			
			cout<<"\n";
		}
		else
		{
			break;
		}
	}
}
i don't know why WA
anybody can help me?
thx!

Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Post by Joseph Kurniawan »

Can your program handle input such as 0000909, 010232?
Please be careful when using array of character since there could be leading zeroes in the input file.
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.

kenneth_cwc
New poster
Posts: 9
Joined: Sat Oct 18, 2003 2:08 pm

Post by kenneth_cwc »

000909
1. 9 shata 9
010232
2. 10 hajar 2 shata 32

are they right?
if so, i don't know y it is wrong :cry:
thx for your reply

Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

try this

Post by Sajid »

Try this input:

Code: Select all

12222313213
Output:

Code: Select all

1. 1 hajar 2 shata 22 kuti 23 lakh 13 hajar 2 shata 13
:wink:
Sajid Online: www.sajidonline.com

kenneth_cwc
New poster
Posts: 9
Joined: Sat Oct 18, 2003 2:08 pm

Post by kenneth_cwc »

it still ok :-?

Dreamer#1
Learning poster
Posts: 77
Joined: Tue Oct 07, 2003 10:07 pm

really mysterious wa!

Post by Dreamer#1 »

hello kenneth,

I generated a huge random input file & used my AC solution & your above solution to generate to different output files & guess what, both files were exactly same in every single manner, not even a single space more or less in any place. :)

I feel that your solution should've been AC (not even PE because it generated solutions more exact than one of my friend's AC but PE solution).

I know how it feels when we get WA specially when we feel really confident about getting AC, its really irritating, so, I would suggest you to better forget about this problem. There must be some specific input which I failed to find (I should say its out of my imagination) that caused WA for your solution. After all, there can be 1e15 input cases & I can't generate & store them all in the input file so I had to use random function but I wasn't lucky enough to generate any input that is causing WA for your solution. Sorry... :(

don't be upset... we all have our own share of luck

Dreamer

n.b. let me know if you need my AC solution.
Not all of our dreams can be made to come true. But still we live with the hope to turn them into reality someday.

Sensor
New poster
Posts: 4
Joined: Tue Nov 18, 2003 10:01 pm

10101 Why???

Post by Sensor »

Hello!
My program gives WA!
Who can find and give me a test where my program is failed???

{ @JUDGE_ID: 37828FF 10101 Pascal}
program proga;
const a:array[1..5] of string=(' kuti ',' lakh ',' hajar ',' shata ','');
b:array[1..5] of byte=(2,2,2,1,2);
var s,t,m,out:string;
k,n,col,i,j:longint;
tt,ku:boolean;

begin
k:=0;
while not eof(input) do
begin
readln(s);
col:=length(s);
out:='';
t:=s;
j:=5;
m:='';
tt:=false;
ku:=true;
i:=1;
while (t='0')and(i<length(t)) do i:=i+1;
t:=copy(t,i,length(t)-i+1);
if length(t)>9 then tt:=true;
while t<>'' do
begin
m:='';
for i:=1 to b[j] do
if length(t)>0 then
begin
{if (t[length(t)]<>'0') then}
m:=t[length(t)]+m;
t:=copy(t,1,length(t)-1);
end;
if m='00' then m:='';
if m[1]='0' then m:=copy(m,2,1);
if m<>'' then
out:=m+a[j]+out;
if ku then
if tt and (j=1) and (m<>'') then begin ku:=false; tt:=false; end;
if ku and (j=1) then ku:=false;
{if not ku and (tt) and (m<>'') and (j=1) then tt:=false;}
{if ku and (m<>'') then ku:=false;}
if j>1 then j:=j-1 else j:=4;
end;
if out='' then out:='0';
if tt then out:=out+'kuti';
k:=k+1;
write(k:4,'. ');
writeln(out);
end;
end.

aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

10101 WA Help

Post by aakash_mandhar »

My code seems to work fine for all conditions.. like prefixed 0's trailing spaces etc... it even takes care of blank lines...

Where is the error.. Plz let me know... Any test case where it fails...

[c]
# include<stdio.h>
# include<string.h>

int a[10],bc,ac,i,ct,stt,tio;
char b[100],ch;
int main()
{
while(1)
{
bc=0;
stt=0;
tio=0;
do
{
ch=fgetc(stdin);
if(ch==EOF) return 1;

if(ch=='\n') break;
if(ch<'0' || ch>'9') continue;
if(stt==0 && ch=='0') {tio=1;continue;} else stt=1;
b[bc++]=ch;
}
while(ch!='\n' && ch!='\r');
b[bc]='\0';
if(bc==0 && tio==0) continue;
ac=0;
for(i=0;i<10;i++) a=0;
switch(bc)
{
case 1: a[0]=b[0]-'0';ac=1;break;
case 2: a[0]=(b[0]-'0')*10+(b[1]-'0');ac=1;break;
case 3: a[1]=b[0]-'0';a[0]=(b[1]-'0')*10+(b[2]-'0');ac=2;break;
case 4: a[2]=b[0]-'0';a[1]=b[1]-'0';a[0]=(b[2]-'0')*10+(b[3]-'0');ac=3;break;
case 5: a[2]=(b[0]-'0')*10+b[1]-'0';a[1]=b[2]-'0';a[0]=(b[3]-'0')*10+(b[4]-'0');ac=3;break;
case 6: a[3]=b[0]-'0';a[2]=(b[1]-'0')*10+b[2]-'0';a[1]=b[3]-'0';a[0]=(b[4]-'0')*10+(b[5]-'0');ac=4;break;
case 7: a[3]=(b[0]-'0')*10 + b[1]-'0';a[2]=(b[2]-'0')*10+b[3]-'0';a[1]=b[4]-'0';a[0]=(b[5]-'0')*10+(b[6]-'0');ac=4;break;
case 8: a[4]=b[0]-'0';a[3]=(b[1]-'0')*10 + b[2]-'0';a[2]=(b[3]-'0')*10+b[4]-'0';a[1]=b[5]-'0';a[0]=(b[6]-'0')*10+(b[7]-'0');ac=5;break;
case 9: a[4]=(b[0]-'0')*10 + b[1]-'0';a[3]=(b[2]-'0')*10 + b[3]-'0';a[2]=(b[4]-'0')*10+b[5]-'0';a[1]=b[6]-'0';a[0]=(b[7]-'0')*10+(b[8]-'0');ac=5;break;
case 10: a[5]=b[0]-'0';a[4]=(b[1]-'0')*10 + b[2]-'0';a[3]=(b[3]-'0')*10 + b[4]-'0';a[2]=(b[5]-'0')*10+b[6]-'0';a[1]=b[7]-'0';a[0]=(b[8]-'0')*10+(b[9]-'0');ac=6;break;
case 11: a[6]=b[0]-'0';a[5]=b[1]-'0';a[4]=(b[2]-'0')*10 + b[3]-'0';a[3]=(b[4]-'0')*10 + b[5]-'0';a[2]=(b[6]-'0')*10+b[7]-'0';a[1]=b[8]-'0';a[0]=(b[9]-'0')*10+(b[10]-'0');ac=7;break;
case 12: a[6]=(b[0]-'0')*10+b[1]-'0';a[5]=b[2]-'0';a[4]=(b[3]-'0')*10 + b[4]-'0';a[3]=(b[5]-'0')*10 + b[6]-'0';a[2]=(b[7]-'0')*10+b[8]-'0';a[1]=b[9]-'0';a[0]=(b[10]-'0')*10+(b[11]-'0');ac=7;break;
case 13: a[7]=b[0]-'0';a[6]=(b[1]-'0')*10+b[2]-'0';a[5]=b[3]-'0';a[4]=(b[4]-'0')*10 + b[5]-'0';a[3]=(b[6]-'0')*10 + b[7]-'0';a[2]=(b[8]-'0')*10+b[9]-'0';a[1]=b[10]-'0';a[0]=(b[11]-'0')*10+(b[12]-'0');ac=8;break;
case 14: a[7]=(b[0]-'0')*10+b[1]-'0';a[6]=(b[2]-'0')*10+b[3]-'0';a[5]=b[4]-'0';a[4]=(b[5]-'0')*10 + b[6]-'0';a[3]=(b[7]-'0')*10 + b[8]-'0';a[2]=(b[9]-'0')*10+b[10]-'0';a[1]=b[11]-'0';a[0]=(b[12]-'0')*10+(b[13]-'0');ac=8;break;
case 15: a[8]=b[0]-'0';a[7]=(b[1]-'0')*10+b[2]-'0';a[6]=(b[3]-'0')*10+b[4]-'0';a[5]=b[5]-'0';a[4]=(b[6]-'0')*10 + b[7]-'0';a[3]=(b[8]-'0')*10 + b[9]-'0';a[2]=(b[10]-'0')*10+b[11]-'0';a[1]=b[12]-'0';a[0]=(b[13]-'0')*10+(b[14]-'0');ac=9;break;

}

printf("%4d.",++ct);
if(a[8]) printf(" %d kuti",a[8]);
if(a[7]) printf(" %d lakh",a[7]);
if(a[6]) printf(" %d hajar",a[6]);
if(a[5]) printf(" %d shata",a[5]);
if(a[4]) printf(" %d kuti",a[4]); else if(a[8]) printf(" kuti");
if(a[3]) printf(" %d lakh",a[3]);
if(a[2]) printf(" %d hajar",a[2]);
if(a[1]) printf(" %d shata",a[1]);
if(a[0]) printf(" %d",a[0]);
if(!a[8] &&!a[7] &&!a[6] &&!a[5] &&!a[4] &&!a[3] &&!a[2] &&!a[1] &&!a[0]) printf(" 0");


printf("\n");
}
}
[/c]
...I was born to code...

rlatif119
New poster
Posts: 16
Joined: Mon Mar 01, 2004 4:00 pm
Location: Dhaka

10101...WA...please help

Post by rlatif119 »

This code generates wrong answer......but i don't know why.......i think its ok......is there any input which include white space between two digits of a number???? please help.[c]

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

void generate_string(char *num, char ch);

char str[100],temp[100];
int count;
main()
{
char num[15];
int len,i,flag;
count=1;
while(1)
{
flag =0;
scanf("%s",num);
if(feof(stdin))
break;
len=strlen(num);
for(i=0;i<len;++i)
{
if(num!='0')
flag=1;
}
if(!flag)
{
printf("%4d. 0\n",count++);

}
else
{
generate_string(num,' ');
len=strlen(str);
if(str[0]!=' ')
printf("%4d. ",count++);
else
printf("%4d.",count++);

for(i=0;i<len;++i)
{
if(str==' ')
{
if(str[i+1]!='\0')
printf("%c",str);
while(str==' ')
++i;
}
printf("%c",str);
}
printf("\n");
strcpy(str,"");
strcpy(temp,"");
}
}
}

void generate_string(char *num, char ch)
{
int length,i,j,k,l,flag;
length = strlen(num);
if(length<3)
{
if(strcmp(num,"00")!=0)
{
i=0;
if(num[0] == '0')
{
temp[0]=' ';
temp[1]=num[1];
temp[2]='\0';
strcat(str,temp);
}
else
{
temp[0]=' ';
temp[1]=num[0];
temp[2]=num[1];
temp[3]='\0';
strcat(str,temp);
}
}
return;
}
else if(length<4)
{
if(strcmp(num,"000")!=0)
{
if(num[0] != '0')
{
temp[0] = num[0]; temp[1] ='\0';
strcat(temp," shata");
strcat(str,temp);
}
for(i=1;i<length;++i)
num[i-1]=num;
num[i-1] = '\0';
generate_string(num, 's');
}
}
else if(length<6)
{
i=0;
if(strcmp(num,"00000")!=0)
{
if(ch == 'l' && num[0] != 0)
temp[0] = ' ';k=1;
flag =0;
while(num=='0')
++i;
for(k=0;i<=length-4;++i)
{
temp[k++]=num;
flag =1;
}
temp[k]='\0';
if(flag)
{
strcat(temp," hajar ");
strcat(str,temp);
}
j=0;
for( ;i<length;++i)
num[j++]=num;
num[j] = '\0';
generate_string(num,'h');
}
}

else if(length<8)
{
i=0;
if(strcmp(num,"0000000")!=0)
{
if(ch == 'k' && num[0] !=0)
temp[0]=' ';k=1;
flag =0;
while(num=='0')
++i;

for(k=0;i<=length-6;++i)
{
temp[k++]=num[i];
flag =1;
}
temp[k]='\0';
if(flag)
{
strcat(temp," lakh ");
strcat(str,temp);
}
j=0;
for( ;i<length;++i)
num[j++]=num[i];
num[j] = '\0';
generate_string(num,'l');
}
}
else if(length<10)
{
i=0;
if(ch=='k'&& num[0] !=0)
temp[0];k=1;
flag=0;
while(num[i]=='0')
++i;

for(k=0;i<=length-8;++i)
{
temp[k++]=num[i];
flag =1;
}
temp[k]='\0';
if(flag)
{
strcat(temp," kuti ");
strcat(str,temp);
}
j=0;
for( ;i<length;++i)
num[j++]=num[i];
num[j] = '\0';
generate_string(num,'k');
}
else
{
char temp1[10],temp2[10];
for(i=0;i<=length-8 ;++i)
{
temp1[i] = num[i];
}
temp1[i] = '\0';

for(k=0;i<length;++i)
temp2[k++] = num[i];
temp2[k] = '\0';
generate_string(temp1,' ');
strcat(str," kuti ");
generate_string(temp2,' ');
}
}
[/c]

dpitts
New poster
Posts: 31
Joined: Tue Jun 17, 2003 10:10 pm

Well,

Post by dpitts »

Your program is a little complex to follow, but whats you're output for:

Code: Select all

1
10
1000
10000
100000
10000000000000
999999999999999
45897458973958
My AC program outputs

Code: Select all

   1. 1
   2. 10
   3. 1 hajar
   4. 10 hajar
   5. 1 lakh
   6. 10 lakh kuti
   7. 9 kuti 99 lakh 99 hajar 9 shata 99 kuti 99 lakh 99 hajar 9 shata 99
   8. 45 lakh 89 hajar 7 shata 45 kuti 89 lakh 73 hajar 9 shata 58
It took me a long time to figure out that 7 wasn't handled in my code before I got AC.

rlatif119
New poster
Posts: 16
Joined: Mon Mar 01, 2004 4:00 pm
Location: Dhaka

Post by rlatif119 »

Thanks dpitts for your reply.
All of your sample input generates correct answer.......but still got WA
:o :roll:

Post Reply

Return to “Volume 101 (10100-10199)”