QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708835 | #2939. Morse Code Palindromes | sefnuray# | AC ✓ | 64ms | 53860kb | Java11 | 2.9kb | 2024-11-04 08:26:13 | 2024-11-04 08:26:13 |
Judging History
answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class MorseCodePalindrome {
static BufferedReader br;
static PrintWriter out;
static StringTokenizer st;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
String[] english = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
"m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
"y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
};
String[] morse = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----",
"..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.",
};
String input = readLine().toLowerCase();
StringBuilder mInp = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (Character.isLetterOrDigit(c)) {
for (int j = 0; j < english.length; j++) {
if (english[j].charAt(0) == c) {
mInp.append(morse[j]);
break;
}
}
}
}
if (mInp.length() == 0) {
out.println("NO");
} else {
boolean isPalindrome = true;
int len = mInp.length();
for (int i = 0; i < len / 2; i++) {
if (mInp.charAt(i) != mInp.charAt(len - i - 1)) {
isPalindrome = false;
break;
}
}
if (isPalindrome) {
out.println("YES");
} else {
out.println("NO");
}
}
out.close();
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine().trim());
return st.nextToken();
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readCharacter() throws IOException {
return next().charAt(0);
}
static String readLine() throws IOException {
return br.readLine().trim();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 48ms
memory: 49000kb
input:
hello
output:
NO
result:
ok single line: 'NO'
Test #2:
score: 0
Accepted
time: 46ms
memory: 52604kb
input:
159
output:
YES
result:
ok single line: 'YES'
Test #3:
score: 0
Accepted
time: 39ms
memory: 53860kb
input:
Madam I'm Adam
output:
NO
result:
ok single line: 'NO'
Test #4:
score: 0
Accepted
time: 64ms
memory: 50676kb
input:
footstool
output:
YES
result:
ok single line: 'YES'
Test #5:
score: 0
Accepted
time: 63ms
memory: 50120kb
input:
SOS
output:
YES
result:
ok single line: 'YES'
Test #6:
score: 0
Accepted
time: 58ms
memory: 53672kb
input:
e'UX73XB
output:
YES
result:
ok single line: 'YES'
Test #7:
score: 0
Accepted
time: 43ms
memory: 49100kb
input:
R2WE&s?FI$ggAvgZQKDMJIAUKDAESIME8R
output:
YES
result:
ok single line: 'YES'
Test #8:
score: 0
Accepted
time: 58ms
memory: 49016kb
input:
4n'dA9KqAO.3ghkPLZ9?B e,h%3RmjCENTTQC75IA1IMFATRN4O3MEYNN0SK6
output:
YES
result:
ok single line: 'YES'
Test #9:
score: 0
Accepted
time: 54ms
memory: 52680kb
input:
zvnoMVQM4ZeCgYu;PxkjHSWKWUACWAPNTSOHOJ3OWEESTT
output:
YES
result:
ok single line: 'YES'
Test #10:
score: 0
Accepted
time: 56ms
memory: 48456kb
input:
3n2B0?nJ8s$XYv8:P,S%8q78OtJemC2fs39?BAHjZvNut1iYPCMm%Nh5AHKE5PqMfIDHg8AD
output:
NO
result:
ok single line: 'NO'
Test #11:
score: 0
Accepted
time: 57ms
memory: 50788kb
input:
h3yH6eTyv;enjUAzi9F%LsMB S$I47IDDEOTIUTCWNENNIMPSAIUNOSII
output:
YES
result:
ok single line: 'YES'
Test #12:
score: 0
Accepted
time: 51ms
memory: 48440kb
input:
mCu?&i8Nl
output:
NO
result:
ok single line: 'NO'
Test #13:
score: 0
Accepted
time: 64ms
memory: 48728kb
input:
zDA%tcl
output:
NO
result:
ok single line: 'NO'
Test #14:
score: 0
Accepted
time: 50ms
memory: 49644kb
input:
5rjGHXsxk&1:ms7M,;CsHTJ3EE1MEYEREL6AOTF5
output:
YES
result:
ok single line: 'YES'
Test #15:
score: 0
Accepted
time: 47ms
memory: 48708kb
input:
gsNbp1VyHZ'bw$kVNKo.:FOVwGDATK2CTTEERMTHDT6MATEITTZ7RBEM
output:
YES
result:
ok single line: 'YES'
Test #16:
score: 0
Accepted
time: 53ms
memory: 48436kb
input:
NVXdeaCzadO6jo,lk?YLUkM
output:
NO
result:
ok single line: 'NO'
Test #17:
score: 0
Accepted
time: 44ms
memory: 48988kb
input:
2z?&PcYWbfxM.V0KRtfnoceK;U$4hV&yEp1pMMV4IAyiU5GN1ilY0
output:
NO
result:
ok single line: 'NO'
Test #18:
score: 0
Accepted
time: 55ms
memory: 49072kb
input:
dYq06,'k3FF6R'Hp6ji1BOY,yw2wpWWWDTKYNTMN2TTSMBUWI4EIFTEEAUTIRBJONMMEX
output:
YES
result:
ok single line: 'YES'
Test #19:
score: 0
Accepted
time: 56ms
memory: 49080kb
input:
p5OKcG:is CZVARdi08;Lm?6ar3NXN3mRh,NclzLuqA,VBFzGin 8z
output:
NO
result:
ok single line: 'NO'
Test #20:
score: 0
Accepted
time: 53ms
memory: 52776kb
input:
M:AqX&, &D.if0GES7gDzPRJlnzUnsOPnr:N:s
output:
NO
result:
ok single line: 'NO'
Test #21:
score: 0
Accepted
time: 50ms
memory: 49964kb
input:
Rheh6SB8gCEv%7:ej0HN'JvpS,XIwPr1%&l&'R
output:
NO
result:
ok single line: 'NO'
Test #22:
score: 0
Accepted
time: 50ms
memory: 51348kb
input:
S!!!### ###!!!
output:
YES
result:
ok single line: 'YES'
Test #23:
score: 0
Accepted
time: 34ms
memory: 49076kb
input:
A!!!### ###!!!
output:
NO
result:
ok single line: 'NO'
Test #24:
score: 0
Accepted
time: 57ms
memory: 50220kb
input:
A!!!##N# ###!!!
output:
YES
result:
ok single line: 'YES'
Test #25:
score: 0
Accepted
time: 54ms
memory: 50584kb
input:
!!!#### .....,,,,???............##########################
output:
NO
result:
ok single line: 'NO'
Test #26:
score: 0
Accepted
time: 54ms
memory: 48776kb
input:
SSSSSSSSSSSSSSSSSSSSOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOSSSSSSSSSSSSSSSSSSSS
output:
YES
result:
ok single line: 'YES'
Test #27:
score: 0
Accepted
time: 38ms
memory: 49016kb
input:
output:
NO
result:
ok single line: 'NO'