Michael Scofield’s letter(HDOJ 2140)

Michael Scofield’s letter
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5180 Accepted Submission(s): 2951

Problem Description
I believe many people are the fans of prison break. How clever Michael is!! In order that the message won’t be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the heart of Sara. Now can you write a program to help Sara encode the letter from Michael easily?
The letter from Michael every time is a string of lowercase letters. You should encode letters as the rules below:
b is ’ ', q is ‘,’, t is ‘!’, m is l, i is e, c is a, a is c, e is i, l is m. It is interesting. Are you found that it is just change michael to leahcim?

Input
The input will consist of several cases, one per line.
Each case is a letter from Michael, the letteres won’t exceed 10000.

Output
For each case, output the encode letter one line.

Sample Input
pmicsibforgevibliqbscrct
ebmovibyout

Sample Output
please forgive me, sara!
i love you!

这道题前面几次都超时了:

**第一次:**Time Limit Exceeded
#include<stdio.h>
#include<string.h>

int main()
{
char a[10001];
while(scanf("%s",&a)!=EOF)
{
for(int i=0;i<strlen(a);i++)
{
if(a[i]‘b’)
{
a[i]=’ ';
}else if(a[i]
‘q’)
{
a[i]=’,’;
}else if(a[i]‘t’)
{
a[i]=’!’;
}else if(a[i]
‘m’)
{
a[i]=‘l’;
}else if(a[i]‘i’)
{
a[i]=‘e’;
}else if(a[i]
‘c’)
{
a[i]=‘a’;
}else if(a[i]‘a’)
{
a[i]=‘c’;
}else if(a[i]
‘e’)
{
a[i]=‘i’;
}else if(a[i]‘l’)
{
a[i]=‘m’;
}
printf("%c",a[i]);
if(i
strlen(a)-1)
{
printf("\n");
}
}

}

return 0;    

}

第二次: Time Limit Exceeded

#include<stdio.h>
#include<string.h>

int main()
{
char a[10001];
while(scanf("%s",&a)!=EOF)
{
for(int i=0;i<strlen(a);i++)
{
if(a[i]‘b’)
{
//a[i]=’ ';
printf(" ");
}else if(a[i]
‘q’)
{
//a[i]=’,’;
printf(",");
}else if(a[i]‘t’)
{
//a[i]=’!’;
printf("!");
}else if(a[i]
‘m’)
{
//a[i]=‘l’;
printf(“l”);
}else if(a[i]‘i’)
{
//a[i]=‘e’;
printf(“e”);
}else if(a[i]
‘c’)
{
//a[i]=‘a’;
printf(“a”);
}else if(a[i]‘a’)
{
//a[i]=‘c’;
printf(“c”);
}else if(a[i]
‘e’)
{
//a[i]=‘i’;
printf(“i”);
}else if(a[i]==‘l’)
{
printf(“m”);
}else
{
printf("%c",a[i]);
}

        if(i==strlen(a)-1)
        {
            printf("\n");
        }
    }

}

return 0;    

}

第三次 Ac:(把那个换行符移掉了,就差那么一点点时间 导致超时了,大家可以注意一下哦)

#include<stdio.h>
#include<string.h>

int main()
{
char a[10001];
while(scanf("%s",&a)!=EOF)
{
for(int i=0;i<strlen(a);i++)
{
if(a[i]‘b’)
{
//a[i]=’ ';
printf(" ");
}else if(a[i]
‘q’)
{
//a[i]=’,’;
printf(",");
}else if(a[i]‘t’)
{
//a[i]=’!’;
printf("!");
}else if(a[i]
‘m’)
{
//a[i]=‘l’;
printf(“l”);
}else if(a[i]‘i’)
{
//a[i]=‘e’;
printf(“e”);
}else if(a[i]
‘c’)
{
//a[i]=‘a’;
printf(“a”);
}else if(a[i]‘a’)
{
//a[i]=‘c’;
printf(“c”);
}else if(a[i]
‘e’)
{
//a[i]=‘i’;
printf(“i”);
}else if(a[i]==‘l’)
{
printf(“m”);
}else
{
printf("%c",a[i]);
}

    }
    printf("\n");
}

return 0;    

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值