字符逆序
来源:互联网 发布:mac 查看安装的程序 编辑:程序博客网 时间:2024/05/16 16:58
字符逆序
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。
Input
输入包括一行。
第一行输入的字符串。
第一行输入的字符串。
Output
输出转换好的逆序字符串。
Example Input
I am a student
Example Output
tneduts a ma I
#include<stdio.h>
#include<string.h>int main(void)
{
char str[100], a;
int i, n, j;
gets(str);
n = strlen(str);
i = 0;
j = i + n - 1;
while(i < j)
{
a = str[i];
str[i] = str[j];
str[j] = a;
i++;
j--;
}
puts(str);
return 0;
}
//strcpy 是对字符串copy 而不会 对字符copy
阅读全文