Problem Type : String
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,len,len2;
char ch[1000],des[1000];
while(scanf("%s",ch)==1)
{
len = strlen(ch);
j=0;
for(i=0; i<len; i++)
{
if(ch[i]== 'B' || ch[i]== 'F' || ch[i]=='P'|| ch[i] =='V' )
{
des[j]='1';
j++;
}
else if(ch[i]=='C'|| ch[i]== 'G'|| ch[i]=='J' || ch[i]=='K'|| ch[i]=='Q'|| ch[i]=='S' || ch[i]=='X'|| ch[i]=='Z')
{
des[j]='2';
j++;
}
else if (ch[i]=='D' || ch[i] == 'T' )
{
des[j]='3';
j++;
}
else if (ch[i]=='L' )
{
des[j]='4';
j++;
}
else if (ch[i]=='M' || ch[i] == 'N')
{
des[j]='5';
j++;
}
else if (ch[i]=='R')
{
des[j]='6';
j++;
}
else
{
des[j]='0';
j++;
}
}
for(i=0; i<j; i++)
{
if(des[i]=='0')
{
continue;
}
if(des[i]!=des[i+1])
{
printf("%c",des[i]);
}
}
printf("\n");
memset(ch,'\0',sizeof(ch));
memset(des,'\0',sizeof(des));
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,len,len2;
char ch[1000],des[1000];
while(scanf("%s",ch)==1)
{
len = strlen(ch);
j=0;
for(i=0; i<len; i++)
{
if(ch[i]== 'B' || ch[i]== 'F' || ch[i]=='P'|| ch[i] =='V' )
{
des[j]='1';
j++;
}
else if(ch[i]=='C'|| ch[i]== 'G'|| ch[i]=='J' || ch[i]=='K'|| ch[i]=='Q'|| ch[i]=='S' || ch[i]=='X'|| ch[i]=='Z')
{
des[j]='2';
j++;
}
else if (ch[i]=='D' || ch[i] == 'T' )
{
des[j]='3';
j++;
}
else if (ch[i]=='L' )
{
des[j]='4';
j++;
}
else if (ch[i]=='M' || ch[i] == 'N')
{
des[j]='5';
j++;
}
else if (ch[i]=='R')
{
des[j]='6';
j++;
}
else
{
des[j]='0';
j++;
}
}
for(i=0; i<j; i++)
{
if(des[i]=='0')
{
continue;
}
if(des[i]!=des[i+1])
{
printf("%c",des[i]);
}
}
printf("\n");
memset(ch,'\0',sizeof(ch));
memset(des,'\0',sizeof(des));
}
return 0;
}
No comments:
Post a Comment