用C将字符串打散成3个字符一组,每组按固定字符替换,然后输出替换结果

[复制链接]
查看11 | 回复1 | 2009-7-1 14:56:15 | 显示全部楼层 |阅读模式
程序如下,已在win-tc和dev-c++下编译通过,结果正确。#include#include#includeint main(){
int i,j=0;
char s[256]={'\0'},b[256]={'\0'};
printf("Please input a string:\n");
gets(s);
for(i=0;i<strlen(s)-2;i+=3)
if(s=='1'&&s[i+1]=='1'&&s[i+2]=='1')
{
b[j]='w';
b[j+1]='o';
j+=2;
}
else if(s=='1'&&s[i+1]=='1'&&s[i+2]=='2')
{
b[j]='a';
b[j+1]='i';
j+=2;
}
else if(s=='1'&&s[i+1]=='1'&&s[i+2]=='3')
{
b[j]='n';
b[j+1]='i';
j+=2;
}
printf("The result is:\n");
printf("%s\n",b);
system("pause");
return 0;}
回复

使用道具 举报

千问 | 2009-7-1 14:56:15 | 显示全部楼层
100分……动手写写吧~~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行