字符串操作二(串)
时间: 1ms 内存:64M
描述:
输入一行字符串(只包含字母),截取最后一位放首位,然后其它的取每一位给asc码+3 。测试数据有多组,一次性输入与输出。
输入:
输出:
示例输入:
asdf
awxz
示例输出:
fdvg
zdz{
提示:
参考答案(内存最优[748]):
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char *p;
p=(char*)malloc(20*sizeof(char));
while(scanf("%s",p)!=EOF)
{
printf("%s",&p[strlen(p)-1]);
p[strlen(p)-1]='\0';
for(int i=0;i<strlen(p);i++) p[i]+=3;
printf("%s\n\n",p);
}
free(p);
return 0;
}
参考答案(时间最优[0]):
#include <stdio.h>
#include <string.h>
int main()
{
int i;
char a[20];
while(gets(a+1))
{
int len = strlen(a+1);
if(len == 0)
{
a[0]=0;
}
else
{
a[0] = a[len];
a[len]=0;
for(i=1; i<len; i++)
{
a[i]=a[i]+3;
}
}
puts(a);
}
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。