## 11787 - Numeral Hieroglyphs

Moderator: Board moderators

obbY
New poster
Posts: 5
Joined: Sun May 16, 2010 11:41 pm

### 11787 - Numeral Hieroglyphs

Is there any critical input for this problem? It seems quite easy but I keep getting WA
My program passes the sample output, I don't know why I get WA, here's my C code

Code: Select all

``removed after AC``
edit: I got ACC, I made a silly mistake

farhan_iut
New poster
Posts: 4
Joined: Mon Jun 08, 2009 11:52 pm

### 11787 - Numeral Hieroglyphs

This problem seems pretty easy.. i got corrrect output for several test cases bt cant find the problem.. plz some1 help.. here my code:

Code: Select all

``````#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
using namespace std;

int main(){
map<char,int>mp,cp;
char a[1000];
int n,u,i,j,k,l,f,flag,p;
int ans;
mp.clear();
char num[7] = {'B', 'U', 'S', 'P', 'F', 'T', 'M'};
char mum[7] = {'M', 'T', 'F', 'P', 'S', 'U', 'B'};
mp['B']=1;
mp['U']=10;
mp['S']=100;
mp['P']=1000;
mp['F']=10000;
mp['T']=100000;
mp['M']=1000000;
//freopen("in.txt","r",stdin);
scanf("%d\n",&n);
while(n--){
cp.clear();
gets(a);
ans=0;
p=0;
f=1;
for(i=0;i<strlen(a);i++){
cp[a[i]]++;
if(cp[a[i]]>9){
flag=0;
f=0;
break;
}
flag=0;
for(j=p;j<7;j++){
if(a[i]==num[j]){
p=j;
flag=1;
break;
}
}
if(flag==0) break;
ans+=mp[a[i]];
}
if(flag==0&&f==1){
ans=0;
p=0;
for(i=0;i<strlen(a);i++){
flag=0;
for(j=p;j<7;j++){
if(a[i]==mum[j]){
p=j;
flag=1;
break;
}
}
if(flag==0) break;
ans+=mp[a[i]];
}
}

if(flag==0) cout<<"error"<<endl;
else cout<<ans<<endl;
}

return 0;
}``````

robot
New poster
Posts: 29
Joined: Sun May 24, 2009 8:39 pm

### Re: 11787 - Numeral Hieroglyphs

Hi farhan...
try this input... for this situition properly doesn't work ur program....
1
SUUUUUUUUUU
ouput:
error

plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

### Re: 11787 - Numeral Hieroglyphs

Some inputs:

Code: Select all

``````20
B
BB
BBBBBBBBBB
BUUB
TM
MTFM
MTFPSB
MFTSB
BUSPMT
UUUBBBUUUUUUUUUU
BUSPFTMMMMMMMMMM
BBBBBBBBBBUUUUUUSSS
BBBBBBBBBUUUUUUSSS
BUUUUUUUUUUB
BUUUUUUUUUB
BUUUUUUUUUSP
BUUUUUUUUU
PPPPSSSSSSUUUUUBBBBBB
PPPPSSSSSSUUUUFUBBBBBB
BBBUSSSPFFFM
``````

Code: Select all

``````1
2
error
error
1100000
error
1111101
error
error
error
error
error
369
error
error
1191
91
4656
error
1031313``````
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

### Re: 11787 - Numeral Hieroglyphs

Some more inputs:

Code: Select all

``````40
BBBBBBBBBUUUUUUUUUSSSSSSSSSPPPPPPPPPFFFFFFFFFTTTTTTTTTMMMMMMMMM
BBBBBBBBBBUUUUUUUUUSSSSSSSSSPPPPPPPPPFFFFFFFFFTTTTTTTTTMMMMMMMMM
BBBBBBBBBUUUUUUUUUUSSSSSSSSSPPPPPPPPPFFFFFFFFFTTTTTTTTTMMMMMMMMM
BBBBBBBBBUUUUUUUUUSSSSSSSSSSPPPPPPPPPFFFFFFFFFTTTTTTTTTMMMMMMMMM
BBBBBBBBBUUUUUUUUUSSSSSSSSSPPPPPPPPPPFFFFFFFFFTTTTTTTTTMMMMMMMMM
BBBBBBBBBUUUUUUUUUSSSSSSSSSPPPPPPPPPFFFFFFFFFFTTTTTTTTTMMMMMMMMM
BBBBBBBBBUUUUUUUUUSSSSSSSSSPPPPPPPPPFFFFFFFFFTTTTTTTTTMMMMMMMMMM
BBBBBBBBBUUUUUUUUUSSSSSSSSSPPPPPPPPPFFFFFFFFFTTTTTTTTTTMMMMMMMMM
MMMMMMMMMTTTTTTTTTFFFFFFFFFPPPPPPPPPSSSSSSSSSUUUUUUUUUBBBBBBBBB
MMMMMMMMMMTTTTTTTTTFFFFFFFFFPPPPPPPPPSSSSSSSSSUUUUUUUUUBBBBBBBBB
MMMMMMMMMTTTTTTTTTTFFFFFFFFFPPPPPPPPPSSSSSSSSSUUUUUUUUUBBBBBBBBB
MMMMMMMMMTTTTTTTTTFFFFFFFFFFPPPPPPPPPSSSSSSSSSUUUUUUUUUBBBBBBBBB
MMMMMMMMMTTTTTTTTTFFFFFFFFFPPPPPPPPPPSSSSSSSSSUUUUUUUUUBBBBBBBBB
MMMMMMMMMTTTTTTTTTFFFFFFFFFPPPPPPPPPSSSSSSSSSSUUUUUUUUUBBBBBBBBB
MMMMMMMMMTTTTTTTTTFFFFFFFFFPPPPPPPPPSSSSSSSSSUUUUUUUUUUBBBBBBBBB
MMMMMMMMMTTTTTTTTTFFFFFFFFFPPPPPPPPPSSSSSSSSSUUUUUUUUUBBBBBBBBBB
BUSTFPM
BBBBBBUPMTB
PPFMTMTM
MTMTMTMTM
MTMT
MFBUS
MMMMMMMMMTFPPPPPPPPP
MMMMMMMMMTFPPPPPPPPPP
MMMMMMMMMMTFPPPPPPPPP
MMMMMMMMMMTFTPPPPPPPPP
BBBBBUUUUUUUUUUU
BUBBB
PPBFM
BUSPFMT
MUSPFTM
BUSPFTMB
BUUSSSPPPPFFFFFTTTTTTMMMMMMMMM
BUUSSSPPPPFFFFFTTTTTTMMMMMMMMMM
BUSPFTMP
BUSPFTMS
BUSPFTMF
BUSPFTMT
BUSPFTMM
BUSPFTMTM
``````

Code: Select all

``````9999999
error
error
error
error
error
error
error
9999999
error
error
error
error
error
error
error
error
error
error
error
error
error
9119000
error
error
error
error
error
error
error
error
error
9654321
error
error
error
error
error
2111111
error``````
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

zerin xahan
New poster
Posts: 1
Joined: Sat Sep 10, 2016 2:26 pm

### Re: 11787 - Numeral Hieroglyphs

Code: Select all

``````#include<bits/stdc++.h>
using namespace std;

int main()
{
long long int sum,i,j,k,l,flag,t,p,flag1,count;

scanf("%lld",&t);

for(j=0;j<t;j++)
{
char a[1000],b[1000];
scanf("%s",a);
flag=1;
sum=0;
flag1=1;
count=0;
int flag2=1;
l=strlen(a);
for(i=0;i<l;i++)
{
if(a[i]=='B'&&(a[i+1]=='U'||a[i+1]=='S'||a[i+1]=='P'||a[i+1]=='F'||a[i+1]=='T'||a[i+1]=='M'))
{
flag=0;
break;
}
else if(a[i]=='U'&&(a[i+1]=='S'||a[i+1]=='P'||a[i+1]=='F'||a[i+1]=='T'||a[i+1]=='M'))
{
flag=0;
break;
}
else if(a[i]=='S'&&(a[i+1]=='P'||a[i+1]=='F'||a[i+1]=='T'||a[i+1]=='M'))
{
flag=0;
break;
}
else if(a[i]=='P'&&(a[i+1]=='F'||a[i+1]=='T'||a[i+1]=='M'))
{
flag=0;
break;
}
else if(a[i]=='F'&&(a[i+1]=='T'||a[i+1]=='M'))
{
flag=0;
break;
}
else if(a[i]=='T'&&a[i+1]=='M')
{
flag=0;
break;
}
}

for(k=0,p=l-1;k<l;k++,p--)
{
b[k]=a[p];
}
for(i=0;i<l;i++)
{
if(b[i]=='B'&&(b[i+1]=='U'||b[i+1]=='S'||b[i+1]=='P'||b[i+1]=='F'||b[i+1]=='T'||b[i+1]=='M'))
{
flag1=0;
break;
}
else if(b[i]=='U'&&(b[i+1]=='S'||b[i+1]=='P'||b[i+1]=='F'||b[i+1]=='T'||b[i+1]=='M'))
{
flag1=0;
break;
}
else if(b[i]=='S'&&(b[i+1]=='P'||b[i+1]=='F'||b[i+1]=='T'||b[i+1]=='M'))
{
flag1=0;
break;
}
else if(b[i]=='P'&&(b[i+1]=='F'||b[i+1]=='T'||b[i+1]=='M'))
{
flag1=0;
break;
}
else if(b[i]=='F'&&(b[i+1]=='T'||b[i+1]=='M'))
{
flag1=0;
break;
}
else if(b[i]=='T'&&b[i+1]=='M')
{
flag1=0;
break;
}
}

if(flag==0&&flag1==0)printf("error\n");
else
{
for(i=0;i<l;i++)
{
if(a[i]!=a[i-1])count=0;
if(a[i]=='M')
sum=sum+1000000;
else if(a[i]=='T')
sum=sum+100000;
else if(a[i]=='F')
sum=sum+10000;
else if(a[i]=='P')
sum=sum+1000;
else if(a[i]=='S')
sum=sum+100;
else if(a[i]=='U')
sum=sum+10;
else if(a[i]=='B')
sum=sum+1;
count++;
if(count>9)
{
flag2=0;
break;
}
}
if(flag2==0)printf("error\n");
else printf("%lld\n",sum);
}
memset(b,0,sizeof(b));
}

return 0;
}``````
getting WA.why?

shahidul_brur
New poster
Posts: 12
Joined: Sun Sep 20, 2015 12:33 pm

### Re: 11787 - Numeral Hieroglyphs

@Zerin Xahan,

Add b[l] = '\0' after this loop:

Code: Select all

``````for(k=0,p=l-1;k<l;k++,p--)
{
b[k]=a[p];
}``````

And replace

Code: Select all

``if(a[i]!=a[i-1])count=0;``
to

Code: Select all

``if(i>0 && a[i]!=a[i-1])count=0;``
You will get AC !