字符串逆序输出
时间: 1ms 内存:128M
描述:
编写一个函数,功能是使输入的字符串逆序输出。
输入:
输入一串字符串,注意字符串中不要有空格。
输出:
输出该字符串的逆序。
示例输入:
ABCDEFG
示例输出:
GFEDCBA
提示:
参考答案(内存最优[964]):
#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
scanf("%s",str);
int len;
len=strlen(str);
int fuction(char *, int);
fuction(str,len);
return 0;
}int fuction(char *s,int n)
{
for (int i=n-1;i>=0;i--)
{
printf("%c",s[i]);
}
}
参考答案(时间最优[0]):
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str[100];
cin>>str;
int len;
len=strlen(str);
int fuction(char *, int);
fuction(str,len);
return 0;
}
int fuction(char *a, int l)
{
int i;
for(i=l-1;i>=0;i--)
cout<<*(a+i);
cout<<endl;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。