Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A_snake(char snake[]); int B_snake(char snake[]); int main(void) { int quantity, i; char snake[201] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 201; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 201; j++) { if (snake[j] == '=') { count--; } else if (snake[j] != '=') { idx = j; break; } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 201; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2)) && j > 3) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int num, i, o, sum; char line[202]; scanf("%d", &num); for (i = 0; memset(line, 0, sizeof(line)), i < num; i++) { scanf("%s", line); if (line[0] == '>' && line[1] == '\'') { sum = 0; o = 2; while (line[o] != '#' && line[o]) o++, sum++; if (!line[o]) { puts("NA"); continue; } o++; while (line[o] != '~' && line[o]) o++, sum--; if (!line[o]) { puts("NA"); continue; } if (sum == 0 && line[o + 1] == 0) puts("A"); else puts("NA"); } else if (line[0] == '>' && line[1] == '^') { o = 2; while (line[o] != '~' && line[o]) { if (line[o] == 'Q' && line[o + 1] == '=') o += 2; } if (!line[o]) { puts("NA"); continue; } if (line[o + 1] == '~' && line[o + 2] == 0) puts("B"); else puts("NA"); } else puts("NA"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> bool checkA(char st[1001]) { int len = strlen(st); if (st[len - 1] != '~') return false; if (len % 2 == 1) return false; st[len / 2 - 1] = '='; for (int i = 0; i < len - 1; i++) { if (st[i] != '=') return false; } return true; } bool checkB(char st[1001]) { if (st[strlen(st) - 1] != '~' || st[strlen(st) - 2] != '~') return false; for (int i = 0; i < strlen(st) - 2; i += 2) { if (!(st[i] == 'Q' && st[i + 1] == '=')) return false; } return true; } int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char str[1001]; scanf("%s", str); bool Af = false; bool Bf = false; if (str[1] == '\'') { Af = checkA(str + 2); } else { Bf = checkB(str + 2); } if (str[0] != '>') { puts("NA"); } else if (Af == Bf) { puts("NA"); } else if (Af == true) { puts("A"); } else { puts("B"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool isA(const string &str) { int n = str.size(); int m = 0; int pos = 2; if (n == 0 || n == 1) return false; if (str[0] != '>') return false; if (str[1] != '\'') return false; while (pos < n && str[pos] == '=') { m++; pos++; } if (pos == n) return false; if (str[pos++] != '#') return false; while (pos < n && str[pos] == '=') { m--; pos++; } if (pos == n) return false; if (str[pos++] != '~') return false; if (m == 0 && pos == n) return true; return false; } bool isB(const string &str) { int n = str.size(); int pos = 2; int m = 0; if (n == 0 || n == 1) return false; if (str[0] != '>') return false; if (str[1] != '^') return false; while (pos + 1 < n && str[pos] == 'Q' && str[pos + 1] == '=') { m++; pos += 2; } if (m == 0) return false; if (pos + 2 != n) return false; if (str[pos] == '~' && str[pos + 1] == '~') return true; return false; } int main() { int n; string str; getline(cin, str); sscanf(str.c_str(), "%d", &n); while (n-- > 0) { getline(cin, str); if (isA(str)) puts("A"); else if (isB(str)) puts("B"); else puts("NA"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { string str; cin >> str; if (str.size() < 2) cout << "NA" << endl; else if (str[0] == '>' && str[1] == '\'') { int j = 2; int l[2] = {0, 0}; int ck = 0; bool ch[2] = {false, true}; while (j < str.size()) { if (str[j] == '=') l[ck]++; else if (str[j] == '#' && l[0] > 0) ch[0] = true, ck = 1; else if (str[j] == '~') break; else ch[1] = false; j++; } if (ch[0] == true && ch[1] == true && l[0] == l[1]) cout << "A" << endl; else cout << "NA" << endl; } else if (str[0] == '>' && str[1] == '^') { if (str.size() % 2 == 1) cout << "NA" << endl; else { bool ch = true; for (int j = 2; j < str.size() - 2; j += 2) { if (str[j] != 'Q' || str[j + 1] != '=') ch = false; } if (str[str.size() - 2] != '~' || str[str.size() - 1] != '~') ch = false; if (ch == true) cout << "B" << endl; else cout << "NA" << endl; } } else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; bool a[4] = {}, b[3] = {}; int cnt = 0; for (int j = 0; j < s.size(); j++) { if (s[j] == '>') { if (!a[1] && s[j + 1] == '\'') a[0] = true; if (s[j + 1] == '^') b[0] = true; } else if (a[0] && s[j] == '=') { a[1] = true; cnt++; } else if (b[0] && s.substr(j, 2) == "Q=") { b[1] = true; } else if (a[1] && s[j] == '#') { a[0] = false; a[2] = true; } else if (a[2] && s[j] == '=') { cnt--; } else if (a[2] && cnt == 0 && j + 1 == s.size() && s[j] == '~') { a[3] = true; } else if (b[1] && j + 2 == s.size() && s.substr(j, 2) == "~~") { b[2] = true; } } if (a[3]) cout << 'A' << endl; else if (b[2]) cout << 'B' << endl; else cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string vbString(int Number, string Character) { string res = ""; for (int i = 0; i < Number; i++) res += Character; return res; } string checksnake(string s) { string t; for (int i = 1; i < 60; i++) { t = ">'" + vbString(i, "=") + "#" + vbString(i, "=") + "~"; if (t == s) return "A"; } for (int i = 1; i < 60; i++) { t = ">^" + vbString(i, "Q=") + "~~"; if (t == s) return "B"; } return "NA"; } int main() { string s; int n; cin >> n; while (n--) { cin >> s; cout << checksnake(s) << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { bool judge = false; string s; cin >> s; if (s[0] == '>') { if (s[1] == '\'' && s[s.size() - 1] == '~') { if (s[s.size() / 2] == '#' && !(s.size() & 1) && s.size() >= 6) cout << "A" << endl; else judge = true; } else if (s[1] == '^' && s[s.size() - 1] == s[s.size() - 2] && s[s.size() - 1] == '~') { for (int i = 2; i < s.size() - 2; i++) { if ((!(i & 1) && s[i] != 'Q') || (i & 1 && s[i] != '=') || s.size() < 6) judge = true; } if (!judge) cout << "B" << endl; } else judge = true; } else judge = true; if (judge) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool A(string body) { if (int a = body.find("#") != -1 && body.size() % 2 == 0 && body.substr(body.size() - 1, 1) == "~") { for (int i = 0; i < a; i++) { if (body.substr(i, 1) == body.substr(body.size() - 2 - i, 1) && body.substr(i, 1) == "=") { continue; } else return false; } } else return false; return true; } bool B(string body) { if (body.substr(body.size() - 2, 2) == "~~" && body.size() % 2 == 0) { for (unsigned int i = 0; i < body.size() - 2; i += 2) { if (body.substr(i, 2) == "Q=") { continue; } else return false; } } else return false; return true; } int main() { int n; string str; scanf("%d\n", &n); for (int i = 0; i < n; i++) { getline(cin, str); if (str.substr(0, 2) == ">'") { if (A(str.substr(2))) cout << "A" << endl; else cout << "NA" << endl; } else if (str.substr(0, 2) == ">^") { if (B(str.substr(2))) cout << "B" << endl; else cout << "NA" << endl; } else cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A(char snake[]) { int i, num; if (snake[0] != '>' || snake[1] != '\'') { return (0); } i = 2; num = 0; while (snake[i] == '=') { i++; num++; } if (num == 0) { return (0); } if (snake[i++] != '#') { return (0); } while (snake[i] == '=') { i++; num--; } if (snake[i] != '~') { return (0); } if (num == 0) { return (1); } return (0); } int B(char snake[]) { int i; if (snake[0] != '>' || snake[1] != '^') { return (0); } i = 2; while (snake[i] == 'Q' && snake[i + 1] == '=') { i += 2; } if (snake[i] == '~' || snake[i + 1] == '~') { return (1); } return (0); } int main(void) { int i, n; char snake[256]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", snake); if (A(snake)) { puts("A"); } else if (B(snake)) { puts("B"); } else { puts("NA"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char str[201]; int i, j, n, cnt1, cnt2, flag; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", str); cnt1 = 0; cnt2 = 0; flag = 0; if (str[0] == '>') { if (str[1] == '\'') { for (j = 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt1++; if (str[j + 1] == '#') break; } for (j = cnt1 + 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt2++; } if (cnt1 == cnt2 && str[cnt1 + cnt2 + 3] == '~' && str[cnt1 + cnt2 + 4] == '\0') { printf("A\n"); flag = 1; } } else if (str[1] == '^') { for (j = 2; str[j] != '\0'; j = j + 2) { if (str[j] == 'Q' && str[j + 1] == '=') { if (str[j + 2] == '~' && str[j + 3] == '~' && str[j + 4] == '\0') { printf("B\n"); flag = 1; } } } } } if (flag == 0) printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { string s; int n; cin >> n; while (n--) { cin >> s; if (s[0] == '>') { if (s[1] == '\'') { int cnt1 = 0; int i; for (i = 2; s[i] == '='; i++) { cnt1++; } if (s[i] != '#') { cout << "NA" << endl; goto skip; } else i++; int cnt2 = 0; for (; s[i] == '='; i++) { cnt2++; } if (cnt1 == cnt2 && s[i] == '~' && i + 1 == s.size()) cout << "A" << endl; else cout << "NA" << endl; } else if (s[1] == '^') { int x = 2; while (s[x] == 'Q' && s[x + 1] == '=') x += 2; if (s[x] == '~' && s[x + 1] == '~' && x + 2 == s.size()) { cout << "B" << endl; } } else cout << "NA" << endl; } skip:; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { public static void main(String arg[]) { Scanner sc = new Scanner(System.in); int n= sc.nextInt(); while(n-->0) { String str = sc.nextLine(); char ch[] = str.toCharArray(); int counta =0; int countb =0; try{ if(ch[0]=='>'&&ch[1]=='\'' &&ch[ch.length-1]=='~') { int co=2; while(ch[co]!='#') { if(ch[co]=='=') counta++; co++; } while(ch[co]!='~') { if(ch[co]=='=') countb++; co++; } if(counta==countb) { System.out.println("A"); continue; } else { System.out.println("NA"); continue; } } else if(ch[0]=='>'&&ch[1]=='^' &&ch[str.length()-1]=='~'&&ch[str.length()-2]=='~') { boolean flag=false; int co=2; while(ch[co] != '~') { if(ch[co]=='Q'&&ch[co+1]=='=') flag = true; else { flag = false; break; } co+=2; } if(flag == true) System.out.println("B"); } System.out.println("NA"); } catch(Exception e) {} } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
python2
def snakeA(s): if s[:2]==">'" and s[-1]=="~": t=s[2:-1].split("#") if t[0]==t[-1]: return True return False def snakeB(s): if s[:2]==">^" and s[-2:]=="~~": t=s[2:-2] if set(t.split("Q="))==set(['']): return True return False for i in range(input()): s=raw_input() if snakeA(s): print "A" elif snakeB(s): print "B" else: print "NA"
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); while (n-- > 0) { String snake = sc.next(); if (snake.indexOf('#') > 0 && snake.charAt(0) == '>' && snake.charAt(1) == '\'' && snake.charAt(snake.length() - 1) == '~') { String[] l = snake.split("[>'#~]"); if (l[2].length() == l[3].length() && l[2].length() + l[3].length() + 4 == snake.length()) { System.out.println("A"); } else { System.out.println("NA"); } } else if (snake.charAt(0) == '>' && snake.charAt(1) == '^' && snake.charAt(snake.length() - 2) == '~' && snake.charAt(snake.length() - 1) == '~' && snake.replaceAll("Q=", "").equals(">^~~")) { System.out.println("B"); } else { System.out.println("NA"); } } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 25); const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; int main() { int n; int flg = 0; cin >> n; while (n--) { string s; int cnt = 0; flg = 0; cin >> s; if (s[0] == '>') { if (s[1] == '\'') { int equal[2] = {0}; int now = 0; for (int i = 2; i < s.size(); i++) { if (s[i] == '=') { equal[now]++; } else if (s[i] == '#') { now = 1; } } if (equal[0] == equal[1] && s[s.size() - 1] == '~') { flg = 1; } } else if (s[1] == '^') { for (int i = 2; i < s.size() - 2; i += 2) { if (s[i] != 'Q' && s[i] != '=') { break; } cnt = i; } if (cnt == (s.size() - 4) && s[s.size() - 2] == '~' && s[s.size() - 1] == '~') { flg = 2; } } } if (flg == 0) { cout << "NA" << endl; } else if (flg == 1) { cout << 'A' << endl; } else { cout << 'B' << endl; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <stdio.h> #include <math.h> int main(){ int n,i,t,l,gou=0,syucnt[10000]={0}; char input[300]; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%s",input); l = strlen(input); if(input[l-1]=='~'&&input[l-2]=='~'&&input[0]=='>'&&input[1]=='^'){//B種の調べ for(t=2;t<=l-4;t=t+2){ if(input[t]=='Q'&&input[t+1]=='='){ gou++; } } if(gou*2==l-4){ syucnt[i]=2; }else syucnt[i]=3; gou=0; }else if(input[l/2]=='#'&&input[l-1]=='~'&&(l-4)%2==0&&input[0]=='>'&&input[1]=='\''){ int j=2; for(t=0;t<(l-4)/2;t++){ if(input[j]=='='&&input[l-j]=='='){ gou++; } j++; } if(gou==((l-4)/2)){ syucnt[i]=1; }else syucnt[i]=3; gou=0; }else syucnt[i]=3; } for(i=0;i<n;i++){//出力 if(syucnt[i]==1){ puts("A"); }else if(syucnt[i]==2){ puts("B"); }else if(syucnt[i]==3){ puts("NA"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, f, i, m; string s; cin >> n; while (n-- > 0) { cin >> s; f = 0; if (s[0] == '>' && s[1] == '\'') { m = s.find('#'); if (m != string::npos) { for (i = 1; s[m - i] == s[m + i];) i++; if (i > 1 && m - i == 1 && m + i == s.size() - 1 && s[m + i] == '~') f = 1; } } else if (s[0] == '>' && s[1] == '^') { for (i = 2; s[i] == 'Q' && s[i + 1] == '=';) i += 2; if (i == s.size() - 2 && s[i] == '~' && s[i + 1] == '~') f = 2; } if (f) puts(f == 1 ? "A" : "B"); else puts("NA"); } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n, n) { for (int x = 0; x < n; ++x) { string line; cin >> line; string sol = "NA"; if (line.find('#') != string::npos) { bool flag = false; string a = ""; string b = ""; for (int x = 2; x < line.size() - 1; ++x) { if (line[x] == '#') { flag = true; continue; } if (!flag) { a += line[x]; } else { b += line[x]; } } if (line.size() > 3 && line[0] == '>' && line[1] == '\'' && line[line.size() - 1] == '~' && a == b) sol = "A"; } else { bool flag = true; for (int x = 2; line.size() > 4 && x < (line.size() - 3); x += 2) { if (line[x] != 'Q' || line[x + 1] != '=') flag = false; } if (line.size() > 4 && line[0] == '>' && line[1] == '^' && line[line.size() - 1] == '~' && line[line.size() - 2] == '~' && flag) sol = "B"; } cout << sol << endl; } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; int check(string S) { if (S[0] != '>' || S[S.size() - 1] != '~') { return 0; } if (S[1] == '\'') { S = S.substr(2, S.size() - 3); if (S.find_first_not_of("#=", 0) != string::npos) return 0; string tmpB = S.substr(0, S.find('#')); string tmpA = S.substr(S.find('#') + 1, S.size() - 1); return tmpB.size() == tmpA.size() ? 1 : 0; } if (S[1] == '^' && S[S.size() - 2] == '~') { S = S.substr(2, S.size() - 4); if (S.find_first_not_of("Q=", 0) != string::npos) return 0; for (int i = 0; i < S.size(); i += 2) { if (S[i] != 'Q' && S[i + 1] != '=') return 0; } return 2; } return 0; } int main() { int N; cin >> N; vector<string> res{"NA", "A", "B"}; string S; while (cin >> S) { cout << res[check(S)] << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int quantity, i, j, idx, count = 0; char snake[200] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); break; } else if (snake[1] == '\'') { for (j = 2; j < 199; j++) { if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 199; j++) { if (snake[j] != '=') { idx = j; break; } count--; } if (count == 0) { if (snake[idx] == '~') puts("A"); else puts("NA"); } else { puts("NA"); } } else if (snake[1] == '^') { for (j = 2; j < 198; j += 2) { if (snake[j] == 'P') count++; if (snake[j + 1] == '=') count--; if (snake[j] == '~' && snake[j + 1] == '~') break; } if (count == 0) puts("B"); else puts("NA"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char str[201]; int i, j, n, cnt1, cnt2, last, flag; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", str); cnt1 = 0; cnt2 = 0; flag = 0; if (str[0] == '>') { if (str[1] == '\'') { for (j = 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt1++; if (str[j + 1] == '#') break; } for (j = cnt1 + 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt2++; } if (cnt1 == cnt2 && str[cnt1 + cnt2 + 3] == '~') { printf("A\n"); flag = 1; } } else if (str[1] == '^') { for (j = 2; str[j] != '\0'; j = j + 2) { if (str[j] == 'Q' && str[j + 1] == '=') { if (str[j + 2] == '~' && str[j + 3] == '~') { printf("B\n"); flag = 1; } } } } } if (flag == 0) printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n; while (cin >> s) { if (s.size() < 6 || s[0] != '>') { cout << "NA" << endl; break; } int cur = 2, l = 0, l2 = 0, f = 0, f2 = 0; if (s[1] == '\'') { while (cur < s.size()) { if (f2) { f2 = 0; break; } else if (s[cur] == '=') { if (!f) l++; else l2++; } else if (s[cur] == '#') { if (!l || f) break; else f = 1; } else if (s[cur] == '~') { if (l && l == l2) { f2 = 1; } else break; } else break; cur++; } } else if (s[1] == '^') { while (cur < s.size()) { if (f2) { f2 = 0; break; } if (s[cur] == 'Q') { if (!f) f = 1; else break; } else if (s[cur] == '=') { if (f == 1) f = 0; else break; } else if (s[cur] == '~') { if (!f) f = 2; else if (f == 2) f2 = 2; else break; } else break; cur++; } } if (f2 == 1) cout << "A" << endl; else if (f2 == 2) cout << "B" << endl; else cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
using System; namespace AOJ.Volume1 { public class Snakes { public static bool CheckA(string input) { // 先頭は「>'」 if (input.Substring(0, 2) != ">'") { return false; } // 末尾は「~」 if (input.Substring(input.Length - 1, 1) != "~") { return false; } // 真ん中のチェック var tmp = input.Substring(2, input.Length - 3).Split('#'); // 「#」が無いか複数存在 if (tmp.Length != 2) { return false; } string bef = tmp[0], aft = tmp[1]; if (bef.Length == 0 || aft.Length == 0) { return false; } // 「=」以外の文字を含む if (bef.Replace("=", "").Length > 0) { return false; } if (aft.Replace("=", "").Length > 0) { return false; } // 「#」の前と後が同じ長さではない if (bef.Length != aft.Length) { return false; } return true; } public static bool CheckB(string input) { // 先頭は「>^」 if (input.Substring(0, 2) != ">^") { return false; } // 末尾は「~~」 if (input.Substring(input.Length - 2, 2) != "~~") { return false; } // 「Q=」が存在しない if (input.Substring(2, input.Length - 4).Length == 0) { return false; } // 「Q=」以外の文字列が存在する if (input.Replace("Q=", "").Length > 0) { return false; } return true; } public static int Main() { int s = int.Parse(Console.ReadLine()); for (int i = 0; i < s; i++) { string input = Console.ReadLine(); if (CheckA(input)) { Console.WriteLine("A"); } else if(CheckB(input)){Console.WriteLine("B");} else { Console.WriteLine("NA"); } } return 0; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); for(int i = 0; i < n; i++){ char[] str = sc.nextLine().toCharArray(); boolean is_na = false; boolean is_a = false; if(str[0] == '>'){ if(str[1] == '\'' ){ int len = 0; int count = 0; boolean flag = false; for(int j = 2; j < str.length; j++){ if(count == 0 && flag == true){ len = j; break; } if(str[j] == '='){ count += flag ? -1 : 1; }else if(str[j] == '#'){ if(count != 0){ flag = true; }else{ is_na = true; break; } } } if(len == str.length-1 && str[len] == '~'){ is_a = true; }else{ is_na = true; } }else if(str[1] == '^'){ if((str.length - 4)/2 == 0){ is_na = true; } for(int j = 0; j < (str.length - 4)/2; j++){ if(str[j*2 + 2] != 'Q' || str[j*2 + 2 + 1] != '='){ is_na = true; } } if(str[str.length -2] == '~' && str[str.length -1] == '~'){ is_a = false; } }else{ is_na = true; } }else{ is_na = true; } System.out.println(is_na ? "NA" : is_a ? "A" : "B"); } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A_snake(char snake[]); int B_snake(char snake[]); int main(void) { int quantity, i; char snake[300] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 300; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 300; j++) { if (snake[j] == '=') { count--; } else if (snake[j] != '=') { idx = j; break; } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 300; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2))) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int quantity, i, j, idx, count = 0; char snake[200] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[1] == '\'') { for (j = 2; j < 199; j++) { if (snake[j] == '=') count++; else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 199; j++) { if (snake[j] != '=') { idx = j; break; } count--; } if (count == 0) { if (snake[idx] == '~') puts("A"); else puts("NA"); } else { puts("NA"); } } else if (snake[1] == '^') { for (j = 2; j < 198; j += 2) { if (snake[j] != 'Q') { if (snake[j] == '~') { idx = j; break; } else if (snake[j + 1] != '=') { idx = j; break; } } } if (snake[idx] == '~' && snake[idx + 1] == '~') puts("B"); else puts("NA"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int D = 0; D < n; ++D) { string s; cin >> s; if (s.compare(0, 2, ">'") == 0) { int bef_eq = 0; int aft_eq = 0; int shp = 0; int pos_shp = 0; int pos_tld = 0; for (unsigned int i = 2; i < s.length(); ++i) { switch (s[i]) { case '=': if (shp == 0) ++bef_eq; else ++aft_eq; break; case '#': shp++; break; case '~': if (i != s.length() - 1) shp = 2; pos_tld = i; break; default: shp = 2; break; } } if (bef_eq && aft_eq && pos_tld && bef_eq == aft_eq && shp == 1) cout << "A\n"; else cout << "NA\n"; } else if (s.compare(0, 2, ">^") == 0) { int cnt_qeq = 0; int pos_tltl = 0; bool invalid = false; if (s.length() <= 2 || s.length() % 2 == 1) invalid = true; for (unsigned int i = 2; i < s.length() && !invalid; i += 2) { if (s.compare(i, 2, "Q=") == 0) ++cnt_qeq; else if (s.compare(i, 2, "~~") == 0) { pos_tltl = i; break; } else invalid = true; } if (pos_tltl != s.length() - 2) { invalid = true; } if (invalid) cout << "NA\n"; else cout << "B\n"; } else { cout << "NA\n"; } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string solve(string s) { if (s.substr(0, 2) == ">'") { int eq = 0; for (int i = 2; i < s.size(); i++) { if (s[i] != '=') break; else { eq++; } } if (eq == 0) return "NA"; if (s[(2 + eq - 1) + 1] != '#') return "NA"; if (s.substr(((2 + eq - 1) + 1) + 1, eq) != s.substr(2, eq)) return "NA"; if (2 + eq + 1 + eq + 1 == s.size() && s[(2 + eq + 1 + eq + 1) - 1] == '~') return "A"; } else if (s.substr(0, 2) == ">^") { int c = 2; while (s[c] == 'Q' && s[c + 1] == '=') { c += 2; } if (c + 1 == s.size() - 1 && s[c] == '~' && s[c + 1] == '~') return "B"; else return "NA"; } else return "NA"; return "NA"; } int main() { int n; cin >> n; for (int i = 0; i < (n); i++) { string s; cin >> s; cout << solve(s) << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s; cin >> s; if (s == ">'" + string((s.size() - 4) / 2, '=') + '#' + string((s.size() - 4) / 2, '=') + '~') { cout << 'A' << endl; } else { int r = (s.size() - 4) / 2; string b; while (r--) { b += "Q="; } if (s == ">^" + b + "~~") { cout << 'B' << endl; } else { cout << "NA" << endl; } } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s; int size = s.size(); string A = ""; string B = ""; for (int i = 0; i < size; i++) { if (i == 0) { A += ">"; B += ">"; } else if (i == 1) { A += "'"; B += "^"; } else { if (i < size - 1) { if (i == (size - 3) / 2 + 2) A += "#"; else A += "="; } else A += "~"; if (i < size - 2) { if (i % 2 == 0) B += "Q"; else B += "="; } else { B += "~"; } } } if (s == A) cout << "A" << endl; else if (s == B) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int i, n; string s; cin >> n; while (n--) { cin >> s; if (s[0] == '>' && s[1] == '\'' && s.size() % 2 == 0) { for (i = 2; i < s.size(); i++) { if (i == s.size() / 2 && s[i] != '#') break; if (i == s.size() / 2) { i++; continue; } if (i == s.size() - 1 && s[i] == '~') { cout << "A" << endl; goto L; } if (s[i] != '=') { cout << i; break; } } } else if (s[0] == '>' && s[1] == '^' && s[3] == 'Q') { for (i = 2; i < s.size(); i++) { if (i == s.size() - 2 && s[i] == '~' && s[i + 1] == '~') { cout << "B" << endl; goto L; } if (s[i] != 'Q' || s[i + 1] != '=') break; else i++; } } cout << "NA" << endl; L:; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static readonly string NA = "NA"; static void Main(string[] args) { StringBuilder sb = new StringBuilder(); int n = int.Parse(Console.ReadLine()); while (n-- > 0) { string s = Console.ReadLine(); string head = s.Substring(0, 2); switch (head) { case ">'": sb.AppendLine(CheckA(s)); break; case ">^": sb.AppendLine(CheckB(s)); break; default: sb.AppendLine(NA); break; } } Console.Write(sb); } static string CheckA(string s) { if (s[s.Length - 1] != '~') return NA; string temp = s.Substring(2, s.Length - 3); string[] t = temp.Split('#'); if (t.Length != 2) return NA; if (t[0].Length != t[1].Length) return NA; if (t[0].Any(u => u != '=')) return NA; if (t[1].Any(u => u != '=')) return NA; return "A"; } static string CheckB(string s) { string tale = s.Substring(s.Length - 2, 2); if (tale != "~~") return NA; string temp = s.Substring(2, s.Length - 4); temp = temp.Replace("Q=", ""); if (temp.Length != 0) return NA; return "B"; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <iostream> #include <string> using namespace std; string solv(string s){ int ss = s.size(); if(s[0] != '>' || s[ss-1] != '~')return "NA"; if(s[ss-2] == '~'){ if(s[1] != '^')return "NA"; for(int i = 0;i < ss-2;i++){ if(s[i] == 'Q' && s[i+1] == '=')return "B"; } }else{ fi(s[1] != ''')return "NA"; int a = 0, f = 0; for(int i = 1;i < ss-1;i++){ if(s[i] == '=' && !f)a++; if(s[i] == '#')f = 1; if(f && !a)return "NA"; if(s[i] == '=' && f)a--; } return a ? "NA" : "A"; } return "NA"; } int main(){ int n;cin >> n; string s; while(n--){ cin >> s; cout << solv(s) << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int max, data; int num; int cut_i; char hebi[] = "特に意味のない文章"; scanf("%d", &max); for (data = 0; data < max; data++) { scanf("%s", hebi); if (strlen(hebi) < 2 || hebi[0] != '>') { puts("NA"); continue; } if (hebi[1] == '\'') { num = 0; cut_i = 2; while (hebi[cut_i] == '=') { cut_i++; num++; } if (hebi[cut_i] != '#' || num <= 0) { puts("NA"); } else { cut_i++; while (hebi[cut_i] == '=') { cut_i++; num--; } if (num != 0) { puts("NA"); } else if (hebi[cut_i] != '~' || hebi[cut_i + 1] != 0) { puts("NA"); } else { puts("A"); } } } else if (hebi[1] == '^') { cut_i = 2; while (hebi[cut_i] == 'Q' && hebi[cut_i + 1] == '=') { cut_i += 2; } if (cut_i == 2) { puts("NA"); } else if (hebi[cut_i] != '~' || hebi[cut_i + 1] != '~' || hebi[cut_i + 2] != 0) { puts("NA"); } else { puts("B"); } } else { puts("NA"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char str[201]; int i, j, n, cnt1, cnt2, flag; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", str); cnt1 = 0; cnt2 = 0; flag = 0; if (str[0] == '>') { if (str[1] == '\'') { for (j = 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt1++; if (str[j + 1] == '#') break; } for (j = cnt1 + 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt2++; } if (cnt1 == cnt2 && str[cnt1 + cnt2 + 3] == '~' && str[cnt1 + cnt2 + 4] == '\0') { printf("A\n"); flag = 1; } } else if (str[1] == '^') { for (j = 2; str[j] != '\0'; j++) { if (j % 2 == 0) { if (str[j] == 'Q' && str[j + 1] == '=') { if (str[j + 2] == '~' && str[j + 3] == '~' && str[j + 4] == '\0') { printf("B\n"); flag = 1; } } else break; } } } } if (flag == 0) printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
char s[101],a[50],b[50],t,t2; Q(){ int i; for(i=0;a[i];i+=2) if(a[i]!='Q'||a[i+1]!='=') return 0; return i>=2; } main(){ scanf("%*d\n"); for(;~scanf("%[^\n]\n",s);){ if(sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&t2)==3&&t=='~'&&strlen(a)==strlen(b)) puts("A"); else if(sscanf(s,">^%[Q=]~%c%c",a,&t,&t2)==2&&t=='~'&&Q()) puts("B"); else puts("NA"); } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string in; int isA() { if (in[0] != '>') return 0; if (in[1] != '\'') return 0; if (!(in[in.length() - 1] == '~' && in[in.length() - 2] == '=')) return 0; int data[2] = {0, 0}; int status = 0; for (int i = 2; i < in.length() - 1; i++) { if (in[i] == '#') status = 1; if (in[i] == '=') data[status]++; } if (data[0] == data[1]) return 1; return 0; } int isB() { if (in[0] != '>') return 0; if (in[1] != '^') return 0; if (!(in[in.length() - 1] == '~' && in[in.length() - 2] == '~')) return 0; for (int i = 2; i < in.length() - 2; i += 2) { if (!(in[i] == 'Q' && in[i + 1] == '=')) return 0; } return 1; } int main() { int num; cin >> num; for (int i = 0; i < num; i++) { cin >> in; if (isA()) cout << "A" << endl; else if (isB()) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> char s[201]; int A(int p, int st, int c) { if (st == 2 && c == 0 && s[p] == 0) return 1; else if (st == 1 && s[p] == '~') return A(p + 1, st + 1, c); else if (st == 1 && s[p] == '=') return A(p + 1, st, c - 1); else if (st == 0 && s[p] == '#') return A(p + 1, st + 1, c); else if (st == 0 && s[p] == '=') return A(p + 1, st, c + 1); else return 0; } int B(int p, int st) { if (st == 3 && s[p] == 0) return 1; else if (p > 3 && (st == 1 || st == 2) && s[p] == '~') return B(p + 1, st + 1); else if (st == 0 && s[p] == '=') return B(p + 1, 1); else if (st == 1 && s[p] == 'Q') return B(p + 1, 0); else return 0; } int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", s); if (s[0] == '>' && s[1] == '\'' && A(2, 0, 0)) puts("A"); else if (s[0] == '>' && s[1] == '^' && B(2, 1)) puts("B"); else puts("NA"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { int n, i, j; char s[100001]; scanf("%d", &n); while (n--) { scanf("%s", s); if (s[0] != '>') { printf("NA"); continue; } if (s[1] == '\'') { for (i = 2; s[i] == '='; i++) ; for (j = 1; s[i - j] == '=' && s[i + j] == '='; j++) ; if (i - j == 1 && s[i + j] == '~' && s[i + j + 1] == 0 && s[i] == '#' && i - 2) printf("A\n"); else printf("NA\n"); } else if (s[1] == '^') { for (i = 2; s[i] == 'Q' && s[i + 1] == '='; i += 2) ; if (s[i] == '~' && s[i + 1] == '~' && s[i + 2] == 0 && i - 2) printf("B\n"); else printf("NA\n"); } else printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
char s[101];A(){char a[101],b[101],t,t2;return sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&t2)==3&&t=='~'&&strlen(a)==strlen(b);}B(){short*q;char*p=s,l=0;if(*(q=p++)=='^>'){for(;*(q=++p)=='=Q';p++)l++;if(l>0&&*(q=p++)=='~~'&&*++p==0)return 1;}return 0;}main(){scanf("%*d\n");for(;~scanf("%[^\n]\n",s);){if(A())puts("A");else if(B())puts("B");elseputs("NA");}}
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int Judge(string &s) { if (s[0] != '>') return -1; if (s.size() < 2) return -1; if (s[1] == '\'') { if (s[s.size() - 1] != '~') return -1; int len = ((int)s.size()) - 3; if (len % 2 == 0) return -1; for (int i = 0; i < ((len - 1) / 2); i++) { if (s[2 + i] != '=' || s[2 + len / 2 + 1] != '=') return -1; } if (s[2 + len / 2] != '#') return -1; return 0; } else if (s[1] == '^') { if (s[s.size() - 1] != '~' || s[s.size() - 2] != '~') return -1; int len = ((int)s.size()) - 4; if (len < 2 || len % 2 != 0) return -1; for (int i = 0; i < (len / 2); i++) { if (s[2 + 2 * i] != 'Q' || s[2 + 2 * i + 1] != '=') return -1; } return 1; } else { return -1; } } int main() { int n; cin >> n; string out[] = {"NA", "A", "B"}; for (int i = 0; i < (n); i++) { string s; cin >> s; int a = Judge(s); cout << out[a + 1] << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int Judge(string &s) { if (s[0] != '>') return -1; if (s.size() < 2) return -1; if (s[1] == '\'') { if (s[s.size() - 1] != '~') return -1; int len = ((int)s.size()) - 3; if (len < 3 || len % 2 == 0) return -1; for (int i = 0; i < ((len - 1) / 2); i++) { if (s[2 + i] != '=' || s[2 + len / 2 + 1] != '=') return -1; } if (s[2 + len / 2] != '#') return -1; return 0; } else if (s[1] == '^') { if (s[s.size() - 1] != '~' || s[s.size() - 2] != '~') return -1; int len = ((int)s.size()) - 4; if (len < 2 || len % 2 != 0) return -1; for (int i = 0; i < (len / 2); i++) { if (s[2 + 2 * i] != 'Q' || s[2 + 2 * i + 1] != '=') return -1; } return 1; } else { return -1; } } int main() { int n; cin >> n; string out[] = {"NA", "A", "B"}; for (int i = 0; i < (n); i++) { string s; cin >> s; int a = Judge(s); cout << out[a + 1] << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s; cin >> s; bool f = s[0] == '>'; int l = s.size(); f &= l > 5; if (s[1] == '\'') { int x = 0; int i; for (i = 2; i < l; i++) { if (s[i] == '=') x++; else { f &= s[i] == '#'; break; } } for (i++; i < l; i++) { if (s[i] == '=') x--; else { f &= s[i] == '~'; break; } } f &= i == l - 1 && x == 0; } else if (s[1] == '^') { int i; for (i = 2; i < l; i += 2) { if (!(i + 1 < l)) { f = 0; break; } if (s[i] == 'Q' && s[i + 1] == '=') continue; if (s[i] == '~' && s[i + 1] == '~') continue; } f &= i == l; } else f = 0; cout << (f ? (s[1] == '^' ? "B" : "A") : "NA") << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
STDOUT.sync = true n = gets.to_i n.times do str = gets.chomp! size = (str.size - 4) / 2 stra = ">'" strb = ">^" size.times do stra += '=' strb += 'Q=' end stra += '#' size.times do stra += '=' end stra += "~" strb += '~~' if (str == stra) puts "A" elsif (str == strb) puts "B" else puts "NA" end end
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using namespace placeholders; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<vector<int> >; using VS = vector<string>; using ISS = istringstream; using OSS = ostringstream; using PII = pair<int, int>; using VPII = vector<pair<int, int> >; template <typename T = int> using VT = vector<T>; template <typename T = int> using VVT = vector<vector<T> >; template <typename T = int> using LIM = numeric_limits<T>; template <typename T> inline istream &operator>>(istream &s, vector<T> &v) { for (T &t : v) { s >> t; } return s; } template <typename T> inline ostream &operator<<(ostream &s, const vector<T> &v) { for (int i = 0; i < int(v.size()); ++i) { s << (" " + !i) << v[i]; } return s; } template <typename T> struct getv_fmt; template <> struct getv_fmt<int> { static constexpr const char *fmt = "%d"; }; template <> struct getv_fmt<long long> { static constexpr const char *fmt = "%lld"; }; template <typename T> void getv(std::vector<T> &v) { for_each(begin(v), end(v), [](T &a) { scanf(getv_fmt<T>::fmt, &a); }); }; template <typename T> inline T fromString(const string &s) { T res; istringstream iss(s); iss >> res; return res; } template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); } template <typename T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } bool is_a(const string &S) { const int Ls = ((int)(S).size()); if (S.find(">'") != 0 || S.find("~") != Ls - 1) { return false; } string T = S.substr(2, Ls - 3); const int Lt = ((int)(T).size()); if (Lt % 2 == 0 || T[Lt / 2] != '#') { return false; } T[Lt / 2] = '='; return all_of(begin(T), end(T), bind(equal_to<char>(), _1, '=')); } bool is_b(const string &S) { const int Ls = ((int)(S).size()); if (S.find(">^") != 0 || S.find("~~") != Ls - 2) { return false; } const string T = S.substr(2, Ls - 4); const int Lt = ((int)(T).size()); if (Lt == 0 || Lt % 2) { return false; } for (int i = 0; i < Lt; i += 2) { if (T[i] != 'Q' || T[i + 1] != '=') { return false; } } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12) << fixed; int N; cin >> N; for (int REP_COUNTER_135 = (int)(0); REP_COUNTER_135 < (int)(N); ++REP_COUNTER_135) { string S; cin >> S; string res = "NA"; if (is_a(S)) { res = "A"; } if (is_b(S)) { res = "B"; } cout << res << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A(char snake[]) { int i, num; if (snake[0] != '>' || snake[1] != '\'') { return (0); } i = 2; num = 0; while (snake[i] == '=') { i++; num++; } if (snake[i++] != '#') { return (0); } while (snake[i] == '=') { i++; num--; } if (snake[i] != '~') { return (0); } if (num == 0) { return (1); } return (0); } int B(char snake[]) { int i; if (snake[0] != '>' || snake[1] != '^') { return (0); } i = 2; while (snake[i] == 'Q' && snake[i + 1] == '=') { i += 2; } if (snake[i] == '~' || snake[i + 1] == '~') { return (1); } return (0); } int main(void) { int i, n; char snake[256]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", snake); if (A(snake)) { puts("A"); } else if (B(snake)) { puts("B"); } else { puts("NA"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A_snake(char snake[]); int B_snake(char snake[]); int main(void) { int quantity, i; char snake[210] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 210; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 210; j++) { if (snake[j] == '=') { count--; } else if (snake[j] == '~') { idx = j; break; } else { return (0); } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 210; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2)) && j > 3) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int quantity, i, j, idx, count = 0; char snake[200] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { for (j = 2; j < 199; j++) { if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 199; j++) { if (snake[j] == '=') { count--; } else if (snake[j] != '=') { idx = j; break; } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') puts("A"); else puts("NA"); } else { puts("NA"); } } else if (snake[1] == '^') { for (j = 2; j < 198; j += 2) { if (snake[j] == 'Q') count++; if (snake[j + 1] == '=') count--; if (snake[j] == '~' && snake[j + 1] == '~') { idx = j; break; } } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) puts("B"); else puts("NA"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { string str; int n; cin >> n; while (n--) { cin >> str; int idx = 2; int cnt = 0; bool flg = true; if (str[0] == '>' && str[1] == 39) { while (idx < str.size() && str[idx] != '#') { cnt++; idx++; } idx++; while (idx < str.size() && str[idx] != '~') { cnt--; idx++; } if (cnt == 0) { cout << "A" << endl; flg = false; } } else if (str[0] == '>' && str[1] == '^') { while (idx + 1 < str.size() && str[idx] == 'Q' && str[idx + 1] == '=') { idx += 2; } if (str[idx] == '~' && str[idx + 1] == '~') { cout << "B" << endl; flg = false; } } if (flg) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { string str; int n; cin >> n; while (n--) { cin >> str; int idx = 2; int cnt = 0; bool flg = true; if (str[0] == '>' && str[1] == 39) { while (str[idx] != '#') { cnt++; idx++; } idx++; while (str[idx] != '~') { cnt--; idx++; } if (cnt == 0) { cout << "A" << endl; flg = false; } } else if (str[0] == '>' && str[1] == '^') { while (str[idx] == 'Q' && str[idx + 1] == '=') { idx += 2; } if (str[idx] == '~' && str[idx + 1] == '~') { cout << "B" << endl; flg = false; } } if (flg) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool check_A(string str) { if (str.size() < 6 || str.size() % 2 == 1) { return false; } if (str.substr(0, 2) != ">'") { return false; } int count = 0; for (int i = 2; i < (str.size() - 4) / 2 + 2; i++) { if (str[i] != '=') { return false; } } if (str[str.size() / 2] != '#') { return false; } for (int i = str.size() / 2 + 1; i < str.size() - 2; i++) { if (str[i] != '=') { return false; } } if (str[str.size() - 1] != '~') { return false; } return true; } bool check_B(string str) { if (str.size() < 6 || str.size() % 2 == 1) { return false; } if (str.substr(0, 2) != ">^") { return false; } for (int i = 2; i < str.size() - 2; i += 2) { if (str.substr(i, 2) != "Q=") { return false; } } if (str.substr(str.size() - 2, 2) != "~~") { return false; } return true; } int main() { int n; string str; cin >> n; for (int loop = 0; loop < n; loop++) { cin >> str; if (check_A(str)) { printf("A\n"); } else if (check_B(str)) { printf("B\n"); } else { printf("NA\n"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; bool check_A(string &S) { auto sz = S.size(); if (S.find(">'=") == 0 && S.find("~") == sz - 1 && sz >= 6) { S = S.substr(2, sz - 3); sz = S.size(); if (S.find_first_not_of("#=", 0) != string::npos) { return 0; } auto pos = S.find("#"); if (S.find("#", pos + 1) != string::npos) { return 0; } if (S[sz / 2] != '#' || sz % 2 == 0) { return 0; } return 1; } return 0; } bool check_B(string &S) { auto sz = S.size(); if (S.find(">^Q=") == 0 && S.find("~~") == sz - 2) { S = S.substr(2, sz - 4); sz = S.size(); if (sz % 2 != 0) { return 0; } for (int i = 0; i < sz; i += 2) { if (S[i] != 'Q' && S[i + 1] != '=') { return 0; } } return 1; } return 0; } int main() { int N; cin >> N; vector<string> res{"NA", "A", "B"}; for (int i = 0; i < (N); i++) { string S; cin >> S; cout << res[check_A(S) ? 1 : check_B(S) ? 2 : 0] << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <string> #include <iostream> using namespace std; int n; string s; bool check() { if(s.size() < 6) return 0; if(s[0] != '>') return 0; if(s[1] != '\'') { int cnt = 0; for(int i = 2; i < s.size() - 1; i++) { if(s[i] != '=') break; cnt++; } if(s[2 + cnt] != '#') return 0; for(int j = cnt + 3; j < s.size(); j++) { if(s[i] != '=') break; cnt--; } if(cnt) return 0; if(2 + cnt + 1 != s.size()) return 0; return s[2 + cnt] == '~' ? 1 : 0; } if(s[1] != '^') { int cnt = 0; for(int i = 2; i < s.size() - 2; i += 2) { if(s[i] != 'Q' || s[i + 1] != '=') break; cnt += 2; } if(cnt + 4 != s.size()) return 0; return (s[cnt + 2] == '~' && s[cnt + 3] == '~') ? 2 : 0; } return 0; } int main() { scanf("%d", &n); for(int i = 0; i < n; i++) { cin >> s; printf("%s\n", !check() ? "NA" : (check() == 1 ? "A" : "B")); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { public static void main(String arg[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); while(n-->0) { char ch[] = in.next().toCharArray(); int counta =0; int countb =0; boolean flag=false; if(ch[0]=='>'&&ch[1]=='\'' &&ch[ch.length-1]=='~') { int co=2; while(ch[co]!='#') { if(ch[co]=='=') counta++; co++; if(co==ch.length-1) break; } while(ch[co]!='~') { if(ch[co]=='=') countb++; co++; } if(counta==countb&&counta>0) System.out.println("A"); else System.out.println("NA"); continue; } else if(ch[0]=='>'&&ch[1]=='^' &&ch[ch.length-1]=='~'&&ch[ch.length-2]=='~') { for(int co=2;co<ch.length-2;co+=2) { if(ch[co]=='Q'&&ch[co+1]=='=') flag = true; else { flag = false; break; } } } System.out.println(flag==true ? "B":"NA"); } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; int main() { int n; cin >> n; for (int q = (0); q < unsigned long long(n); ++q) { string s; cin >> s; bool p = true; if (s.substr(0, 2) == ">'") { s = s.substr(2); int c = 0; for (int i = 0; i < s.size(); i++) if (s[i] == '=') { c++; } else break; if (s[c] != '#') p = false; s = s.substr(c + 1); if (c + 1 != s.size() || s[s.size() - 1] != '~') p = false; for (int i = (0); i < unsigned long long(c); ++i) if (s[i] != '=') p = false; cout << (p ? "A" : "NA") << endl; } else if (s.substr(0, 2) == ">^") { s = s.substr(2); while (s.substr(0, 2) == "Q=") s = s.substr(2); cout << (s == "~~" ? "B" : "NA") << endl; } else { cout << "NA" << endl; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static readonly string NA = "NA"; static void Main(string[] args) { StringBuilder sb = new StringBuilder(); int n = int.Parse(Console.ReadLine()); while (n-- > 0) { string s = Console.ReadLine(); string head = s.Substring(0, 2); switch (head) { case ">'": sb.AppendLine(CheckA(s)); break; case ">^": sb.AppendLine(CheckB(s)); break; default: sb.AppendLine(NA); break; } } Console.Write(sb); } static string CheckA(string s) { if (s[s.Length - 1] != '~') return NA; string temp = s.Substring(2, s.Length - 3); string[] t = temp.Split('#'); if (t.Length != 2) return NA; if (t[0].Length != t[1].Length) return NA; temp = temp.Replace("=", ""); if (temp != "#") return NA; return "A"; } static string CheckB(string s) { string tale = s.Substring(s.Length - 2, 2); if (tale != "~~") return NA; string temp = s.Substring(2, s.Length - 4); temp = temp.Replace("Q=", ""); if (temp.Length != 0) return NA; return "B"; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string S; int n; string solve(string T) { int chain = 0, ok = 0; if (T.size() >= 3) { if (T[T.size() - 1] == '~') { if (T.substr(0, 2) == ">'" && T.size() >= 6) { for (int i = 2; i < T.size() - 1; i++) { if (T[i] == '#') { ok++; } else { if (ok == 0) { chain++; } else { chain--; } } } if (ok == 1 && chain == 0) { return "A"; } } if (T.substr(0, 2) == ">^" && T[T.size() - 2] == '~' && T.size() >= 6) { for (int i = 2; i < T.size() - 2; i += 2) { if (T.substr(i, 2) != "Q=") { goto E; } } return "B"; E:; } } } return "NA"; } int main() { cin >> n; for (int h = 0; h < n; h++) { cin >> S; cout << solve(S) << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, size; string s, a, b; for (cin >> n; n > 0; n--) { cin >> s; size = s.size(); if (size % 2) { cout << "NA" << endl; continue; } a = ">'"; b = ">^"; for (int i = 0; i < size / 2 - 2; i++) { a = a + "="; b = b + "Q="; } a += "#"; for (int i = 0; i < size / 2 - 2; i++) { a = a + "="; } a += "~"; b += "~~"; if (s == a) cout << "A" << endl; else if (s == b) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { bool b; int n, i, j, t, c[2]; char s[201]; cin >> n; for (i = 0; i < n; i++) { b = true; cin >> s; if (s[0] == '>') { if (s[1] == '\'') { for (j = 2, t = c[0] = c[1] = 0; j < strlen(s) - 1; j++) { if (s[j] == '=') c[t]++; else if (t = 0 && s[j] == '#') t++; else { b = false; break; } } if (b && c[0] == c[1] && s[strlen(s) - 1] == '~') cout << "A" << endl; else cout << "NA" << endl; continue; } else if (s[1] == '^') { for (j = 2; j < strlen(s) - 2; j += 2) { if (s[j] != 'Q' || s[j + 1] != '=') { b = false; break; } } if (b && s[strlen(s) - 2] == '~' && s[strlen(s) - 1] == '~') cout << "B" << endl; else b = false; continue; } else b = false; } else b = false; if (!b) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char A, B; char snake[256]; int n; int cnt; int i, j, len1, len2; scanf("%d", &n); for (i = 0; i < n; i++) { A = B = 0; scanf("%s", snake); if (snake[0] == '>' && snake[1] == '\'') { j = 2; len1 = 0; while (snake[j] != '#' && snake[j] == '=' && snake[j] != '\0') { len1++; j++; } if (snake[j] == '#') { j++; len2 = 0; while (snake[j] != '~' && snake[j] == '=' && snake[j] != '\0') { len2++; j++; } if (len1 == len2 && len1 > 0 && snake[j + 1] == '\0') { A = 1; } } } else if (snake[0] == '>' && snake[1] == '^') { j = 2; len1 = 0; len2 = 1; while (snake[j] != '~') { if (j % 2 == 0 && snake[j] != 'Q') { len2 = 0; break; } if (j % 2 == 1 && snake[j] != '=') { len2 = 0; break; } j++; len1++; } if (len2 && snake[j + 1] == '~' && len1 > 0 && len1 % 2 == 0 && snake[j + 2] == '\0') { B = 1; } } if (A) { printf("A\n"); } else if (B) { printf("B\n"); } else { printf("NA\n"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, size; string s, a, b; for (cin >> n; n > 0; n--) { cin >> s; size = s.size(); a = ">'"; b = ">^"; for (int i = 0; i < size / 2 - 2; i++) { a = a + "="; b = b + "Q="; } a += "#"; for (int i = 0; i < size / 2 - 2; i++) { a = a + "="; } a += "~"; b += "~~"; if (s == a) cout << "A" << endl; else if (s == b) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s; cin >> s; string head = s.substr(0, 2); bool ok = true; if (head == ">'") { int c = 0; for (int i = (2); i < (s.size()); ++i) { if (s[i] != '=') break; c++; } if (s[c + 2] != '#') ok = false; else if (s.substr(c + 3, c) != string(c, '=')) ok = false; else if (s.size() != c * 2 + 4) ok = false; else if (s[s.size() - 1] != '~') ok = false; puts(ok ? "A" : "NA"); } else if (head == ">^") { for (int i = 2; i < s.size() - 2; i += 2) if (s.substr(i, 2) != "Q=") { ok = false; break; } if (ok && s.substr(s.size() - 2) != "~~") ok = false; puts(ok ? "B" : "NA"); } else puts("NA"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool isA(string s) { int cnt1 = 0; for (int i = 2; i < s.size(); ++i) { if (s[i] == '=') { ++cnt1; } else if (s[i] == '#') { break; } else { return false; } } int cnt2 = 0; for (int i = cnt1 + 3; i < s.size(); ++i) { if (s[i] == '=') { ++cnt2; } else if (s[i] == '~') { return cnt1 == cnt2; } else { return false; } } return false; } bool isB(string s) { if (s.size() % 2) return false; for (int i = 2; i < s.size(); i += 2) { if (s[i] == 'Q' && s[i + 1] == '=') { continue; } else if (s[i] == '~' && s[i + 1] == '~') { return true; } else { return false; } } return false; } int main() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i < n; ++i) { if (s[i][0] != '>' || s[i].size() == 2) { cout << "NA" << endl; continue; } if (s[i][1] == '\'') { cout << ((isA(s[i])) ? "A" : "NA") << endl; } else if (s[i][1] == '^') { cout << ((isB(s[i])) ? "B" : "NA") << endl; } else { cout << "NA" << endl; } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int z = 0; z < n; z++) { string a; cin >> a; string b = a.substr(0, 2), c = a.substr(a.length() - 2, 2); if (b == ">'") { if (c[1] == '~') { int d[2] = {0, 0}, e = 0; bool f = false; for (int i = 2; i < a.length() - 1; i++) { if (a[i] == '=') { while (a[i] == '=') { i++; d[e]++; } e++; } if (a[i] == '#') { f = true; } } if (f == true && d[0] == d[1]) { cout << "A" << endl; goto stop; } } } if (b == ">^") { if (c == "~~") { for (int i = 2; i < a.length() - 2; i++) { string d = a.substr(i, 2); if (d == "Q=") { cout << "B" << endl; goto stop; } } } } cout << "NA" << endl; stop:; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
# Aizu Problem 00139: Snakes # import sys, math, os, copy # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def is_A_snake(snake): if snake[1] != "'": return False snake = snake[2:-1] segments = snake.split('#') if len(segments) != 2: return False L = len(segments[0]) target = '=' * L for segment in segments: if segment != target: return False return True def is_B_snake(snake): if snake[1] != "^" or snake[-2] != '~' or snake[2] != 'Q' or snake[-3] != '=': return False snake = snake[2:-2] L = len(snake) return snake == "Q=" * (L // 2) n = int(input()) for _ in range(n): snake = input().strip() if snake[0] != '>' or snake[-1] != '~': print("NA") else: if '#' in snake: print("A" if is_A_snake(snake) else "NA") else: print("B" if is_B_snake(snake) else "NA")
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
gets.to_i.times do s = gets.chomp if s =~ /^>(?:.*)(=+)#\1~$/ puts ?A elsif s =~ /^>(?:.*)(Q=)+(?:.*)~$/ puts ?B else puts 'NA' end end
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
import scala.io.StdIn.{readInt,readLine} object Main { def find(s:String) = { if(s.length<2) "NA" else if(s(0)=='>') { if(s(1) == ''') { // maybeA if(isA && s(s.length-1)=='~') "A" else "NA" } else if (s(1) == '^') { // maybeB var isB = true for(i<-2 until s.length-2 by 2) { if(s(i)!='Q' || s(i+1)!='=') { isB = false } } if(isB && s(s.length-2)=='~' && s(s.length-1)=='~') "B" else "NA" } else { "NA" } } else "NA" } def main(args:Array[String]) = { val n = readInt for(i<-1 to n) { val s = readLine.trim println(find(s)) } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A_snake(char snake[]); int B_snake(char snake[]); int main(void) { int quantity, i; char snake[200] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 199; j++) { if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 199; j++) { if (snake[j] == '=') { count--; } else if (snake[j] != '=') { idx = j; break; } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 198; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (snake[j] == '~' && snake[j + 1] == '~') { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') return (1); } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
class Ex(Exception): pass n=int(input()) for i in range(n): try: snk=input() l=len(snk) head=snk[:2] body=snk[2:l-1] tail=snk[l-1] if tail!='~' or snk[0]!='>': print("NA") continue spl_a=body.split('#') if len(spl_a)==2 and spl_a[0]==spl_a[1] and len(spl_a[0])!=0: for char in spl_a[0]: if char!='=': print("NA") raise Ex() if head[1]=='\'': print('A') raise Ex() else: print("NA") raise Ex() bars=body.split('=') for j in range(len(bars)-1): if bars[j]!='Q': print("NA") raise Ex() if head[1]=='^'and bars[len(bars)-1]=='~':print('B') else:print("NA") except Ex:pass
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> void Atype(); void Btype(); void wrong(); int A, B; char b[200]; int main() { int n, i; char a; scanf("%d", &n); for (i = 0; i < n; i++) { A = 0; B = 0; scanf("%s", b); if (b[0] != '>') wrong(); else { if (b[1] == '\'') Atype(); else if (b[1] == '^') Btype(); else wrong(); } if (A == 0) { printf("A\n"); } else if (B == 0) { printf("B\n"); } else { printf("NA\n"); } } return 0; } void Atype() { B = 1; int x, y, i; char c; x = 0; y = 0; while (1) { if (b[2 + x] != '=') { break; } x++; } if (b[2 + x] != '#') wrong(); while (1) { if (b[3 + x + y] != '=') { break; } y++; } if (x != y) wrong(); if (b[3 + x + y] != '~') wrong(); if (b[4 + x + y] != '\0') wrong(); } void Btype() { A = 1; int x = 1; char c, q; while (1) { if (b[2 * x] == 'Q' && b[2 * x + 1] == '=') { x++; continue; } else break; } if (b[2 * x] == '~' && b[2 * x + 1] == '~') B = 0; else wrong(); if (b[2 * x + 2] != '\0') wrong(); } void wrong() { A = 1; B = 1; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { int i, j, n, f; char s[210]; scanf("%d", &n); while (n--) { scanf("%s", s); if (s[0] == '>' && s[1] == '\'') { i = 2; f = 0; while (1) { if (s[i] == '#') break; if (s[i] == '=') f++; else { f = 0; break; } i++; } if (f == 0) printf("NA\n"); else { for (j = 0; j < f; j++) if (s[i + j + 1] != '=') break; if (j == f) { if (s[i + f + 1] == '~') printf("A\n"); else printf("NA\n"); } else printf("NA\n"); } } else if (s[0] == '>' && s[1] == '^') { for (i = 2; i < strlen(s) - 2; i += 2) { if (s[i] != 'Q' || s[i + 1] != '=') break; } if (i == strlen(s) - 2) { if (s[i] == '~' && s[i + 1] == '~') printf("B\n"); else printf("NA\n"); } else printf("NA\n"); } else printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N, j; cin >> N; while (N--) { int runcnt = 0, j; char S[150] = {0}; cin >> S; if (S[0] == '>' && S[1] == 39) { int K = 0; for (j = 2; j < 1000; j++) { if (S[j] == '=') { runcnt++; K = 1; } else if (S[j] == '#') { break; } else { cout << "NA" << endl; break; } } for (int i = j + 1; i < 1000; i++) { if (S[i] == '=') { runcnt--; } else if (runcnt == 0 && S[i] == '~' && K == 1) { cout << "A" << endl; break; } else { cout << "NA" << endl; break; } } } else if (S[0] == '>' && S[1] == '^') { int F = 0; for (j = 2; j < 1000;) { if (S[j] == 'Q' && S[j + 1] == '=') { j += 2; F = 1; } else if (S[j] == '~' && S[j + 1] == '~' && F == 1) { cout << "B" << endl; break; } else { cout << "NA" << endl; break; } } } else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { int n, c, h, i; char s[201]; scanf("%d", &n); while (n--) { scanf("%s", s); if (s[c = 0] != '>' || s[h = 1] != '\'' && s[1] != '^') { printf("NA\n"); continue; } for (i = 2; s[i]; i++) { if (s[1] == '\'') { if (s[i] == '=') c += h; if (s[i] == '#') { if (h == -1) break; h *= -1; } if (s[i] == '~') { if (c != 0) break; } } else { if (s[i] == 'Q' && s[i + 1] == '=') i++; else if (s[i] != '~') break; } } if (s[i]) printf("NA\n"); else { if (s[1] == '\'') { if (s[i - 2] == '=') printf("A\n"); else printf("NA\n"); } else { if (s[i - 3] == '=') printf("B\n"); else printf("NA\n"); } } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-8; int main(void) { int n; cin >> n; while (n--) { string snake; cin >> snake; if (snake[0] == '>' && snake[1] == '\'' && snake[snake.size() - 1] == '~') { int count = 0; int end; for (int i = 2; i < snake.size() && snake[i] == '='; i++) { count++; end = i; } end++; if (count && snake[end] == '#' && end + count + 2 == snake.size()) { bool yes = true; for (int i = end + 1; i < snake.size() - 1; i++) { if (snake[i] != '=') yes = false; } if (yes) { cout << "A" << endl; } else { cout << "NA" << endl; } } else { cout << "NA" << endl; } } else if (snake[0] == '>' && snake[1] == '^' && snake[snake.size() - 1] == '~' && snake[snake.size() - 2] == '~') { bool yes = true; for (int i = 2; i < snake.size() - 2; i++) { if (i % 2 == 0 && snake[i] != 'Q') yes = false; if (i % 2 == 1 && snake[i] != '=') yes = false; } if (yes) { cout << "B" << endl; } else { cout << "NA" << endl; } } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string repeat(int n, string s) { string res = ""; for (int i = 0; i < n; ++i) res += s; return res; } int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { string snake; cin >> snake; int len = snake.size(); if (len % 2 == 1) { cout << "NA" << endl; continue; } string A = ">'" + repeat((len - 4) / 2, "=") + "#" + repeat((len - 4) / 2, "=") + "~"; string B = ">^" + repeat((len - 4) / 2, "Q=") + "~~"; if (snake == A) { cout << "A" << endl; } else if (snake == B) { cout << "B" << endl; } else { cout << "NA" << endl; } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string judgeSnakeType(string s) { if (s.find(">'") == 0 && s.find("~") == s.size() - 1) { int mark = 0; int cnt = 0; for (int i = 2; i < s.size(); i++) { if (mark == 0 && s[i] == '=') { mark = 1; cnt++; } else if (mark == 1 && s[i] == '=') { cnt++; } else if (s[i] == '#') { if (mark == 0) return "NA"; if (mark == 1) mark = 2; } else if (mark == 2 && s[i] == '=') { mark = 3; cnt--; } else if (mark == 3 && s[i] == '=') { cnt--; } } if (mark != 3 || cnt != 0) return "NA"; return "A"; } else if (s.find(">^") == 0 && s.find("~~") == s.size() - 2) { bool isMark = false; for (int i = 2; i < s.size() - 2; i++) { if (!((i % 2 == 0 && s[i] == 'Q') || (i % 2 == 1 && s[i] == '='))) { return "NA"; } else { isMark = true; } } if (!isMark) return "NA"; return "B"; } else { return "NA"; } } void solve(string snake) { cout << judgeSnakeType(snake) << endl; } int main() { int d; cin >> d; string snake; for (int i = 0; i < d; i++) { cin >> snake; solve(snake); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int max, data; int num; int cut_i; char hebi[] = " "; scanf("%d", &max); for (data = 0; data < max; data++) { scanf("%s", hebi); if (strlen(hebi) < 2 || hebi[0] != '>') { puts("NA"); continue; } if (hebi[1] == '\'') { num = 0; cut_i = 2; while (hebi[cut_i] == '=') { cut_i++; num++; } if (hebi[cut_i] != '#' || num <= 0) { puts("NA"); } else { cut_i++; while (hebi[cut_i] == '=') { cut_i++; num--; } if (num != 0) { puts("NA"); } else if (hebi[cut_i] != '~' || hebi[cut_i + 1] != 0) { puts("NA"); } else { puts("A"); } } } else if (hebi[1] == '^') { cut_i = 2; while (hebi[cut_i] == 'Q' && hebi[cut_i + 1] == '=') { cut_i += 2; } if (cut_i == 2) { puts("NA"); } else if (hebi[cut_i] != '~' || hebi[cut_i + 1] != '~' || hebi[cut_i + 2] != 0) { puts("NA"); } else { puts("B"); } } else { puts("NA"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { /** * @param args */ int solve(String str) { final int HEAD=0; final int EYE_A=1; final int EYE_B=2; final int BODY_A1=3; final int BODY_A2=4; final int BODY_B=5; final int STOMACH_A=6; final int TAIL_A=7; final int TAIL_B=8; int state=-1; int count=0; for(int i=0;i<str.length();++i) { switch(str.charAt(i)) { case '>': if(state==-1){state=HEAD;} else{return 2;} break; case '\'': if(state==HEAD){state=EYE_A;} else{return 2;} break; case '^': if(state==HEAD){state=EYE_B;} else{return 2;} break; case 'Q': if(state==EYE_B){state=BODY_B;} if(state!=BODY_B||str.charAt(++i)!='='){return 2;} break; case '=': if(state==EYE_A||state==BODY_A1){state=BODY_A1;++count;} else if(state==STOMACH_A||state==BODY_A2){state=BODY_A2;--count;} break; case '#': if(state==BODY_A1){state=STOMACH_A;} else{return 2;} break; case '~': if(state==BODY_A2&&count==0){state=TAIL_A;} else if(state==BODY_B){state=TAIL_B;} else if(state==TAIL_B&&count<2){++count;} else{return 2;} } } return state==TAIL_A?0:1; } void io() { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i<n;++i) { String str=sc.next(); switch(solve(str)) { case 0: System.out.println('A'); break; case 1: System.out.println('B'); break; case 2: System.out.println("NA"); break; } } } public static void main(String[] args) { // TODO Auto-generated method stub new Main().io(); } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char snake[200]; int n, cnt1 = 0, cnt2 = 0, i, j = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", snake); while (1) { if (snake[j] == '>') { j++; if (snake[j] == '\'') { j++; while (1) { if (snake[j] == '=') { j++; cnt1++; } else if (snake[j] == '#') { j++; while (1) { if (snake[j] == '=') { j++; cnt2++; } else if (snake[j] == '~') { if (cnt1 == cnt2) { puts("A"); break; } else { puts("NA"); break; } break; } else { puts("NA"); break; } } break; } else { puts("NA"); break; } } break; } else if (snake[j] == '^') { j++; while (1) { if (snake[j] == 'Q' && snake[j + 1] == '=') { j += 2; } else { break; } } if (snake[j] == '~' && snake[j + 1] == '~') { puts("B"); } break; } else { puts("NA"); break; } } else { puts("NA"); break; } } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; static const double eps = 10e-9; bool isA(string str) { if (str.substr(0, 2) != ">'") return false; string rear = str.substr(2, str.size() - 2); int eq = count(rear.begin(), rear.end(), '='); int shrp = count(rear.begin(), rear.end(), '#'); int til = count(rear.begin(), rear.end(), '~'); if (shrp != 1 || (eq + shrp + til) != rear.size() || til != 1) return false; int lhs = 0; int rhs = 0; bool flag = true; for (int i = 0; i < rear.size() - 1; i++) { if (rear[i] == '#') { flag = false; continue; } flag ? lhs++ : rhs++; } return lhs == rhs && lhs != 0; } bool isB(string str) { if (str.substr(0, 2) != ">^") return false; string rear = str.substr(2, str.size() - 2); bool isok = false; int i; for (i = 2; i < rear.size();) { if (rear.substr(i, 2) == "Q=") { isok = true; i += 2; } else break; } return (isok && rear.substr(i, 2) == "~~") && (i + 2 == rear.size()); } int main() { int n; while (~scanf("%d", &n)) { for (int i = 0; i < n; i++) { string str; cin >> str; if (isA(str)) cout << "A" << endl; else if (isB(str)) cout << "B" << endl; else cout << "NA" << endl; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { string snake; cin >> snake; if (snake.length() < 2) { puts("NA"); continue; } if (snake[0] == '>' && snake[1] == '\'') { int cnt = 0; int j; for (j = 2; j < snake.length(); j++) { if (snake[j] == '#') break; cnt++; } int n = 0; for (j += 1; j < snake.length(); j++) { if (snake[j] == '~') break; n++; } if (cnt != n || j != snake.length() - 1) { puts("NA"); } else { puts("A"); } } else if (snake[0] == '>' && snake[1] == '^') { bool flag = true; string s = ""; for (int i = 2; i < snake.length(); i++) { if (snake[i] == '~') break; s += snake[i]; if (s.length() == 2) { if (s != "Q=" || s != "~~") flag = false; s = ""; } } if (flag) puts("B"); else puts("NA"); } else { puts("NA"); } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s; cin >> s; string::const_iterator beg = s.begin(); try { if (*beg != '>') throw -1; beg++; if (*beg == '\'') { beg++; int eq_count = 0; while (*beg == '=') { if (beg == s.end()) throw -1; eq_count++; beg++; } if (*beg != '#') throw -1; beg++; int c = 0; while (*beg == '=') { if (beg == s.end()) throw -1; c++; beg++; } if (eq_count != c) throw -1; if (*beg != '~') throw -1; beg++; if (beg != s.end()) throw -1; cout << "A" << endl; } else if (*beg == '^') { beg++; bool f = false; while (1) { if (f && *beg != 'Q') break; f = true; if (*beg != 'Q') throw -1; beg++; if (*beg != '=') throw -1; beg++; } if (*beg != '~') throw -1; beg++; if (*beg != '~') throw -1; beg++; if (beg != s.end()) throw -1; cout << "B" << endl; } else throw -1; } catch (int e) { cout << "NA" << endl; continue; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { int n, i, j; char s[100001]; scanf("%d", &n); while (n--) { scanf("%s", s); if (s[0] != '>') { printf("NA"); continue; } if (s[1] == '\'') { for (i = 3; s[i] == '='; i++) ; for (j = 1; s[i - j] == '=' && s[i + j] == '='; j++) ; if (i - j == 1 && s[i + j] == '~' && s[i + j + 1] == 0 && s[i] == '#' && j - 1) printf("A\n"); else printf("NA\n"); } else if (s[1] == '^') { for (i = 2; s[i] == 'Q' && s[i + 1] == '='; i += 2) ; if (s[i] == '~' && s[i + 1] == '~' && s[i + 2] == 0 && i - 2) printf("B\n"); else printf("NA\n"); } else printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; static const double PI = 6 * asin(0.5); static const int INF = 1 << 24; template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } int main() { int n; cin >> n; for (int(i) = (0); (i) < ((n)); ++(i)) { string s; cin >> s; if (s.substr(0, 2) == ">'" && s.substr(s.size() - 1, 1) == "~") { s = s.substr(2); s = s.substr(0, s.size() - 1); bool f = true; while (s.size() > 1) { if (s[0] == s[s.size() - 1] && s[0] == '=') { s = s.substr(1, s.size() - 2); } else { f = false; break; } } if (f) { if (s[0] == '#') { cout << "A\n"; } else cout << "NA\n"; } else { cout << "NA\n"; } } else if (s.substr(0, 2) == ">^" && s.substr(s.size() - 2, 2) == "~~") { s = s.substr(2); s = s.substr(0, s.size() - 2); bool f = true; while (s.size() >= 2) { if (s.substr(0, 2) == "Q=") { s = s.substr(2); } else { f = false; break; } } if (f) { cout << "B\n"; } else cout << "NA\n"; } else { cout << "NA\n"; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
//package _0139; import java.util.*; import java.lang.*; import java.math.*; public class Main { Scanner sc = new Scanner(System.in); boolean isA(String snake) { if (snake.startsWith(">'")) { if (snake.endsWith("~")) { String mid = snake.substring(2, snake.length() - 1); if (mid.length() >= 3) { String[] spl = mid.split("#", 2); if (spl[0].equals(spl[1])) { for (int i = 0; i < spl[0].length(); i++) { if ('=' != spl[0].charAt(i)) { return false; } } return true; } } } } return false; } boolean isB(String snake) { if (snake.startsWith(">^")) { if (snake.endsWith("~~")) { String mid = snake.substring(2, snake.length() - 2); if (mid.length() >= 2) { while (mid.startsWith("Q=")) { mid = mid.substring(2); } if (mid.equals("")) { return true; } } } } return false; } /* * >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ */ String getAns(String snake) { String ret = "NA"; if (snake.startsWith(">'")) { if (isA(snake)) ret = "A"; } else if (snake.startsWith(">^")) { if (isB(snake)) ret = "B"; } return ret; } void run() { int n = sc.nextInt(); for (int i = 0; i < n; i++) { System.out.println(getAns(sc.next())); } } public static void main(String[] args) { Main m = new Main(); m.run(); } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int quantity, i, j, idx, count = 0; char snake[200] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); break; } else if (snake[1] == '\'') { for (j = 2; j < 199; j++) { if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 199; j++) { if (snake[j] != '=') { idx = j; break; } count--; } if (count == 0) { if (snake[idx] == '~') puts("A"); else puts("NA"); } else { puts("NA"); } } else if (snake[1] == '^') { for (j = 2; j < 198; j += 2) { if (snake[j] == 'Q') count++; if (snake[j + 1] == '=') count--; if (snake[j] == '~' && snake[j + 1] == '~') break; } if (count == 0) puts("B"); else puts("NA"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char w[201]; int a, i, j, k; scanf("%d", &a); for (j = 0; j < a; j++) { gets(w); if (w[0] != '>') { printf("NA\n"); continue; } if (w[1] == '\'') { for (i = 2; w[i] != '#'; i++) { if (w[i] != '=') { printf("NA\n"); continue; } } int t = i - 1; for (k = t + 1; t > 0; t--) { if (w[i++] != '=') { printf("NA\n"); continue; } } if (w[i++] != '~') { printf("NA\n"); continue; } if (w[i] != '\0') { printf("NA\n"); continue; } printf("A\n"); } if (w[1] == '^') { for (i = 2; w[i] == '~'; i += 2) { if (w[i] != 'Q') { printf("NA\n"); continue; } if (w[i + 1] != '=') { printf("NA\n"); continue; } } if (w[i] != '~') { printf("NA\n"); continue; } if (w[i + 1] != '~') { printf("NA\n"); continue; } if (w[i + 2] != '\0') { printf("NA\n"); continue; } printf("B\n"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char A, B; char snake[256]; int n; int cnt; int i, j, len1, len2; scanf("%d", &n); for (i = 0; i < n; i++) { A = B = 0; scanf("%s", snake); if (snake[0] == '>' && snake[1] == '\'') { j = 2; len1 = 0; while (snake[j] != '#' && snake[j] != '\0') { len1++; j++; } if (snake[j] == '#') { j++; } len2 = 0; while (snake[j] != '~' && snake[j] != '\0') { len2++; j++; } if (len1 == len2 && len1 > 0 && snake[j + 1] == '\0') { A = 1; } } else if (snake[0] == '>' && snake[1] == '^') { j = 2; len1 = 0; while (snake[j] != '~') { if (j % 2 == 0 && snake[j] != 'Q') { break; } if (j % 2 == 1 && snake[j] != '=') { break; } j++; len1++; } if (snake[j + 1] == '~' && len1 > 0 && len1 % 2 == 0 && snake[j + 2] == '\0') { B = 1; } } if (A) { printf("A\n"); } else if (B) { printf("B\n"); } else { printf("NA\n"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int main(void) { char str[] = "特に意味のない文章"; int cut_i, cut_j; int len, kaisu; int hantei; scanf("%d", &kaisu); for (cut_i = 0; cut_i < kaisu; cut_i++) { scanf("%s", str); len = strlen(str); hantei = 0; if ((len < 5) || (str[0] != '>') || (len % 2 != 0)) { printf("NA\n"); continue; } len--; if ((str[1] == '\'') && (str[len] == '~')) { cut_j = 2; while (str[cut_j] == '=') { hantei++; cut_j++; } if (str[cut_j] != '#') { printf("NA\n"); continue; } cut_j++; while (str[cut_j] == '=') { hantei--; cut_j++; } if (hantei == 0) { printf("A\n"); } else { printf("NA\n"); } } else if ((str[1] == '^') && (str[len - 1] == str[len]) && (str[len] == '~')) { for (cut_j = 2; cut_j < len - 2; cut_j++) { if ((str[cut_j] != 'Q') || (str[cut_j + 1] != '=')) { hantei = -1; } cut_j++; } printf("B\n"); } else { printf("NA\n"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { bool b; int n, i, j, t, c[2]; char s[201]; cin >> n; for (i = 0; i < n; i++) { b = true; cin >> s; if (s[0] == '>') { if (s[1] == '\'') { for (j = 2, t = c[0] = c[1] = 0; j < strlen(s) - 1; j++) { if (s[j] == '=') c[t]++; else if (t == 0 && s[j] == '#') t++; else { b = false; break; } } if (b && c[0] > 0 && c[0] == c[1] && s[strlen(s) - 1] == '~') cout << "A" << endl; else cout << "NA" << endl; continue; } else if (s[1] == '^') { for (j = 2; j < strlen(s) - 2; j += 2) { if (s[j] != 'Q' || s[j + 1] != '=') { b = false; break; } } if (b && s[strlen(s) - 2] == '~' && s[strlen(s) - 1] == '~') cout << "B" << endl; else b = false; continue; } else b = false; } else b = false; if (!b) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int in; cin >> in; for (int i = 0; i < in; i++) { int status = 0; string snake; cin >> snake; if (snake[0] != '>') { cout << "NA" << endl; continue; } if (snake[1] == '^') { for (int j = 2; j < snake.size() - 2; j += 2) { if (snake[j] != 'Q' || snake[j + 1] != '=') { cout << "NA" << endl; status = 1; break; } } if (snake[snake.size() - 2] == '~' && snake[snake.size() - 1] == '~' && status == 0) { cout << "B" << endl; } continue; } else if (snake[1] == '\'') { int head = 0, tale = 0, join; for (int j = 2; j < snake.size(); j++) { if (snake[j] == '#') { join = j; break; } head++; } for (int j = join + 1; j < snake.size() - 1; j++) { if (snake[j] != '=') { cout << "NA" << endl; continue; } tale++; } if (head == tale && snake[snake.size() - 1] == '~') { cout << "A" << endl; continue; } } cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using namespace placeholders; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<vector<int> >; using VS = vector<string>; using ISS = istringstream; using OSS = ostringstream; using PII = pair<int, int>; using VPII = vector<pair<int, int> >; template <typename T = int> using VT = vector<T>; template <typename T = int> using VVT = vector<vector<T> >; template <typename T = int> using LIM = numeric_limits<T>; template <typename T> inline istream &operator>>(istream &s, vector<T> &v) { for (T &t : v) { s >> t; } return s; } template <typename T> inline ostream &operator<<(ostream &s, const vector<T> &v) { for (int i = 0; i < int(v.size()); ++i) { s << (" " + !i) << v[i]; } return s; } template <typename T> struct getv_fmt; template <> struct getv_fmt<int> { static constexpr const char *fmt = "%d"; }; template <> struct getv_fmt<long long> { static constexpr const char *fmt = "%lld"; }; template <typename T> void getv(std::vector<T> &v) { for_each(begin(v), end(v), [](T &a) { scanf(getv_fmt<T>::fmt, &a); }); }; template <typename T> inline T fromString(const string &s) { T res; istringstream iss(s); iss >> res; return res; } template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); } template <typename T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } bool is_a(const string &S) { const int Ls = ((int)(S).size()); if (S.find(">'") != 0 || S.find("~") != Ls - 1) { return false; } string T = S.substr(2, Ls - 3); const int Lt = ((int)(T).size()); if (Lt % 2 == 0 || Lt <= 3 || T[Lt / 2] != '#') { return false; } T[Lt / 2] = '='; return all_of(begin(T), end(T), bind(equal_to<char>(), _1, '=')); } bool is_b(const string &S) { const int Ls = ((int)(S).size()); if (S.find(">^") != 0 || S.find("~~") != Ls - 2) { return false; } const string T = S.substr(2, Ls - 4); const int Lt = ((int)(T).size()); if (Lt == 0 || Lt % 2) { return false; } for (int i = 0; i < Lt; i += 2) { if (T[i] != 'Q' || T[i + 1] != '=') { return false; } } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12) << fixed; int N; cin >> N; for (int REP_COUNTER_135 = (int)(0); REP_COUNTER_135 < (int)(N); ++REP_COUNTER_135) { string S; cin >> S; string res = "NA"; if (is_a(S)) { res = "A"; } if (is_b(S)) { res = "B"; } cout << res << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; int check(string S) { if (S[0] != '>' || S[S.size() - 1] != '~') { return 0; } if (S[1] == '\'') { if (S.substr(2, S.size() - 3).find_first_not_of("#=", 0) != string::npos) return 0; string tmpB = S.substr(2, S.find('#') - 2); string tmpA = S.substr(S.find('#') + 1, S.size() - (S.find('#') + 2)); return tmpB.size() == tmpA.size() ? 1 : 0; } if (S[1] == '^' && S[S.size() - 2] == '~') { if (S.substr(2, S.size() - 4).find_first_not_of("Q=", 0) != string::npos) return 0; for (int i = 2; i < S.size() - 2; i += 2) { if (S[i] != 'Q' && S[i + 1] != '=') return 0; } return 2; } } int main() { int N; cin >> N; vector<string> res{"NA", "A", "B"}; string S; while (cin >> S) { cout << res[check(S)] << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const double EPS = 1e-12; const double PI = acos(-1.0); int main() { int n; cin >> n; for (int i = (0); i <= ((n)-1); ++i) { string s; cin >> s; string h = s.substr(0, 2); if (h == ">'") { s += "!"; if (s.find('#') != string::npos) { int pos = s.find('#'); int size = pos - 2; for (int i = (0); i <= ((pos - 2) - 1); ++i) { if (s[i + 2] == s[i + pos + 1] && s[i + 2] == '=') { } else { cout << "NA" << endl; goto next; } } if (s[pos + size + 1] == '~' && s[pos + size + 1] == '!') { cout << "A" << endl; goto next; } else { cout << "NA" << endl; goto next; } } else { cout << "NA" << endl; goto next; } } else if (h == ">^") { s += "!!"; int b = 2; bool flag = false; while (s.substr(b, 2) == "Q=") { b += 2; flag = true; } if (s.substr(b, 2) == "~~" && s.substr(b + 2, 2) == "!!" && flag) { cout << "B" << endl; goto next; } else { cout << "NA" << endl; goto next; } } else { cout << "NA" << endl; goto next; } next:; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char A, B; char snake[256]; int n; int cnt; int i, j, len1, len2; scanf("%d", &n); for (i = 0; i < n; i++) { A = B = 0; scanf("%s", snake); if (snake[0] == '>' && snake[1] == '\'') { j = 2; len1 = 0; while (snake[j] != '#' && snake[j] != '\0') { len1++; j++; } if (snake[j] == '#') { j++; len2 = 0; while (snake[j] != '~' && snake[j] != '\0') { len2++; j++; } if (len1 == len2 && len1 > 0 && snake[j + 1] == '\0') { A = 1; } } } else if (snake[0] == '>' && snake[1] == '^') { j = 2; len1 = 0; len2 = 1; while (snake[j] != '~') { if (j % 2 == 0 && snake[j] != 'Q') { len2 = 0; break; } if (j % 2 == 1 && snake[j] != '=') { len2 = 0; break; } j++; len1++; } if (len2 && snake[j + 1] == '~' && len1 > 0 && len1 % 2 == 0 && snake[j + 2] == '\0') { B = 1; } } if (A) { printf("A\n"); } else if (B) { printf("B\n"); } else { printf("NA\n"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { char w[201]; int a, i, j, k; scanf("%d", &a); for (j = 0; j < a; j++) { scanf("%s", w); if (w[0] != '>') { printf("NA\n"); continue; } if (w[1] == '\'') { for (i = 2; w[i] != '#'; i++) { if (w[i] != '=') { printf("NA\n"); continue; } } int t = i - 1; for (k = t; t > 0; t--) { if (w[i++] != '=') { printf("NA\n"); continue; } } if (w[i++] != '~') { printf("NA\n"); continue; } if (w[i] != '\0') { printf("NA\n"); continue; } printf("A\n"); } if (w[1] == '^') { for (i = 2; w[i] == '~'; i += 2) { if (w[i] != 'Q') { printf("NA\n"); continue; } if (w[i + 1] != '=') { printf("NA\n"); continue; } } if (w[i] != '~') { printf("NA\n"); continue; } if (w[i + 1] != '~') { printf("NA\n"); continue; } if (w[i + 2] != '\0') { printf("NA\n"); continue; } printf("B\n"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; while (n--) { string snake; cin >> snake; if (snake.size() < 4) { cout << "NA" << endl; } else if (snake[0] == '>' && snake[1] == '\'' && snake[snake.size() - 1] == '~') { bool first = true; int count1 = 0; int count2 = 0; for (int i = 2; i < snake.size() - 1; ++i) { if (snake[i] == '=') { if (first) { ++count1; } else { ++count2; } } else if (snake[i] == '#') { first = false; } } if (count1 == count2 && count1 >= 1) { cout << "A" << endl; } else { cout << "NA" << endl; } } else if (snake[0] == '>' && snake[1] == '^' && snake[snake.size() - 2] == '~' && snake[snake.size() - 1] == '~') { bool flag = true; int count = 0; for (int i = 2; i < snake.size() - 2; i += 2) { if (snake[i] != 'Q' || snake[i + 1] != '=') { flag = false; break; } else { ++count; } } if (flag && count) { cout << "B" << endl; } else { cout << "NA" << endl; } } else { cout << "NA" << endl; } } } int main() { solve(); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, j, fa, fb, acount, acount2, i; string data; cin >> n; getline(cin, data); for (j = 0; j < n; j++) { fa = 0; fb = 0; acount = acount2 = 0; getline(cin, data); if (data[0] == '>' && data[1] == '\'') { fa = 1; i = 2; while (data[i] == '=') { acount++; i++; } if (data[i] != '#') fa = 0; i++; while (data[i] == '=') { acount2++; i++; } if (acount != acount2) fa = 0; if (data[data.length() - 1] != '~') { fa = 0; } } if (data[0] == '>' && data[1] == '^') { fb = 1; for (i = 2; i < data.length() - 3; i = i + 2) { if (data[i] != 'Q' || data[i + 1] != '=') fb = 0; } if (data[data.length() - 1] != '~' || data[data.length() - 2] != '~') fb = 0; } if (fa == 1) cout << "A" << endl; else if (fb == 1) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; for (int b = 0; b < a; b++) { string s = "NA"; string c; cin >> c; if (c[0] == '>' && c[c.length() - 1] == '~') { if (c[1] == '\'' && (c.length() & 1) == 0) { bool A = true; for (int i = 3; i < c.length() - 2; i++) { if (i == c.length() / 2) { if (c[i] != '#') A = false; } else { if (c[i] != '=') A = false; } } if (A) s = "A"; } else if (c[1] == '^' && c[c.length() - 2] == '~') { bool B = true; for (int d = 2; d < c.length() - 2; d += 2) { if (c[d] != 'Q' || c[d + 1] != '=') B = true; } if (B) s = "B"; } } cout << s << endl; } }