Description
将一个字符串中七种特定的字符转化为另一种方式输出,转化方式如下:
Input
多组输入,每组用例占一行包括一个字符串,以#结束输入
Output
对于每组用例,输出转化后的字符串
Sample Input
Happy Joy Joy!
plain_vanilla
(**)
?
the 7% solution
#
Sample Output
Happy%20Joy%20Joy%21
plain_vanilla
%28%2a%2a%29
?
the%207%25%20solution
Solution
简单字符串处理
Code
#include<stdio.h>
#include<string.h>
char *table[7]={" ","!","$","%","(",")","*"},*table_plus[7]={"%20","%21","%24","%25","%28","%29","%2a"};
char s[100];
int main()
{
int i;
while(1)
{
gets(s);
if(strcmp(s,"#")==0)//输入结束条件
return 0;
for(char *p=s;*p;)
{
for(i=0;i<7;i++)
if(strncmp(table[i],p,strlen(table[i]))==0)//找到匹配
{
printf("%s",table_plus[i]);
break;
}
if(i<7)//输出转化后的字符串
p+=strlen(table[i]);
else//输出原字符
printf("%c",*p++);
}
printf("\n");
}
}