盐荒子孙2
时间: 1ms 内存:128M
描述:
没有盐,做饭只能用酱油。
将所有的salt替换为soy sauce,不管大小写。
输入:
包含salt的英文语料
输出:
用soy sauce替换salt后的输出
示例输入:
Salt is necessary
Water is not sAlt as salT
as you can make it soy-bean
sauce can be saLt
soy-bean sauce only
bean soy-bean sauce
示例输出:
soy sauce is necessary
Water is not soy sauce as soy sauce
as you can make it soy-bean
sauce can be soy sauce
soy-bean sauce only
bean soy-bean sauce
提示:
参考答案(内存最优[752]):
#include<stdio.h>
#include<string.h>
int main()
{
char a[1000],b[]="salt";
char c[1000];
int i,n,d,j;
while(gets(a)&&a[0]!=EOF)
{
strcpy(c,a);
n=strlen(c);
for(i=0;c[i]!=0;i++)
{
if(c[i]>='A'&&c[i]<='Z')
c[i]=c[i]+32;
}
for(i=0;i<n;i++)
{
if(c[i]==b[0])
{
d=i;
for(j=0;j<4;d++,j++)
{
if(c[d]!=b[j])
break;
}
if(j==4)
{
printf("soy sauce");
i+=3;
continue;
}
}
printf("%c",a[i]);
}
printf("\n");
}
return 0;
}
参考答案(时间最优[0]):
#include<stdio.h>
#include<string.h>
int main()
{
char a[1000],b[]="salt";
char c[1000];
int i,n,d,j;
while(gets(a)&&a[0]!=EOF)
{
strcpy(c,a);
n=strlen(c);
for(i=0;c[i]!=0;i++)
{
if(c[i]>='A'&&c[i]<='Z')
c[i]=c[i]+32;
}
for(i=0;i<n;i++)
{
if(c[i]==b[0])
{
d=i;
for(j=0;j<4;d++,j++)
{
if(c[d]!=b[j])
break;
}
if(j==4)
{
printf("soy sauce");
i+=3;
continue;
}
}
printf("%c",a[i]);
}
printf("\n");
}
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。