1.reverse函数反转string
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
string N;
cin>>N;
reverse(N.begin(), N.end());
cout<<N<<endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
2.reverse函数反转字符数组
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main() {
char a[101];
cin.getline(a,sizeof(a));
int m=strlen(a);
reverse(a,a+m);
puts(a);
}