I'm getting WA as well, and I really don't see why I should be. My program handles the number 0 (just prints 0), a leading 0 in an interior term (e.g. "09 lakh" becomes "9 lakh"), and an interior term which is completely 0 (the term is not printed). Is this another correct-but-not-accepted solution?
/* Takes care of leading zeroes */
bool checkit(string & s)
{
while (s.length())
{
if (s.at(0) != '0')
break;
s = s.substr(1);
}
return s.length();
}
/* Takes the end off the string and returns the
* text version of that portion which was removed */
string chop_and_print(string &in)
{
string result;
int length = 2;
if (ident == " shata ")
length = 1;
length = min(length, in.length());
result = in.substr(in.length() - length);
in = in.substr(0, in.length() - length);
if (!checkit(result))
return "";
result.append(ident);
return result;
}
GreenPenInc wrote:My program handles the number 0 (just prints 0), a leading 0 in an interior term (e.g. "09 lakh" becomes "9 lakh"), and an interior term which is completely 0 (the term is not printed). Is this another correct-but-not-accepted solution?
I got AC with C today.
Following is input I used for local test.
Please try to check, ... I can't read program well except for C.
I faced lots of troubles with this problem and finally identified few points and got accepted.
1. There is a cycle. Check it properly.
2. Fix your code for this type of input : 10 kuti kuti 1 shata 1
3. There is an input, it is 0 (zero). What is your output for this input ?
4. I am not sure but I have handled Blank Line also.
there will be nothing like 0 lakh or 0 hajar.......there could be many other problems too, but I could not check because of time....if you don't get Acc after fixing this mistake then post again...
Heyah :]
I am a quite fresh and unexperienced computer scientist and I ask for help.
As I've noticed the vast majority uses c/c++ etc. However, I've written my program in PASCAL and I hope that won't be any obstalce.
var
l,wp,spr:string;
i,j,n,le:longint;
procedure wypisz;
Begin
if n>999 then write(n,'.') else
if n>99 then write(' ',n,'.') else
if n>9 then write(' ',n,'.') else
write(' ',n,'.')
End;
procedure zero(p:longint);
Begin
if (l[p]='0')then begin
if l[p+1]='0' then begin
wp:='' ;
spr:='';
end else wp:=l[p+1] end else
wp:=l[p]+l[p+1];
End;
BEGIN
while not(eof) do Begin
inc(n);
readln(l);
le:=length(l);
spr:='0';
for i:=le downto 1 do if l<>'0' then spr:=l;
if spr='0' then begin
wypisz;
writeln(' 0');
end else begin
spr:='a';
if le<8 then
if le<6 then
if le<4 then
if le<3 then begin
wypisz;
if(l[1]='')or(l[1]='0') then begin
if(le=2)then writeln(' ',l[2])
else writeln(' 0');end
else writeln(' ',l)
end else
begin {3}
wypisz;
if l[1]<>'0'then write(' ',l[1],' shata');
zero(2);
if wp<>'' then writeln(' ',wp) else writeln
end else
begin {4,5}
wypisz;
if le=4 then begin if l[1]<>'0'then write (' ',l[1],' hajar')end else
begin zero(1); if wp<>'' then write(' ',wp,' hajar'); end;
if l[le-2]<>'0'then write(' ',l[le-2],' shata');
zero(le-1);
if wp<>'' then writeln(' ',wp) else writeln;
end else
begin {6,7}
wypisz;
if le=6 then begin if l[1]<>'0'then write (' ',l[1],' lakh')end else
begin zero(1); if wp<>'' then write(' ',wp,' lakh'); end;
zero(le-4); if wp<>'' then write(' ',wp,' hajar');
if l[le-2]<>'0'then write(' ',l[le-2],' shata');
zero(le-1);
if wp<>'' then writeln(' ',wp) else writeln;
end
else
if le<15 then
if le<13 then
if le<11 then
if le<10 then begin {8,9}
wypisz;
if le=8 then begin if l[1]<>'0'then write (' ',l[1],' kuti')end else
begin zero(1); write(' ',wp,' kuti'); end;
zero(le-6); if wp<>'' then write(' ',wp,' lakh');
zero(le-4); if wp<>'' then write(' ',wp,' hajar');
if l[le-2]<>'0'then write(' ',l[le-2],' shata');
zero(le-1);
if wp<>'' then writeln(' ',wp) else writeln;
end
else begin
wypisz; {10}
if l[1]<>'0'then write(' ',l[1],' shata');
zero(2); if wp<>'' then write(' ',wp,' kuti');
if (wp='')and(l[1]<>'0') then write(' kuti');
zero(4); if wp<>'' then write(' ',wp,' lakh');
zero(le-4);if wp<>'' then write(' ',wp,' hajar');
if l[le-2]<>'0'then write(' ',l[le-2],' shata');
zero(le-1);
if wp<>'' then writeln(' ',wp) else writeln;
end
else begin {11,12}
wypisz;
if le=11 then begin if l[1]<>'0'then write (' ',l[1],' hajar')end else
begin zero(1); if wp<>'' then write(' ',wp,' hajar'); end;
if l[le-9]<>'0'then write(' ',l[le-9],' shata');
zero(le-8); if (wp<>'') then write(' ',wp,' kuti');
if (wp='')and((l[le-9]<>'0')or(wp<>'')) then write(' kuti');
zero(le-6); if wp<>'' then write(' ',wp,' lakh');
zero(le-4);if wp<>'' then write(' ',wp,' hajar');
if l[le-2]<>'0'then write(' ',l[le-2],' shata');
zero(le-1);
if wp<>'' then writeln(' ',wp) else writeln;
end
else begin {13,14}
wypisz;
if le=13 then begin if l[1]<>'0'then write (' ',l[1],' lakh')end else
begin zero(1); if wp<>'' then write(' ',wp,' lakh'); end;
zero(le-11);if wp<>'' then write(' ',wp,' hajar');
if l[le-9]<>'0'then write(' ',l[le-9],' shata');
zero(le-8); if wp<>'' then write(' ',wp,' kuti');
if (wp='')and((l[le-9]<>'0')or(wp<>'')) then write(' kuti');
zero(le-6); if wp<>'' then write(' ',wp,' lakh');
zero(le-4);if wp<>'' then write(' ',wp,' hajar');
if l[le-2]<>'0'then write(' ',l[le-2],' shata');
zero(le-1);
if wp<>'' then writeln(' ',wp) else writeln;
end
else begin {15}
wypisz;
if l[1]<>'0' then write(' ',l[1],' kuti');
zero(le-13);if wp<>'' then write(' ',wp,' lakh');
zero(le-11);if wp<>'' then write(' ',wp,' hajar');
if l[le-9]<>'0'then write(' ',l[le-9],' shata');
zero(le-8); if wp<>''
then write(' ',wp,' kuti');
if (wp='')and((l[le-9]<>'0')or(wp<>'')) then write(' kuti');
zero(le-6); if wp<>'' then write(' ',wp,' lakh');
zero(le-4);if wp<>'' then write(' ',wp,' hajar');
if l[le-2]<>'0'then write(' ',l[le-2],' shata');
zero(le-1);
if wp<>'' then writeln(' ',wp) else writeln;
end;