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
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s; cin >> s; int f1 = 0, f2 = 0, k = -1; bool f; for (int i = 0; i < s.size(); i++) if (s[i] == '>') { k = i; break; } if (k == -1 || s.size() < 5) { printf("NA\n"); continue; } if (s[k + 1] == '^') { f = false; for (int i = k; i + 1 < s.size(); i++) if (s[i] == 'Q' && s[i + 1] == '=') f = true; if (f && s[s.size() - 1] == '~' && s[s.size() - 2] == '~') { printf("B\n"); continue; } } int cnt = 0; for (int i = k; i < s.size(); i++) { if (s[i] == '=') { while (s[i] == '=' && i < s.size()) { cnt++; i++; } k = i; break; } } f = false; for (int i = k; i < s.size(); i++) { if (s[i] == '#') { k = i; f = true; } } if (f) { for (int i = k; i < s.size(); i++) { if (s[i] == '=') { while (s[i] == '=' && i < s.size()) { cnt--; i++; } break; } } if (cnt == 0 && s[s.size() - 1] == '~') { printf("A\n"); continue; } } printf("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
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) { if (s[i] == '=') if (shp == 0) ++bef_eq; else ++aft_eq; else if (s[i] == '#') { shp++; } else if (s[i] == '~') { pos_tld = i; break; } else { shp = 2; break; } } if (bef_eq && aft_eq && pos_tld && bef_eq == aft_eq && shp == 1 && pos_tld == s.length() - 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; 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 || snake[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=") flag = false; s = ""; } } if (flag && snake[snake.length() - 1] == '~') 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
UNKNOWN
require 'pp' $stdin.gets.chomp.to_i.times do line = $stdin.gets.chomp ans = false if (m = line.match(/>'(=+)#(=+)~$/)) then if m[1].length == m[2].length then puts 'A' ans = true end end if (m = line.match(/>\^(.*?)~~$/)) then if ((m[1].unpack("a2"*(m[1].length/2))).all? {|x| x == "Q="}) then puts 'B' ans = true end end puts 'NA' if !ans 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
#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] == '~') { 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; void a() { cout << "NA" << endl; return; } int main() { int n; vector<string> sample; string aaa; cin >> n; for (int i = 0; i < n; i++) { cin >> aaa; sample.push_back(aaa); } for (int i = 0; i < n; i++) { string snake = sample[i]; string::size_type aruyon; if ((aruyon = snake.find(">'")) == 0) { int equal = 0; int j; for (j = 2; snake.at(j) == '='; j++) equal++; if (equal > 0) if (snake.at(j) == '#') { j++; for (; snake.at(j) == '='; j++) equal--; if (equal == 0) { if (snake.at(j) == '~' && j + 1 == snake.size()) cout << 'A' << endl; else a(); } else a(); } else a(); else a(); } else if ((aruyon = snake.find(">^")) == 0) { int j; bool dou = false; if ((aruyon = snake.find("~~")) == snake.size() - 2) { if (aruyon % 2 == 0) { for (j = 2; j < aruyon; j++) { dou = false; if (snake.at(j) == 'Q') j++; else { j = 0; break; } if (snake.at(j) != '=') { a(); break; } else dou == true; } if (dou) cout << 'B' << endl; else a(); } else a(); } else a(); } else a(); } 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 str; string kp; string set; int flag = 0; int count = 0; int i = 0; cin >> str; for (i = 0; i < 2; i++) kp += str[i]++; if (kp == ">'") { while (str[i] != '#') { if (str[i] == '=') count++; else flag = -1; if (flag == -1) break; i++; } i++; while (str[i] != '~') { if (str[i] == '=') count--; else flag = -1; if (flag == -1) break; i++; } if (flag != -1 && !count) flag = 1; } else if (kp == ">^") { while (i < str.length() - 2) { count = 2; while (count--) { set += str[i]; i++; } if (set == "Q=") flag = 2; else flag = -1; set.erase(set.begin(), set.end()); if (flag == -1) break; } for (i = str.length() - 2; i < str.length(); i++) set += str[i]; if (set == "~~") flag = 2; else flag = -1; } if (flag == 1) cout << "A" << endl; else if (flag == 2) 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 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
UNKNOWN
#include <bits/stdc++.h> int main(void) { int quantity, i, j, idx; char snake[200] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { int count = 0; 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] == '~')) { if (snake[idx + 2] == '\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(int argc, const char* argv[]) { int num; int i, j, k, l; scanf("%d", &num); for (l = 0; l < num + 1; l++) { char snake[200]; int bodyacnt = 0; int bodybcnt = 0; int midcnt = 0; int endacnt = 0; int endbcnt = 0; int nacnt = 0; for (i = 0; i < 200; i++) { scanf("%c", &snake[i]); if (snake[i] == '\n') { break; } } if (snake[0] == '>') { if (snake[1] == '\'') { for (j = 2; j < i; j++) { if (snake[j] == '=') { bodyacnt++; } else if (snake[j] == '#') { break; } } for (k = j; k < i; k++) { if (snake[k] == '=') { midcnt++; } else if (snake[k] == '~') { endacnt++; if (endacnt == 2) { nacnt++; } } else nacnt++; } } else if (snake[1] == '^') { for (j = 2; j < i / 2; j += 2) { if (snake[j] == 'Q' && snake[j + 1] == '=') { bodybcnt++; } else nacnt++; } if (snake[i - 2] == '~' && snake[i - 1] == '~' && snake[i - 3] != '~') { endbcnt++; } } else nacnt++; } if (bodybcnt > 0 && endbcnt == 1 && nacnt == 0) { printf("B\n"); } else if (bodyacnt == midcnt && endacnt == 1 && nacnt == 0 && bodyacnt > 0) { printf("A\n"); } else if (l != 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; template <class T> ostream& operator<<(ostream& os, vector<T> v) { for (typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) { os << *it_i << ", "; } return os; } bool checkA(string s) { set<string> S; for (int i = 1; i <= 100; ++i) { S.insert(">'" + string(i, '=') + "#" + string(i, '=') + "~"); } return S.count(s) > 0; } bool checkB(string s) { set<string> S; for (int i = 1; i <= 100; ++i) { vector<string> con(i, "Q="); S.insert(">^" + accumulate(con.begin(), con.end(), string()) + "~~"); } return S.count(s) > 0; } string solve(string s) { if (checkA(s)) return "A"; if (checkB(s)) return "B"; 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 Tc; string s; while (cin >> Tc) { while (Tc--) { cin >> s; int const N = s.size(); bool NA = 0; bool isA; if (s[1] == '\'') { if (s.substr(2, (N - 3) / 2) + "~" != s.substr(3 + (N - 3) / 2)) NA = 1; if (s[(N - 3) / 2 + 2] != '#') NA = 1; isA = 1; } else if (s[1] == '^') { if (!(s[2] == 'Q' && s[3] == '=')) NA = 1; int cnt; for (cnt = 2; cnt < N - 2; cnt += 2) { if (!(s[cnt] == 'Q' && s[cnt + 1] == '=')) NA = 1; } if (!(s[cnt] == '~' && s[cnt + 1] == '~')) NA = 1; isA = 0; } else { NA = 1; } if (NA) cout << "NA" << endl; else if (isA) cout << "A" << endl; else cout << "B" << 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 += ">"; else if (i == 1) A += "'"; else if (i == (size - 1)) A += "~"; else if (i == ((size - 3) / 2 + 2)) A += "#"; else A += "="; } for (int i = 0; i < size; i++) { if (i == 0) B += ">"; else if (i == 1) B += "^"; else if (i >= size - 2) B += "~"; else if (i % 2 == 0) B += "Q"; else B += "="; } if (size % 2 == 0) { if (s == A) cout << "A" << endl; else if (s == B) 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
python3
def checkA(s): if s[:2] == ">'" and s[-1] == "~": body = s[2:-1] if len(body) >= 3 and body.count("#") == 1 and body.index("#") == len(body) // 2: return True else: return False else: return False def checkB(s): if s[:2] == ">^" and s[-2:] == "~~": body = s[2:-2] if len(body) > 0 and len(body) % 2 == 0: for i in range(0, len(body), 2): if body[i:i + 2] != "Q=": return False else: return True else: return False else: return False n = int(input()) for _ in range(n): s = input() if len(s) <= 5: print("NA") else: if checkA(s): print("A") elif checkB(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
cpp
#include <bits/stdc++.h> using namespace std; void a() { cout << "NA" << endl; return; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string snake; cin >> snake; string::size_type aruyon; if ((aruyon = snake.find(">'")) == 0) { int equal = 0; int j; for (j = 2; snake.at(j) == '='; j++) equal++; if (equal > 0) if (snake.at(j) == '#') { j++; for (; snake.at(j) == '='; j++) equal--; if (equal == 0) { if (snake.at(j) == '~' && j + 1 == snake.size()) cout << 'A' << endl; else a(); } else a(); } else a(); else a(); } else if ((aruyon = snake.find(">^")) == 0) { int j; bool dou = false; if ((aruyon = snake.find("~~")) == snake.size() - 2) { if (aruyon % 2 == 0) { for (j = 2; j < aruyon; j++) { if (snake.at(j) == 'Q') j++; else { j = 0; break; } if (snake.at(j) != '=') { a(); break; } else dou == true; } if (j == aruyon && dou == true) cout << 'B' << endl; else a(); } else a(); } else a(); } else a(); } 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 asnake(string s) { int n = s.size(); string com = ">\'"; for (int i = 0; i < (n - 4) / 2; i++) com += '='; com += '#'; for (int i = 0; i < (n - 4) / 2; i++) com += '='; com += '~'; if (s == com) return true; else return false; } bool bsnake(string s) { int n = s.size(); string com = ">^"; for (int i = 0; i < (n - 4) / 2; i++) com += "Q="; com += "~~"; if (s == com) return true; else return false; } int main() { int n; cin >> n; for (int p = 0; p < n; p++) { string s; cin >> s; if (asnake(s)) cout << "A" << endl; else if (bsnake(s)) 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, 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; goto end; } } for (int i = j + 1; i < 1000; i++) { if (S[i] == '=') { runcnt--; } else if (runcnt == 0 && S[i] == '~' && K == 1) { cout << "A" << endl; goto end; } else { cout << "NA" << endl; goto end; } } } 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; goto end; } else { cout << "NA" << endl; goto end; } } } else cout << "NA" << endl; end:; } 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; char snake[200] = {0}; char *str; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { int count = 0; 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] == '^') { 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') 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 ; #define pb(n) push_back(n) #define fi first #define se second #define all(r) (r).begin(),(r).end() #define gsort(st,en) sort((st),(en),greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout<<#x<<": "<<x<<endl #define fcout(n) cout<<fixed<<setprecision((n)) #define scout(n) cout<<setw(n) #define vary(type,name,size,init) vector< type> name(size,init) #define rep(i,n) for(int i = 0; i < (int)(n);++i) #define REP(i,a,b) for(int i = (a);i < (int)(b);++i) #define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it) #define repa(n,array) for(auto &n :(array)) using ll = long long; using vi = vector<int>; using vl = vector<ll>; using dict = map<string,int>; using pii = pair<int,int> ; constexpr int imax = ((1<<30)-1)*2+1 ; constexpr int inf = 100000000; constexpr double PI = acos(-1.0) ; double eps = 1e-10 ; const int dy[] = {-1,0,1,0}; const int dx[] = {0,-1,0,1}; inline bool value(int x,int y,int w,int h){ return (x >= 0 && x < w && y >= 0 && y < h); } template<typename T> void Unique(vector<T> &v){ sort(all(v)); v.erase(unique(all(v)),v.end()); } template<typename T> T ston(string& str, T n){ istringstream sin(str) ; T num ; sin >> num ; return num ; } void Ans(bool f){ if(f) cout << "YES"<<endl; else cout << "NO"<<endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; string s; cin >> n; rep(i,n){ cin >> s; if(s[0] != '>'|| s.size() < 6 || s.size()%2 == 1|| (s[1] != '\'' && s[1] != '^') ){ cout << "NA"<<endl; } else if(s[1] == '\''){ int cnt = find(all(s),'#') - s.begin()-2; if(2*cnt+3 == s.size()-1 && s[2*cnt+3] == '~' ){ cout << "A"<<endl; } else{ cout <<"NA"<<endl; } } else{ bool f = false; for(int i = 2; i < s.size(); i+=2){ if(!(s[i] == 'Q' && s[i+1] == '=')){ if(s[i] == '~' && s[i+1] == '~' && i == s.size()-2){ cout << "B"<<endl; f = true; } else{ break; } } } if(!f) 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 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] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); 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); } } 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) { 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] == '~') { 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; template <class T> ostream& operator<<(ostream& os, vector<T> v) { for (typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) { os << *it_i << ", "; } return os; } bool checkA(string s, int k, bool f0, bool f1, bool f2) { int n = s.size(); if (k == n - 1) { if (s[k] != '~') return false; return f0 && f1 && f2; } if (k == 0) { if (n < 2) return false; if (s[k] != '>' || s[k + 1] != '\'') return false; return checkA(s, k + 2, f0, f1, f2); } if (!f0) { if (s[k] != '=') return false; return checkA(s, k + 1, true, f1, f2); } if (!f1) { if (s[k] == '#') { return checkA(s, k + 1, f0, true, f2); } else if (s[k] == '=') { return checkA(s, k + 1, f0, f1, f2); } return false; } if (!f2) { if (s[k] != '=') return false; return checkA(s, k + 1, f0, f1, true); } return s[k] == '=' && checkA(s, k + 1, f0, f1, f2); } bool checkB(string s, int k) { int n = s.size(); if (k == 0) { if (n < 2) return false; if (s[k] != '>' || s[k + 1] != '^') return false; return checkB(s, k + 2); } if (s[k] == 'Q') { if (k + 1 >= n) return false; if (s[k + 1] != '=') return false; return checkB(s, k + 2); } if (k + 2 == n && s[k] == '~') { return s[k + 1] == '~'; } return false; } string solve(string s) { if (checkA(s, 0, false, false, false)) return "A"; if (checkB(s, 0)) return "B"; 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<iostream> #include<string> 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
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;} else{return 2;} 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;count=1;} else if(state==TAIL_B){++count;} else{return 2;} } } if(state==TAIL_B&&count!=2)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
cpp
#include <bits/stdc++.h> using namespace std; bool check(string s, int n) { if (s.size() <= n) return true; return false; } void solve() { string s; cin >> s; int n = 0; if (s[n] == '>') { n++; if (check(s, n)) ; else if (s[n] == '\'') { n++; int cnt = 0; while (s[n] == '=' && !check(s, n)) { cnt++; n++; } if (s[n] == '#') { n++; if (check(s, n)) goto exit; while (s[n] == '=' && !check(s, n)) { cnt--; n++; } if (cnt == 0) { if (s[n] == '~') { n++; if (n == s.size()) { cout << "A\n"; return; } } } } } else if (s[n] == '^') { n++; if (check(s, n)) goto exit; while (true) { if (check(s, n + 1)) goto exit; else { if (s[n] == 'Q' && s[n + 1] == '=') n += 2; else if (s[n] == '~' && s[n + 1] == '~') { cout << "B\n"; return; } else goto exit; } } n++; if (check(s, n)) goto exit; if (s[n] == '~') { n++; if (check(s, n)) goto exit; if (s[n] == '~') { n++; if (n == s.size()) { cout << "B\n"; return; } } } } } exit:; cout << "NA\n"; return; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) solve(); }
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; if (s[0] == '>' && s[1] == '\'' && s[2] == '=') { int i = 2; int cnt = 0; while (s[i] == '=') { i++; cnt++; } if (s[i] == '#' && i < s.size()) { i++; while (s[i] == '=') { if (i == s.size() - 1) break; i++; cnt--; } } if (cnt == 0 && s[i] == '~') cout << "A" << endl; else cout << "NA" << endl; } else if (s[0] == '>' && s[1] == '^' && s[2] == 'Q') { int i = 2; int cnt = 0; bool end = false; while (i + 1 < s.size()) { if (s[i] == 'Q' && s[i + 1] == '=') { i += 2; } else if (s[i] == '~' && s[i + 1] == '~') { end = true; cout << "B" << endl; i += 2; } else { break; } } if (!end) cout << "NA" << endl; } else { cout << i << " 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
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; for (int i = 0; i < t[0].Length; i++) { if (t[0][i] != '=') return NA; if (t[1][i] != '=') 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; int main() { int i, n; string s; cin >> n; while (n--) { cin >> s; if (s[0] == '>' && s[1] == '\'' && !s.size() % 2) { 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] != '=') break; } } else if (s[0] == '>' && s[1] == '^') { 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
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; while (N--) { string str; cin >> str; bool Aflag, Bflag; Aflag = Bflag = true; if (str.substr(0, 2) == ">'") Bflag = false; else if (str.substr(0, 2) == ">^") Aflag = false; else Aflag = Bflag = false; if (Aflag) { int p = str.find("#"); if (p == str.npos) { Aflag = false; break; } int cnt = 0; for (int i = 2; i < p; i++) { if (str[i] == '=' && str[p + i - 1] == '=') cnt++; else { Aflag = false; break; } } if (cnt == 0) Aflag = false; if (str[cnt * 2 + 3] == '~' && str.length() == cnt * 2 + 4) ; else Aflag = false; } if (Bflag) { int p = 2; while (str.substr(p, 2) == "Q=") p += 2; if (p == 2) { Bflag = false; } if (str.substr(p, 2) == "~~" && str.length() == p + 2) ; else Bflag = false; } if (Aflag) cout << "A" << endl; else if (Bflag) 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(void) { string s; int n; cin >> n; while (n--) { cin >> s; 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] == '~') cout << "A" << endl; else cout << "NA" << endl; } else if (s[1] == '^') { if (s[2] == 'Q' && s[3] == '=' && s[s.size() - 1] == '~' && s[s.size() - 2] == '~') { 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
UNKNOWN
#include <bits/stdc++.h> int main(void) { char snake[200]; int n, cnt1 = 0, cnt2 = 0, i, j; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", snake); j = 0; 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
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 var isA = true val s2 = s.drop(2).dropRight(1) if(s2(s2.length/2) != '#') isA = false else { val s3 = s2.split("#") if(s3(0)!=s3(1) || s3(0).exists(_!='=')) isA = false } 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" } } } 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
cpp
#include <bits/stdc++.h> using namespace std; string afunc(string str) { string res = "NA"; for (int i = 0, j = str.size() - 1; i <= j; i++, j--) { if (i == j) { if (str[i] == '#') { res = "A"; } } else if (str[i] != str[j]) { break; } } return res; } string bfunc(string str) { string res = "B"; for (int i = 0; i < str.size(); i += 2) { if (str[i] != 'Q' || str[i + 1] != '=') { res = "NA"; break; } } return res; } int main() { int n; string str, res; while (cin >> n && n) { while (n--) { cin >> str; res = "NA"; if ('>' == str[0]) { str.erase(str.begin()); int l = str.size(); if (str[0] == '\'' && str[l - 1] == '~') { str.erase(str.end() - 1); str.erase(str.begin()); if (str.size() % 2 == 1) { res = afunc(str); } } else if (str[0] == '^' && str[l - 1] == str[l - 2] && str[l - 1] == '~') { str.erase(str.end() - 1); str.erase(str.end() - 1); str.erase(str.begin()); if (str.size() % 2 == 0) { res = bfunc(str); } } } 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; 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; 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 && i == s.length() - 2) break; else 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
java
import java.util.*; import java.lang.*; import java.io.*; class Main{ private static boolean snake_A(String snake) { if(snake.charAt(snake.length()-1) != '~') return false; if(!snake.substring(0,2).equals(">'")) return false; if(snake.indexOf("#") == -1) return false; if(snake.indexOf("#") > snake.indexOf("~")) return false; if(snake.indexOf("#")-snake.indexOf("'") != snake.indexOf("~")-snake.indexOf("#")) return false; int left,right; left = right = 0; for(int i=2;i<snake.indexOf("#");i++) { if(snake.charAt(i) == '=') left++; else { return false; } } for(int i=snake.indexOf("#")+1;i<snake.indexOf("~");i++) { if(snake.charAt(i) == '=') right++; else return false; } if(left != right) return false; return true; } private static boolean snake_B(String snake) { if(!snake.substring(snake.length()-2,snake.length()).equals("~~")) return false; if(!snake.substring(0,2).equals(">^")) return false; int cnt = 0; for(int i=2;i<snake.indexOf("~");i+=2) { if(snake.substring(i,i+2).equals("Q=")) cnt++; else return false; } if(cnt < 1) return false; return true; } public static void main(String args[])throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n; n = Integer.parseInt(in.readLine()); while(n-- > 0) { String snake = in.readLine(); if(snake_A(snake)) { System.out.println("A"); } else if(snake_B(snake)) { 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
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) { 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++) { 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; 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
python2
for i in [0]*input(): s=raw_input() n=(len(s)-4)/2 if s==">'"+"="*n+"#"+"="*n+"~": print "A" elif s==">^"+"Q="*n+"~~": 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
UNKNOWN
def is_a?(s) s =~ />(?:[^=])*(=+)#(=+)~/ unless $1 == nil || $2 == nil return s && $1.size == $2.size end false end def is_b?(s) s =~ />\^(Q=)+~~/ end n = gets.chomp.to_i n.times do s = gets.chomp if is_a?(s) puts :A elsif is_b?(s) 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; string solve(string s) { if (s[0] != '>') return "NA"; if (s.size() % 2 != 0) return "NA"; int i = 0, j; if (s[1] == '\'') { for (i = 2; i < s.size(); ++i) { if (s[i] == '#') break; else if (s[i] != '=') return "NA"; } int l = i - 2; ++i; for ((j) = 0; (j) < (l); ++(j)) if (s[i + j] != '=') return "NA"; if (s[s.size() - 1] != '~') return "NA"; if (i + l + 1 != s.size()) return "NA"; return "A"; } else if (s[1] == '^') { for (i = 2; i < s.size(); i += 2) { if (s.substr(i, 2) != "Q=") { if (i + 2 == s.size() && s.substr(i, 2) == "~~") break; else return "NA"; } } return "B"; } return "NA"; } int main(void) { int i, j, n; string s; scanf("%d", &n); for (; n--;) { 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
UNKNOWN
#include <bits/stdc++.h> int main(void) { int n, i, c1, c2, f; char s[201]; scanf("%d", &n); while (n--) { scanf("%s", s); f = 1; if (s[0] != '>') { puts("NA"); continue; } if (s[1] == '\'') { c1 = c2 = 0; for (i = 2; s[i] != '#'; i++) { if (s[i] != '=') { f = 0; break; } c1++; } for (i++; s[i] != '~'; i++) { if (s[i] != '=') { f = 0; break; } c2++; } if (!(c1 == c2 && s[i + 1] == 0)) { f = 0; } if (f) { puts("A"); } else { puts("NA"); } } else if (s[1] == '^') { for (i = 2; s[i] != '~'; i = i + 2) { if (!(s[i] == 'Q' && s[i + 1] == '=')) { f = 0; break; } } if (!(s[i] == '~' && s[i + 1] == '~' && s[i + 2] == 0)) { f = 0; } if (f) { 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
java
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args){ try{ new Main(); }catch(IOException e){ e.printStackTrace(); } } public Main() throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); List<String> Ans = new ArrayList<String>(); String line = in.readLine(); int size = Integer.parseInt(line); for(int n=0; n<size; n++){ line = in.readLine(); int type = 0; String c = line.substring(0, 2); if(c.equals(">'")){ int count = 0; int sharp = 0; for(int i=2; i<line.length(); i++){ c = line.substring(i, i+1); if(c.equals("=")){ count++; } else if(c.equals("#")){ if(count > 0){ count = -count; sharp = 1; } else{ type = -1; break; } } else if(c.equals("~")){ if(i != line.length()-1){ type = -1; break; } if(count==0 && sharp==1){ type = 1; break; } else{ type = -1; break; } } } } else if(c.equals(">^")){ int count = 0; for(int i=2; i<line.length(); i++){ c = line.substring(i, i+1); if(count%2==0 && count>=2 && c.equals("~")){ if(i==line.length()-1){ type = -1; break; } c = line.substring(i+1, i+2); if(c.equals("~")){ type = 2; break; } else{ type = -1; break; } } if(i%2==0){ if(!c.equals("Q")){ type = -1; break; } count++; } if(i%2==1){ if(!c.equals("=")){ type = -1; break; } count++; } } } else{ type = -1; } switch(type){ case 1: Ans.add("A"); break; case 2: Ans.add("B"); break; default: Ans.add("NA"); } } for(int n=0; n<Ans.size(); n++){ System.out.println(Ans.get(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
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 < 49; i++) { t = ">\'" + vbString(i, "=") + "#" + vbString(i, "=") + "~"; if (t == s) return "A"; } for (int i = 1; i < 49; i++) { t = ">^" + vbString(i, "Q=") + "~~"; if (t == s) return "B"; } return "NA"; } int main() { string s; int n, i = 0; cin >> n; for (i = 0; i < n; i++) { cin >> s; cout << checksnake(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() { const string species[] = {"A", "B", "NA"}; string str = ""; int n; while (getline(cin, str)) { stringstream ssn(str); ssn >> n; if (n == 0) { break; } int i, j; for (i = 0; i < n; ++i) { string res = species[2]; getline(cin, str); int len = str.length(); if (str[0] == '>') { if (str[1] == '\'') { res = species[0]; } else if (str[1] == '^') { res = species[1]; } else { res = species[2]; } } if (res == species[0] || res == species[1]) { if (res == species[0]) { int prev = 0; int after = 0; int mid = 0; bool flag = false; for (j = 2; j < len - 1; ++j) { if (str[j] == '=') { if (!flag) { ++prev; } else { ++after; } continue; } else if (str[j] == '#') { flag = true; ++mid; continue; } else { break; } } if (j == len - 1) { if (str[j] == '~' && flag && mid == 1 && prev != 0 && after != 0 && prev == after) { res = species[0]; } else { res = species[2]; } } else { res = species[2]; } } else { for (j = 2; j < len - 2; j += 2) { if (str[j] == 'Q' && str[j + 1] == '=') { continue; } else { break; } } if (j == len - 2 && str[j] == '~' && str[j + 1] == '~') { res = species[1]; } else { res = species[2]; } } } 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 main() { int cnt, cnt2; int i = 0; char snake[201]; scanf("%d", &cnt); while (i != cnt) { scanf("%s", snake); if (strlen(snake) < 2 || snake[0] != '>') { printf("NA\n"); } else if (snake[1] == '\'') { cnt2 = 0; i = 2; while (snake[i] == '=') { i++; cnt2++; } if (snake[i] != '#' || cnt2 <= 0) { printf("NA\n"); } else { i++; while (snake[i] == '=') { i++; cnt2--; } if (cnt2 != 0) { printf("NA\n"); } else if (snake[i] != '~' || snake[i + 1] != 0) { printf("NA\n"); } else { printf("A\n"); } } } else if (snake[1] == '^') { i = 2; while (snake[i] == 'Q' && snake[i + 1] == '=') { i += 2; } if (i == 2) { printf("NA\n"); } else if (snake[i] != '~' || snake[i + 1] != '~' || snake[i + 2] != 0) { printf("NA\n"); } else { printf("B\n"); } } else { printf("NA\n"); } cnt++; } 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(); 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; bool isa(string s) { if (s.substr(0, 2) != ">'") return false; int x = 2; int c = 0; while (s[x + c] == '=') { c++; } if (s[x + c] != '#') return false; x = x + c + 1; for (int i = 0; i < c; i++) { if (s[x + i] != '=') return false; } x += c; if (s[x] != '~') return false; return true; } bool isb(string s) { if (s[0] != '>') return false; if (s[1] != '^') return false; int x = 2; int c = 0; while (s[x + c] == 'Q' && s[x + 1 + c] == '=') { c += 2; } x += c; if (s[x] != '~') return false; if (s[x + 1] != '~') return false; return true; } int main() { string s = ""; int n; cin >> n; for (int i = 0; i < (n); i++) { cin >> s; if (isa(s)) cout << "A" << endl; else if (isb(s)) 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
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]=='~'&&ch[ch.length-3]!='~') { int co=2; while(ch[co]!='~') { if(ch[co]=='Q'&&ch[co+1]=='=') flag = true; else { flag = false; break; } co+=2; } } 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; int main(void) { int n, len, flag = 0, flag2 = 0, cnt1 = 0, cnt2 = 0; char snake[10000][200]; cin >> n; for (int i = 0; i < n; i++) { scanf("%s", snake[i]); len = strlen(snake[i]); if (snake[i][0] == '>' && snake[i][1] == '\'') { for (int j = 2; j < len - 1; j++) { if (snake[i][j] == '=' && flag == 0) { cnt1++; flag2 = 1; } if (snake[i][j] == '=' && flag == 1) { cnt2++; flag2 = 1; } if (snake[i][j] == '#') flag = 1; } if (snake[i][len - 1] == '~' && cnt1 == cnt2 && flag2 == 1) cout << 'A' << endl; else cout << "NA" << endl; flag = 0; cnt1 = 0; cnt2 = 0; } else if (snake[i][0] == '>' && snake[i][1] == '^') { for (int j = 2; j < len - 2; j++) { if (snake[i][j] == 'Q' && snake[i][j + 1] == '=') flag = 1; } if (snake[i][len - 2] == '~' && snake[i][len - 1] == '~' && flag == 1) 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; bool is_a(string& s) { if (s[0] != '>' || s[1] != '\'') return false; int eq_count = 0; int i; for (i = 2; s[i] == '='; i++) { eq_count++; } if (s[i++] != '#') return false; for (; s[i] == '='; i++) { eq_count--; } if (eq_count == 0 && s[i] == '~') return true; return false; } bool is_b(string& s) { if (s[0] != '>' || s[1] != '^') return false; int len = s.size(); if (len % 2 == 1) return false; int i; for (i = 2; i < len - 2; i += 2) { if (s[i] != 'Q' || s[i + 1] != '=') return false; } if (s[i] != '~' || s[i + 1] != '~') return false; return true; } int main() { int n; cin >> n; for (int i = 0; i < (n); i++) { string s; cin >> s; if (is_a(s)) { cout << "A" << endl; continue; } else if (is_b(s)) { cout << "B" << endl; continue; } 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; int sz = s.size(); if (s[0] != '>' || sz < 6) { cout << "NA" << endl; continue; } if (s[1] == '\'') { int t = sz - 3; if (t % 2 == 0) { cout << "NA" << endl; continue; } for (int j = 2; j < 2 + t; j++) { if (j == 2 + (t + 1) / 2 && s[j] != '#') { cout << "NA" << endl; goto end; } else if (j != 2 + (t + 1) / 2 && s[j] != '=') { cout << "NA" << endl; goto end; } } if (s[sz - 1] != '~') { cout << "NA" << endl; continue; } cout << "A" << endl; end:; } else if (s[1] == '^') { int t = sz - 4; if (t % 2 == 1) { cout << "NA" << endl; continue; } for (int j = 0; j < t; j++) { if (j % 2 == 0 && s[j + 2] != 'Q') { cout << "NA" << endl; goto end2; } else if (j % 2 == 1 && s[j + 2] != '=') { cout << "NA" << endl; goto end2; } } if (s[sz - 1] != '~' || s[sz - 2] != '~') { cout << "NA" << endl; continue; } cout << "B" << endl; end2:; } else { cout << "NA" << endl; continue; } } 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] == '\'') { int c; for (i = 2; w[i] != '#'; i++) { if (w[i] != '=') { printf("NA\n"); continue; } c++; } i++; for (k = 0; k < c; k++) { 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; const double EPS = 1e-9; template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); } template <class T, class C> void chmax(T& a, C b) { if (a < b) a = b; } template <class T, class C> void chmin(T& a, C b) { if (b < a) a = b; } template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); } int main() { int n; cin >> n; while (n--) { string snk; cin >> snk; if (snk.size() < 2 || snk.size() % 2 != 0 || (snk.substr(0, 2) != ">'" && snk.substr(0, 2) != ">^")) { cout << "NA" << endl; } else if (snk.substr(0, 2) == ">^") { if (6 <= snk.size() && snk.substr(2, 2) == "Q=" && snk.substr(snk.size() - 2, 2) == "~~") { for (int i = 4; i < snk.size() - 2; i += 2) { if (snk.substr(i, 2) != "Q=") { goto ng; } } cout << "B" << endl; } else { ng:; cout << "NA" << endl; } } else { if (snk[(snk.size() - 3) / 2 + 2] == '#') { for (int i = 0; i < (snk.size() - 3) / 2; i++) { if (snk[i + 2] != '=' || snk[i + 3 + (snk.size() - 3) / 2] != '=') { goto ng; } } cout << "A" << 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; bool isSnakeA(string snake) { if (snake[0] != '>' || snake[1] != '\'' || snake[snake.length() - 1] != '~') { return false; } int pre = 0, post = 0; bool sharpFlag = false; for (int i = 2; i < (int)snake.length() - 1; i++) { if (!sharpFlag) { switch (snake[i]) { case '=': pre++; break; case '#': sharpFlag = true; break; default: return false; break; } } else { if (snake[i] == '=') { post++; } else { return false; } } } return pre > 0 && pre == post; } bool isSnakeB(string snake) { if (snake[0] != '>' || snake[1] != '^' || snake[snake.length() - 2] != '~' || snake[snake.length() - 2] != '~') { return false; } int count = 0; bool QFlag = false; for (int i = 2; i < (int)snake.length() - 2; i++) { switch (snake[i]) { case 'Q': if (QFlag) { return false; } else { QFlag = true; } break; case '=': if (QFlag) { count++; QFlag = false; } else { return false; } break; default: return false; break; } } return count > 0; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string snake; cin >> snake; if (isSnakeA(snake)) { cout << "A" << endl; } else if (isSnakeB(snake)) { 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; bool isA(const string& s) { if (s.size() >= 1 && s[0] != '>') return false; if (s.size() >= 2 && s[1] != '\'') return false; bool a_flag = true; bool equal_flag = false; int cnt = 0; int j; for (int i = 1; i < s.size(); i++) { if (equal_flag == false) { if (s[i] == '=') { equal_flag = true; for (j = i; j < s.size() && s[j] == '='; j++) { cnt++; } if (j >= s.size()) { a_flag = false; break; } else if (s[j] != '#') { a_flag = false; break; } else { j++; } } } else { for (; j < s.size() && s[j] == '='; j++) cnt--; } } if (cnt != 0) return false; if (a_flag == false) return false; if (equal_flag == false) return false; if (s[s.size() - 1] != '~') return false; return true; } bool isB(const string& s) { if (s.size() >= 1 && s[0] != '>') return false; if (s.size() >= 1 && s[1] != '^') return false; bool q_equal_flag = false; for (int i = 3; i < s.size(); i++) { if (s[i - 1] == 'Q' && s[i] == '=') { q_equal_flag = true; } } if (s[s.size() - 2] != '~' || s[s.size() - 1] != '~') { return false; } if (q_equal_flag == false) return false; return true; } int main() { int n; cin >> n; for (; n--;) { string s; cin >> s; if (isA(s)) { cout << "A" << endl; } else if (isB(s)) { 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
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { char snake[200]; int num; int i, j, k, l; scanf("%d", &num); for (l = 0; l < num + 1; l++) { int bodyacnt = 0; int bodybcnt = 0; int midcnt = 0; int endcnt = 0; int nacnt = 0; for (i = 0; i < 200; i++) { scanf("%c", &snake[i]); if (snake[i] == '\n') { break; } } if (snake[0] == '>') { if (snake[1] == '\'') { for (j = 2; j < i; j++) { if (snake[j] == '=') { bodyacnt++; } else if (snake[j] == '#') { break; } } for (k = j; k < i; k++) { if (snake[k] == '=') { midcnt++; } else if (snake[k] == '~') { endcnt++; if (endcnt == 1) { break; } } } } else if (snake[1] == '^') { for (j = 2; j < i / 2; j += 2) { if (snake[j] == 'Q' && snake[j + 1] == '=') { bodybcnt++; } else if (snake[i] == !'Q' && snake[i] != '=' && snake[i] != '~') nacnt++; } if (snake[i - 2] == '~' && snake[i - 1] == '~') { endcnt++; } } else nacnt++; } if (bodybcnt > 0 && endcnt == 1 && nacnt == 0) { printf("B\n"); } else if (bodyacnt == midcnt && endcnt == 1 && nacnt == 0) { printf("A\n"); } else if (l != 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 str; int n; cin >> n; while (n--) { cin >> str; int ca = 0; int cntsha = 0; bool a = true; if (str.size() % 2 == 0) { if (str[str.size() / 2] == '#') str[str.size() / 2] = '='; for (int i = 2; i < str.size() - 1; i++) { if (str[i] != '=') { a = false; break; } } if (a) ca = 1; } if (ca != 1) { bool b = true; for (int i = 2; i < str.size() - 2; i++) { if (i % 2) { if (str[i] != '=') { b = false; break; } } else { if (str[i] != 'Q') { b = false; break; } } } if (b) { ca = 2; } } if (ca == 1) { cout << "A" << endl; } else if (ca == 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; int main() { int n; cin >> n; while (n--) { string s; cin >> s; int f = 0; if (s.substr(0, 2) == ">'") { int i = 2, j1 = 0, j2 = 0; for (; i < s.length() && s[i] == '='; i++) j1++; if (i < s.length() && s[i++] == '#') { for (; i < s.length() && s[i] == '='; i++) j2++; if (j1 == j2 && i < s.length() && s[i] == '~') { cout << "A"; f++; } } } else if (s.substr(0, 2) == ">^") { int i = 2; for (; i < s.length() - 1 && s.substr(i, 2) == "Q="; i += 2) ; if (s.substr(i, 2) == "~~") { cout << "B"; f++; } } if (f == 0) cout << "NA"; cout << 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
java
import java.util.Scanner; public class Main{ public static void main(String[] args){ new Main().run(); } public void run(){ Scanner scan = new Scanner(System.in); while(scan.hasNext()){ int n = scan.nextInt(); for(int i = 0;i < n;i++){ String snake = scan.next(); if(snake.substring(0,2).equals(">'") && snake.indexOf("#") >= 2 && snake.charAt(snake.length()-1) == '~'){ int eqC = 0; int sh = 0; boolean fl = true; for(int j = 2;j < snake.length()-1;j++){ if(snake.charAt(j) == '=' && sh == 0){ eqC++; }else if(snake.charAt(j) == '='){ eqC--; }else if(snake.charAt(j) == '#' && sh == 0){ sh = 1; }else{ fl = false; } } if(fl && eqC == 0){ System.out.println("A"); }else{ System.out.println("NA"); } }else if(snake.substring(0,2).equals(">^")){ snake = snake.replaceAll("Q=",""); if(snake.equals(">^~~")){ System.out.println("B"); }else{ System.out.println("NA"); } }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; int main() { char buf[210]; int bi, n, eqc, ti; cin >> n; for (int i = 0; i < n; i++) { bi = 0; cin >> buf; if (buf[bi++] != '>') { cout << "NA" << endl; continue; } if (buf[bi] == '\'') { bi++; eqc = 0; while (buf[bi + eqc] == '=') eqc++; if (buf[bi + eqc] != '#') { cout << "NA" << endl; continue; } bi += eqc + 1; for (ti = 0; ti < eqc; ti++) if (buf[bi + ti] != '=') break; if (ti < eqc) { cout << "NA" << endl; continue; } bi += ti; if (buf[bi] == '~' && buf[bi + 1] == '\0') cout << "A" << endl; else cout << "NA" << endl; } else if (buf[bi] == '^') { bi++; while (buf[bi] == 'Q' && buf[bi + 1] == '=') bi += 2; if (buf[bi] == '~' && buf[bi + 1] == '~') { if (buf[bi + 2] == '\0') cout << "B" << endl; else cout << "NA" << endl; } else cout << "NA" << endl; } else { cout << "NA" << endl; continue; } } 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 > 5) { 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.size() % 2 == 0 && s.size() > 4) { 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
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { string s; cin >> s; if (s.size() < 4 || s.size() % 2 == 1) { puts("NA"); continue; } if (s[0] == '>' && s[1] == '\'' && s[s.size() - 1] == '~') { int cnt = 0; bool flag = false; for (int i = 2; i < s.size() - 1; i++) { if (s[i] != '=' && s[i] != '#') { puts("NA"); goto g; } if (flag && s[i] == '#') { puts("NA"); goto g; } if (s[i] == '#') flag = true; else { if (flag) cnt--; else cnt++; } } puts(cnt ? "NA" : "A"); } else if (s[0] == '>' && s[1] == '^' && s[s.size() - 2] == '~' && s[s.size() - 1] == '~') { for (int i = 2; i < s.size() - 2; i += 2) { if (s[i] != 'Q' || s[i + 1] != '=') { puts("NA"); goto g; } } puts("B"); } else puts("NA"); g:; } }
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]) { 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
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] != '#') { return 0; } return S.erase(pos, 1).size() % 2 == 0 ? 1 : 0; } 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 <bits/stdc++.h> const int INF = 10000000; using namespace std; int main() { int n; string s; cin >> n; for (int k = 0; k < (int)(n); k++) { cin >> s; if (s.length() < 2) { cout << "NA" << endl; goto end; } else if (s[0] == '>' && s[1] == '\'') { int num1 = 0, num2 = 0, i; for (i = 2; i < s.length() - 1; i++) { if (s[i] == '=') num1++; else if (s[i] == '#') break; else { cout << "NA" << endl; goto end; } } for (; i < s.length() - 1; i++) { if (s[i] == '=') num2++; } if (num1 == num2 && s[s.length() - 1] == '~') { cout << "A" << endl; } else { cout << "NA" << endl; goto end; } } else if (s[0] == '>' && s[1] == '^') { bool f = true; for (int i = 2; i < s.length() - 2; i++) { if (i % 2 == 0 && s[i] != 'Q') f = false; else if (i % 2 == 1 && s[i] != '=') f = false; } if (f && s[s.length() - 2] == '~' && s[s.length() - 1] == '~') { cout << "B" << endl; } else { cout << "NA" << endl; goto end; } } else cout << "NA" << endl; 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
java
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args){ try{ new Main(); }catch(IOException e){ e.printStackTrace(); } } public Main() throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); List<String> Ans = new ArrayList<String>(); String line = in.readLine(); int size = Integer.parseInt(line); for(int n=0; n<size; n++){ line = in.readLine(); int type = 0; String c = line.substring(0, 2); if(c.equals(">'")){ int count = 0; for(int i=2; i<line.length(); i++){ c = line.substring(i, i+1); if(c.equals("=")){ count++; } else if(c.equals("#")){ if(count != 0){ count = -count; } else{ type = -1; break; } } else if(c.equals("~")){ if(i != line.length()-1){ type = -1; break; } if(count==0){ type = 1; break; } else{ type = -1; break; } } } } else if(c.equals(">^")){ int count = 0; for(int i=2; i<line.length(); i++){ c = line.substring(i, i+1); if(count%2==0 && count>=2 && c.equals("~")){ if(i==line.length()-1){ type = -1; break; } c = line.substring(i+1, i+2); if(c.equals("~")){ type = 2; break; } else{ type = -1; break; } } if(i%2==0){ if(!c.equals("Q")){ type = -1; break; } count++; } if(i%2==1){ if(!c.equals("=")){ type = -1; break; } count++; } } } else{ type = -1; } switch(type){ case 1: Ans.add("A"); break; case 2: Ans.add("B"); break; default: Ans.add("NA"); } } for(int n=0; n<Ans.size(); n++){ System.out.println(Ans.get(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
UNKNOWN
#include <bits/stdc++.h> int main(void) { int max, num; int total; int i; char snake[201]; scanf("%d", &max); for (num = 0; num < max; num++) { scanf("%s", snake); if (strlen(snake) < 2 || snake[0] != '>') printf("NA\n"); if (snake[1] == '\'') { total = 0; i = 2; while (snake[i] == '=') { i++; num++; } if (snake[i] != '#' || num <= 0) printf("NA\n"); else { i++; while (snake[i] == '=') { i++; num--; } if (num != 0) printf("NA\n"); else if (snake[i] != '~' || snake[i + 1] != 0) printf("NA\n"); else printf("A\n"); } } else if (snake[1] == '^') { i = 2; while (snake[i] == 'Q' && snake[i + 1] == '=') i += 2; if (i == 2) printf("NA\n"); else if (snake[i] != '~' || snake[i + 1] != '~' || snake[i + 2] != 0) printf("NA\n"); else 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
python3
for _ in [0]*int(input()): s=input() a='NA' if s[1]=="'" and s[-1]=='~' and '#' in s: s=s[2:-1].split('#') a=[a,'A'][set(s[0])==set(s[1])=={'='} and len(set(s))==1] elif s[1]=='^' and s[-2:]=='~~': s=s[2:-2] a=['NA','B'][len(s)==2*s.count('Q=') and len(s)>0] print(a)
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] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); 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
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); } Q(char*a){ int i; for(i=0;a[i];i+=2) if(a[i]!='Q'||a[i+1]!='=') return 0; return i>=2; } B(){ char a[101],t,t2; return sscanf(s,">^%[Q=]~%c%c",a,&t,&t2)==2&&t=='~'&&Q(a); } main(){ scanf("%*d\n"); for(;~scanf("%[^\n]\n",s);){ if(A()) puts("A"); else if(B()) 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; int main() { int n; for (cin >> n; n--;) { string s; cin >> s; string ans = "NA"; if (s.substr(0, 2) == ">'" && s[s.size() - 1] == '~') { string tmp = s.substr(2, s.size() - 3); if (tmp.size() % 2 != 0 && tmp[tmp.size() / 2] == '#' && tmp.substr(0, tmp.size() / 2) == tmp.substr(tmp.size() / 2 + 1, tmp.size() / 2) && tmp.substr(0, tmp.size() / 2) == *(new string(tmp.size() / 2, '='))) { ans = "A"; } } else if (s.substr(0, 2) == ">^" && s.substr(s.size() - 2, 2) == "~~") { string tmp = s.substr(2, s.size() - 4); while (tmp.size() > 0) { if (tmp.substr(0, 2) == "Q=") tmp = tmp.substr(2, tmp.size() - 2); else break; } if (tmp.size() == 0) { ans = "B"; } } cout << ans << 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
char s[102];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);){puts(A()?"A ":B()?"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; int checksnake(string, int); int main(void) { int n, len, flag = 0, flag2 = 0, flag3 = 0, cnt1 = 0, cnt2 = 0; char snake[200]; int type; cin >> n; for (int i = 0; i < n; i++) { scanf("%s", snake); len = strlen(snake); type = checksnake(snake, len); if (type == 1) cout << 'A' << endl; else if (type == 2) cout << 'B' << endl; else if (type == 3) cout << "NA" << endl; } return 0; } int checksnake(string snake, int len) { int flag = 0, flag2 = 0, flag3 = 0; int true_flag = 0; int cnt1 = 0, cnt2 = 0; for (int i = 0; i < len - 1; i++) { if (snake[i] == '>' && snake[i + 1] == '\'') flag2 = 1; if (snake[i] == '=' && flag == 0 && flag2 == 1) { cnt1++; flag3 = 1; } if (snake[i] == '=' && flag == 1 && flag2 == 1) { cnt2++; flag3 = 1; } if (snake[i] == '#' && flag2 == 1 && flag3 == 1) flag = 1; } if (snake[len - 1] == '~' && cnt1 == cnt2 && flag2 == 1 && flag3 == 1) { return 1; true_flag = 1; } if (true_flag == 0) { for (int i = 0; i < len - 2; i++) { if (snake[i] == '>' && snake[i + 1] == '^') flag3 = 1; if (snake[i] == 'Q' && snake[i + 1] == '=' && flag3 == 1) flag = 1; } if (snake[len - 2] == '~' && snake[len - 1] == '~' && flag == 1 && flag3 == 1) { return 2; true_flag = 1; } } if (true_flag == 0) { return 3; } }
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 inline int in() { int x; scanf("%d", &x); return x; } vector<string> split(const string& s, char delim) { stringstream ss(s); string token; vector<string> res; while (getline(ss, token, delim)) { res.push_back(token); } return res; } int main() { int n = in(); for (int i = 0; i < n; i++) { string snake; cin >> snake; string head = snake.substr(0, 2); bool ok = true; if (head == ">'") { vector<string> ts = split(snake.substr(2), '#'); if (ts.size() == 2 && ts[0] + '~' == ts[1]) { puts("A"); } else ok = false; } else if (head == ">^") { vector<string> ts = split(snake.substr(2), '='); for (int j = 0; j < ts.size() - 1; j++) { if (ts[j] != "Q") { ok = false; } } if (ok) ok = ts[ts.size() - 1] == "~~"; if (ok) puts("B"); } else ok = false; if (!ok) 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 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[1] && 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
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 < 200; 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 < 200; 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 < 200; 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(int argc, const char* argv[]) { int num; int i, j, k, l; scanf("%d", &num); for (l = 0; l < num + 1; l++) { char snake[200]; int bodyacnt = 0; int bodybcnt = 0; int midcnt = 0; int endacnt = 0; int endbcnt = 0; int nacnt = 0; for (i = 0; i < 200; i++) { scanf("%c", &snake[i]); if (snake[i] == '\n') { break; } } if (snake[0] == '>') { if (snake[1] == '\'') { for (j = 2; j < i; j++) { if (snake[j] == '=') { bodyacnt++; } else if (snake[j] == '#') { break; } } for (k = j; k < i; k++) { if (snake[k] == '=') { midcnt++; } else if (snake[k] == '~') { endacnt++; if (endacnt == 1) { break; } } } } else if (snake[1] == '^') { for (j = 2; j < i / 2; j += 2) { if (snake[j] == 'Q' && snake[j + 1] == '=') { bodybcnt++; } else if (snake[i] == !'Q' && snake[i] != '=' && snake[i] != '~') nacnt++; } if (snake[i - 2] == '~' && snake[i - 1] == '~') { endbcnt++; } } else nacnt++; } if (bodybcnt > 0 && endbcnt == 1 && nacnt == 0) { printf("B\n"); } else if (bodyacnt == midcnt && endacnt == 1 && nacnt == 0) { printf("A\n"); } else if (l != 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 checksnake(string, int); int main(void) { int n, len; char snake[200]; int type; cin >> n; for (int i = 0; i < n; i++) { scanf("%s", snake); len = strlen(snake); type = checksnake(snake, len); if (type == 1) cout << 'A' << endl; else if (type == 2) cout << 'B' << endl; else if (type == 3) cout << "NA" << endl; for (int a = 0; a < 200; a++) { snake[a] = 0; } len = 0; } return 0; } int checksnake(string snake, int len) { int flag1 = 0, flag2 = 0, flag3 = 0; int true_flag = 0, true_flag2 = 0; int cnt1 = 0, cnt2 = 0; for (int i = 0; i < len - 1; i++) { if (snake[i] != '>' && snake[i] != '#' && snake[i] != '=' && snake[i] != '\'') { true_flag2 = 1; break; } if (snake[i] == '>' && snake[i + 1] == '\'') flag2 = 1; if (snake[i] == '=' && flag1 == 0 && flag2 == 1) { cnt1++; flag3 = 1; } if (snake[i] == '=' && flag1 == 1 && flag2 == 1) { cnt2++; flag3 = 1; } if (snake[i] == '#' && flag2 == 1 && flag3 == 1) flag1 = 1; } if (snake[len - 1] == '~' && cnt1 == cnt2 && flag2 == 1 && flag3 == 1) { return 1; true_flag = 1; } if (true_flag == 0) { for (int i = 0; i < len - 2; i++) { if (snake[i] != '>' && snake[i] != '^' && snake[i] != '=' && snake[i] != 'Q') { true_flag2 = 1; break; } if (snake[i] == '>' && snake[i + 1] == '^') flag3 = 1; if (snake[i] == 'Q' && snake[i + 1] == '=' && flag3 == 1) flag1 = 1; } if (snake[len - 2] == '~' && snake[len - 1] == '~' && flag1 == 1 && flag3 == 1) { return 2; true_flag = 1; } } if (true_flag == 0 && true_flag2 == 1) { return 3; } }
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 (; n--;) { string s; cin >> s; bool flag = false; if (s[0] != '>') { flag = true; } bool a_flag = true; bool b_flag = true; bool equal_flag = false; int cnt = 0; for (int i = 1; i < s.size(); i++) { int j; if (equal_flag == false) { if (s[i] == '=') { equal_flag = true; for (j = i; j < s.size() && s[j] == '='; j++) { cnt++; } if (j >= s.size()) { a_flag = false; break; } else if (s[j] != '#') { a_flag = false; break; } else { j++; } } } else { for (; j < s.size() && s[j] == '='; j++) cnt--; } } if (s.size() < 6) { b_flag = false; } else if (s[1] != '^') { b_flag = false; } bool q_equal_flag = false; for (int i = 3; i < s.size(); i++) { if (s[i - 1] == 'Q' && s[i] == '=') { q_equal_flag = true; } } if (s[s.size() - 2] != '~' || s[s.size() - 1] != '~') { b_flag = false; } if (flag) { cout << "NA" << endl; } else if (a_flag && equal_flag && cnt == 0 && s[s.size() - 1] == '~') { cout << "A" << endl; } else if (b_flag && q_equal_flag) { 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
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;} else{return 2;} } } if(state==TAIL_B&&count!=1)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
python3
# -*- coding: utf-8 -*- import sys import os import math N = int(input()) def is_A(s): if s[0:2] != ">'": return False if s[-1] != '~': return False body = s[2:-1] lst = body.split('#') if len(lst) != 2: return False if lst[0] == lst[1] and len(lst[0]) == lst[0].count('='): return True else: return False def is_B(s): if s[0:2] != ">^": return False if s[-2:] != '~~': return False body = s[2:-2] if body.count('Q=') == len(body) // 2: return True else: return False for s in sys.stdin: s = s.strip() if is_A(s): print('A') elif is_B(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
cpp
#include <bits/stdc++.h> using namespace std; void a() { cout << "NA" << endl; return; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string snake; cin >> snake; string::size_type aruyon; if ((aruyon = snake.find(">'")) == 0) { int equal = 0; int j; for (j = 2; snake.at(j) == '='; j++) equal++; if (equal == 0) { a(); break; } if (snake.at(j) == '#') j++; else { a(); break; } for (; snake.at(j) == '='; j++) equal--; if (equal != 0) { a(); break; } if (snake.at(j) == '~' && j + 1 == snake.size()) cout << 'A' << endl; } else if ((aruyon = snake.find(">^")) == 0) { int j; if ((aruyon = snake.find("~~")) != snake.size() - 2) { a(); break; } if (aruyon % 2 != 0) { a(); break; } for (j = 2; j < aruyon; j++) { if (snake.at(j) == 'Q') j++; else { a(); j = 0; break; } if (snake.at(j) != '=') { a(); break; } } if (j == aruyon) cout << 'B' << endl; } else a(); } 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[250]; 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> const double PI = acos(-1); using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string ans; string s; cin >> s; if (s[0] != '>') { cout << "NA" << endl; continue; } if (s[1] == '^') { ans = 'B'; int h = 2; while (h < s.size() - 2) { if (s[h++] != 'Q' || s[h++] != '=') { ans = "NA"; break; } } if (s[h++] != '~' || s[h++] != '~') ans = "NA"; if (s[h] != '\0') ans = "NA"; } else if (s[1] == '\'') { ans = 'A'; int h1 = 0, h2 = 0; int j = 1; while (s[++j] == '=') h1++; if (s[j] != '#') ans = "NA"; while (s[++j] == '=') h2++; if (s[j] != '~') ans = "NA"; if (s[++j] != '\0') ans = "NA"; if (h1 != h2) ans = "NA"; } cout << ans << 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 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) { 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) { 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
#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] != '=') { 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] == '~') { 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() { int n; cin >> n; while (n--) { string str; string kp; string set; int flag = 0; int count = 0; int i = 0; cin >> str; for (i = 0; i < 2; i++) kp += str[i]++; if (kp == ">'") { while (str[i] != '#') { if (str[i] == '=') count++; else flag = -1; if (flag == -1) break; i++; } i++; while (str[i] != '~') { if (str[i] == '=') count--; else flag = -1; if (flag == -1) break; i++; } if (flag != -1 && !count) flag = 1; } else if (kp == ">^") { while (i < str.length() - 2) { count = 2; while (count--) { set += str[i]; i++; } if (set == "Q=") flag = 2; else flag = -1; set.erase(set.begin(), set.end()); if (flag == -1) break; } for (i = str.length() - 2; i < str.length(); i++) set += str[i]; if (set == "~~" && flag == 2) flag = 2; else flag = -1; } if (flag == 1) cout << "A" << endl; else if (flag == 2) 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
import Control.Monad -- replicateM main = do n <- readLn ss <- replicateM n getLine putStr . unlines . map snakeType $ ss snakeType s | isTypeA s = "A" | isTypeB s = "B" | otherwise = "NA" isTypeA s = s == ">'" ++ eqs ++ "#" ++ eqs ++ "~" && length eqs >= 1 where eqs = takeWhile (== '=') (drop 2 s) isTypeB s = s == ">^" ++ qs ++ "~~" where qs = concat $ replicate ((length s - 4) `div` 2) "Q="
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 solve(string &s) { if (s.length() >= 3 && s.substr(0, 2) == ">'" && s[(int)s.length() - 1] == '~') { int c1 = 0, c2 = 0, t = 0, f = 0; for (int i = 2; i + 1 < (int)s.length(); ++i) { if (s[i] != '=' && s[i] != '#') f = 1; if (s[i] == '#' && t >= 1) f = 1; if (f) break; if (s[i] == '#') ++t; else if (t) ++c2; else ++c1; } if (!f && c1 == c2) return 0; } if (s.length() >= 4 && s.substr(0, 2) == ">^" && s.substr((int)s.length() - 2) == "~~") { int f = 0; for (int i = 2; i + 2 < s.length(); i += 2) if (s.substr(i, 2) != "Q=") f = 1; if (!f) return 1; } return -1; } int main() { int T; cin >> T; for (int t = 0; t < (int)(T); ++t) { string s; cin >> s; int ans = solve(s); cout << (ans == 0 ? "A" : (ans == 1 ? "B" : "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++) { bool a = false, b = false; string str; cin >> str; if (str[0] == '>' && str[1] == '\'' && str.size() % 2 == 0) { a = true; } if (str[0] == '>' && str[1] == '^' && str.size() % 2 == 0) { b = true; } if (a) { for (unsigned j = 2; j < str.size() - 1; j++) { if (j != (str.size() / 2) && str[j] != '=') { a = false; break; } } if (str[str.size() / 2] != '#' || str[str.size() - 1] != '~') a = false; } if (b) { for (unsigned j = 2; j < str.size() - 3; j += 2) { if (str[j] != 'Q' || str[j + 1] != '=') { b = false; break; } } if (str[str.size() - 2] != '~' || str[str.size() - 1] != '~') b = false; } if (a) cout << "A" << endl; else if (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(void) { int n, len, flag = 0, cnt1 = 0, cnt2 = 0; char snake[10000][200]; cin >> n; for (int i = 0; i < n; i++) { scanf("%s", snake[i]); len = strlen(snake[i]); if (snake[i][0] == '>' && snake[i][1] == '\'' && snake[i][2] == '=') { for (int j = 3; j < len - 2; j++) { if (snake[i][j] == '=' && flag == 0) cnt1++; if (snake[i][j] == '=' && flag == 1) cnt2++; if (snake[i][j] == '#') flag = 1; } if (snake[i][len - 1] == '~' && cnt1 == cnt2) cout << 'A' << endl; else cout << "NA" << endl; flag = 0; cnt1 = 0; cnt2 = 0; } else if (snake[i][0] == '>' && snake[i][1] == '^') { for (int j = 2; j < len - 3; j++) { if (snake[i][j] == 'Q' && snake[i][j + 1] == '=') flag = 1; } if (snake[i][len - 2] == '~' && snake[i][len - 1] == '~' && flag == 1) 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
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() { int n; cin >> n; getchar(); for (int i = 0; i < n; i++) { string snake; getline(cin, snake); string ans = "NA"; if (snake[0] == '>' && snake[1] == '\'') { int shape = 0; for (int i = 2; i < snake.length(); i++) { if (i + 1 >= snake.length()) { if (snake[i] == '~') ans = "A"; } else { if (snake[i] != '=' && snake[i] != '#') break; if (snake[i] == '#') { if (shape == 1) break; else { shape++; if (i - 2 != (double)(snake.length() - 4) / 2) break; } } } } } else if (snake[0] == '>' && snake[1] == '^' && snake.length() % 2 == 0) { for (int i = 3; i < snake.length(); i += 2) { if (i + 2 >= snake.length()) { if (snake[i - 1] == '~' && snake[i] == '~') ans = "B"; } else { if (snake[i - 1] != 'Q' || snake[i] != '=') break; } } } cout << ans << 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
python2
def snakeJudge(snake): if snake[:2] == ">'" : snake = snake[2 : len(snake) - 1] x1 = snake[0 : snake.index("#")] x2 = snake[snake.index("#") + 1: len(snake)] if x1 == x2 : return "A" if snake[:2] == ">^" : judge = True snake = snake[2 : len(snake) - 2] x1 = snake.count("Q=") x2 = len(snake) if x2 / 2 == x1 : return "B" return "NA" n = input() for i in range(0, n): snake = raw_input() print snakeJudge(snake)
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; int main() { int n; string snake; int idx; int count; cin >> n; getline(cin,snake); for(int i=0;i<n;i++) { getline(cin,snake); //明らかにどちらのヘビでもない if(snake[0]!='>') { cout << "NA" << endl; break; } else { //A種であるか判定 if(snake[1]=='\'') { if(snake[2]!='=') { cout << "NA" << endl; goto NA; } idx=3; count=1; while(1) { if(snake[idx]!='=' && snake[idx]!='#') { cout << "NA" << endl; goto NA; } else if(snake[idx]=='=') { idx++; count++; } else if(snake[idx]=='#') { idx++; break; } } while(1) { if(snake[idx]!='=' && snake[idx]!='~') { cout << "NA" << endl; goto NA; } else if(snake[idx]=='=') { idx++; count--; } else if(snake[idx]=='~' && idx==snake.length()-1) { if(count==0) break; else { cout << "NA" << endl; goto NA; } } else { cout << "NA" << endl; goto NA; } } cout << "A" << endl; } //B種であるか判定 else if(snake[1]=='^') { if(snake[2]!='Q') { cout << "NA" << endl; goto NA;p } if(snake[3]!='=') { cout << "NA" << endl; goto NA; } idx=4; while(1) { if(snake[idx]!='Q') break; idx++; if(snake[idx]!='=') { cout << "NA" << endl; goto NA; } idx++; } if((snake[idx]!='~' || snake[idx+1]!='~') || snake.length()>idx+2) { cout << "NA" << endl; goto NA; } cout << "B" << endl; } else { cout << "NA" << endl; goto NA; } } 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, 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++) { if (S[j] == '=') { runcnt++; K = 1; } else if (S[j] == '#') { break; } else { cout << "NA" << endl; goto end; } } for (int i = j + 1;; i++) { if (S[i] == '=') { runcnt--; } else if (runcnt == 0 && S[i] == '~' && K == 1) { cout << "A" << endl; goto end; } else { cout << "NA" << endl; goto end; } } } else if (S[0] == '>' && S[1] == '^') { int F = 0; for (j = 2;;) { if (S[j] == 'Q' && S[j + 1] == '=') { j += 2; F = 1; } else if (S[j] == '~' && S[j + 1] == '~' && F == 1) { cout << "B" << endl; goto end; } else { cout << "NA" << endl; goto end; } } } else cout << "NA" << endl; end:; } 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> const double Eps = 1e-6; using namespace std; int main() { char buf[256]; int n; scanf("%d\n", &n); while (n--) { memset(buf, '\0', sizeof(buf)); cin.getline(buf, sizeof(buf)); if (strlen(buf) < 3) { puts("NA"); continue; } const char* p = buf + 2; if (buf[0] == '>' && buf[1] == '\'') { int c[4]; memset(c, 0, sizeof(c)); int sharp, tilde; int i; for (i = 0; p[i] != '\0'; ++i) { if (p[i] == '=') ++c[0]; else if (p[i] == '#') { ++c[1]; sharp = i; } else if (p[i] == '~') { ++c[2]; tilde = i; } else ++c[3]; } if (c[0] > 0 && c[0] % 2 == 0 && c[1] == 1 && sharp == i / 2 - 1 && c[2] == 1 && tilde == i - 1) puts("A"); else puts("NA"); } else if (buf[0] == '>' && buf[1] == '^') { int i; for (i = 0; p[i] != '\0'; i += 2) { if (p[i] != 'Q' || p[i + 1] != '=') break; } if (i >= 2 && strcmp(p + i, "~~") == 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
UNKNOWN
#include <bits/stdc++.h> int main(void) { int num, i, o, sum; char line[202]; scanf("%d", &num); for (i = 0; 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
UNKNOWN
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { int num; int i, j, k, l; char snake[200]; int bodyacnt = 0; int bodybcnt = 0; int midcnt = 0; int endacnt = 0; int endbcnt = 0; int nacnt = 0; scanf("%d", &num); for (l = 0; l < num + 1; l++) { bodyacnt = 0; bodybcnt = 0; midcnt = 0; endacnt = 0; endbcnt = 0; nacnt = 0; for (i = 0; i < 200; i++) { scanf("%c", &snake[i]); if (snake[i] == '\n') { break; } } if (snake[0] == '>') { if (snake[1] == '\'' && i % 2 == 0) { for (j = 2; j < i / 2 + 1; j++) { if (snake[j] == '=') { bodyacnt++; } else if (snake[j] == '#') { break; } else break; } for (k = j; k < i - 1; k++) { if (snake[k] == '=') { midcnt++; } } if (snake[i - 1] == '~' && snake[i - 2] != '~') { endacnt++; } } else if (snake[1] == '^' && i % 2 == 0) { for (j = 2; j < i - 3; j += 2) { if (snake[j] == 'Q' && snake[j + 1] == '=') { bodybcnt++; } else nacnt = 1; } if (snake[i - 2] == '~' && snake[i - 1] == '~' && snake[i - 3] != '~') { endbcnt++; } } } printf("%d %d %d %d %d\n", bodyacnt, bodybcnt, endacnt, midcnt, nacnt); if (bodybcnt > 0 && endbcnt == 1 && nacnt == 0) { printf("B\n"); } else if (bodyacnt == midcnt && endacnt == 1 && nacnt == 0 && bodyacnt > 0) { printf("A\n"); } else if (l != 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() { int n; cin >> n; for (int i = 0; i < n; i++) { string str; cin >> str; if (str.size() <= 4) cout << "NA" << endl; if (str.substr(0, 2) == ">'" && str[str.size() - 1] == '~' && str.size() % 2 == 0) { string ss = str.substr(2, str.size() - 3); if (ss.size() >= 3) { bool f = true; for (int j = 0; j < ss.size(); j++) { if (j == 0) { if (ss[j] != '=') { f = false; break; } } else if (j == ss.size() / 2) { if (ss[j] != '#') { f = false; break; } } else { if (ss[j] != '=') { f = false; break; } } } if (f) cout << "A" << endl; else cout << "NA" << endl; } else { cout << "NA" << endl; } } else if (str.substr(0, 2) == ">^" && str.substr(str.size() - 2, 2) == "~~" && str.size() % 2 == 0) { string ss = str.substr(2, str.size() - 4); bool f = true; if (ss.size() >= 2) { for (int j = 0; j < ss.size(); j += 2) { if (ss.substr(j, 2) != "Q=") { f = false; break; } } if (f) cout << "B" << endl; else cout << "NA" << endl; } else cout << "NA" << endl; } else cout << "NA" << endl; } return 0; }