字符串
转换后的逆序字符串超过20个字符时的打印
I like coding
gnidoc ekil I
I want to restart 2020
The string you entered has exceeded the limit
您输入的字符串已超出限制
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()){
String str = sc.nextLine();
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
if(str.length() > 20){
System.out.println("The string you entered has exceeded the limit");
break;
}
for(int i = 0; i<str.length();i++){
sb.append(str.charAt(i));
}
for(int i = sb.length()-1; i>=0;i--){
sb1.append(str.charAt(i));
}
System.out.println(sb1);
}
}
} class Solution: def strReverse(self, p): a = [] if len(p) > 20: return "The string you entered has exceeded the limit" for each in p: a.append(each) a.reverse() b = "".join(a) return b if __name__ == "__main__": gifts = input() function = Solution() results = function.strReverse(gifts) print(results)