字符串反转:给定 n 组字符串,每组字符串个数不超过 20,输出每组字符串的反串;
Input:
3
nwpu
china
xi an
Output:
upwn
anihc
na ix
#include <iostream>;
#include <stdio.h>
#include <string.h>
int const maxn = 30;
int main(void)
{
int n;
scanf("%d", &n);
getchar();//接收回车
char str[n][maxn];
for(int i = 0; i < n; i++)
{
gets(str[i]);//不能用scanf,因为其会吧空格当成结束标志
}
for(int i = 0; i < n; i++)
{
int len = strlen(str[i]);
for(int j = 0; j < len / 2; j++)
{
char temp = str[i][j];
str[i][j] = str[i][len - j - 1];
str[i][len - j - 1] = temp;
}
}
for(int i = 0; i < n; i++)
{
printf("%s\n", str[i]);
}
return 0;
}