Poj Solution 2608

http://poj.org/problem?id=2608

#include<iostream>
#include<string>
#include<map>
#include<cstdlib>
#include<algorithm>
using namespace std;

char ss[21];
int a[21];


int main()
{
map<char,int>m;
m['B']=1;     m['A']=0;
m['F']=1;     m['E']=0;
m['P']=1;     m['I']=0;
m['V']=1;     m['O']=0; 
m['C']=2;     m['U']=0;
m['G']=2;     m['H']=0;
m['J']=2;     m['W']=0;
m['K']=2;     m['Y']=0;
m['Q']=2;
m['S']=2;
m['Z']=2;
m['X']=2;
m['D']=3;
m['T']=3;
m['L']=4;
m['M']=5;
m['N']=5;
m['R']=6;
int i,j,len,t;
while(scanf("%s",ss)!=EOF)
{
   len=strlen(ss);
   j=0;
   for(i=0;i<len;i++)
   {
    if(m[ss[i]]==0)
     continue;
    t=m[ss[i]];
    if(j==0)
     a[j++]=t;
    else
    {
     if((a[j-1]!=t)||m[ss[i-1]]==0)                            
      a[j++]=t;
     else
      continue;
    }
   }
   for(i=0;i<j;i++)
    printf("%d",a[i]);
   printf("n");
}
system("pause");
return 0;
}
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *