杭电oj 2719

时间:2023-03-09 19:57:55
杭电oj 2719

  Tips:本程序没有什么难度,只要按照逻辑进行替换即可,需要注意的是,由于输入串中含有空格符号,所以不能使用scanf("%s",ch);来读取一串,可以使用gets()函数读取一行字符。

 #include<stdio.h>
#include<string.h>
int main()
{
char ch[];
while(gets(ch))//不能使用sacnf("%s,ch),因为遇见空格就会结束读入
{
if(*ch == '#')
{
return ;
}
char temp[];
int j=;
for(int i=; i<strlen(ch);i++)
{
if(ch[i] == ' ')
{
temp[j++] = '%';
temp[j++] = '';
temp[j++] = '';
}else if(ch[i] == '!')
{
temp[j++] = '%';
temp[j++] = '';
temp[j++] = '';
}else if(ch[i] == '$')
{
temp[j++] = '%';
temp[j++] = '';
temp[j++] = '';
}else if(ch[i] == '%')
{
temp[j++] = '%';
temp[j++] = '';
temp[j++] = '';
}else if(ch[i] == '(')
{
temp[j++] = '%';
temp[j++] = '';
temp[j++] = '';
}else if(ch[i] == ')')
{
temp[j++] = '%';
temp[j++] = '';
temp[j++] = '';
}else if(ch[i] == '*')
{
temp[j++] = '%';
temp[j++] = '';
temp[j++] = 'a';
}else
{
temp[j++] = ch[i];
} } int i=;
while(i<j)
{
printf("%c",temp[i]);
i++;
} printf("\n");
}
return ;
}