1 条题解
-
0
C :
#include <stdio.h> #include <string.h> int main() { char encode[101], decode[101]; int i, length; gets(encode); length = strlen(encode); decode[length] = '\0'; for (i = 0;i < length;i++) { if ('A' <= encode[i] && encode[i] <= 'Z') { decode[i] = 'A' + ('Z' - encode[i]); } else if ('a' <= encode[i] && encode[i] <= 'z') { decode[i] = 'a' + ('z' - encode[i]); } else { decode[i] = encode[i]; } } puts(decode); return 0; }
C++ :
#include <stdio.h> #include <string.h> int main() { char encode[101], decode[101]; int i, length; gets(encode); length = strlen(encode); decode[length] = '\0'; for (i = 0;i < length;i++) { if ('A' <= encode[i] && encode[i] <= 'Z') { decode[i] = 'A' + ('Z' - encode[i]); } else if ('a' <= encode[i] && encode[i] <= 'z') { decode[i] = 'a' + ('z' - encode[i]); } else { decode[i] = encode[i]; } } puts(decode); return 0; }
Pascal :
var i:longint; s,sa:string; function turn(c:char):char; var ch:char; begin ch:=upcase(c); if( not(ch in ['A'..'Z']) ) then exit(c); ch:=chr( ord('A')+ord('Z')-ord(ch) ); if(upcase(c)=c) then exit(ch) else exit(lowercase(ch)); end; begin readln(s); sa:=''; for i:=1 to length(s) do sa:=sa+turn(s[i]); writeln(sa); end.
Java :
import java.util.Scanner; public class Main { private static Scanner s = new Scanner(System.in) ; public static void main(String[] args) { String str = s.nextLine() ; System.out.println(f(str)); } public static String f(String str){ char c[] = str.toCharArray() ; for (int i = 0; i < c.length; i++) { if(c[i]>='a'&&c[i]<='z') c[i] = (char) ('a'+24-(c[i]-'a')+1) ; else if(c[i]>='A'&&c[i]<='Z'){ c[i] = (char) ('A'+24-(c[i]-'A')+1) ; } } return new String(c) ; } }
- 1
信息
- ID
- 1306
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者