#include (849)#include using namespace std; int main(){ string str; while(cin>>str){ for(int i=str.size()-1;i>=0;i--){ cout<<str[i]; } cout<<endl; } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); String s1 = new StringBuilder(s).reverse().toString(); System.out.println(s1); } }当然也可以如下一行解决,但没必要
import java.util.Scanner; public class Main02 { public static void main(String[] args) { System.out.println(new StringBuilder(new Scanner(System.in).nextLine()).reverse().toString()); } }
#include<stdio.h> #include<string.h> int main (){//the shorter,the better. char str[200],c;int i,n; for(;~scanf("%s",str);) for(n=strlen(str),i=n-1;i>=0;i?printf("%c",str[i]):printf("%c\n",str[i]),i--); }
#include <iostream> #include <algorithm> using namespace std; int main() { string str; while(cin >> str) { reverse(str.begin(),str.end()); cout << str << endl; } return 0; }
#include <iostream> using namespace std; int main() { char str[201]; while (cin >> str) { int len = 0 ; for (; str[len] != '\0' ; len++); for (int i = len - 1, j = 0 ; j < len / 2 ; i--, j++) swap(str[i], str[j]); for (int i = 0 ; i < len ; i++) cout << str[i]; cout << endl; } return 0; }只有我这么憨憨的吗…
#include<iostream> using namespace std; int main() { string str; string::iterator it; while(cin>>str) { for(it = str.end()-1;it!=str.begin()-1;it--) cout<<*it; cout<<endl; } }
#include<iostream> #include<string> using namespace std; int main(){ string str; while(cin >> str){ for(int i = str.size() - 1; i >= 0; i--){ cout << str[i]; } cout << endl; } return 0; }