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 a = 0, b = 0; bool f; if (s[0] == '>') { if (s[1] == '^') { f = false; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'Q' && s[i + 1] == '=') f = true; } if (f && s[s.size() - 1] == '~' && s[s.size() - 2] == '~') { cout << "B" << endl; continue; } } int cnt = 0, k = 0; f = false; while (k < s.size()) { if (s[k] == '=') { while (s[k] == '=') { cnt++; k++; } break; } k++; } if (s[k] == '#') f = true; while (k < s.size()) { if (s[k] == '=') { while (s[k] == '=') { cnt--; k++; } break; } k++; } if (f && cnt == 0) { cout << "A" << endl; continue; } } 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(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] == '^' && snake[i][2] == 'Q' && snake[i][3] == '=') { if (snake[i][len - 2] == '~' && snake[i][len - 1] == '~') cout << 'B' << endl; } else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int 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
cpp
#include <bits/stdc++.h> using namespace std; bool A(string s) { if (s[0] != '>' || s[1] != '\'' || s[s.size() - 1] != '~') return false; if (s.size() % 2 == 1) return false; if (s[s.size() / 2] != '#') return false; s[s.size() / 2] = '='; for (int i = 2; i < s.size() - 1; i++) { if (s[i] != '=') return false; } return true; } bool B(string s) { if (s[0] != '>' || s[1] != '^' || s[s.size() - 2] != '~' || s[s.size() - 1] != '~') return false; for (int i = 2; i < s.size() - 2; i++) { if (i % 2 == 0) { if (s[i] != 'Q') return false; } else { if (s[i] != '=') return false; } } return true; } int main(void) { string str; int n; cin >> n; while (n--) { cin >> str; if (A(str)) cout << "A" << endl; else if (B(str)) cout << "B" << endl; else cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> bool checkA(char *p) { int eqCnt = 0; if (*p++ != '>') return false; if (*p++ != '\'') return false; while (*p++ == '=') eqCnt++; p--; if (*p++ != '#') return false; while (*p++ == '=') eqCnt--; p--; if (eqCnt != 0) return false; if (*p++ != '~') return false; if (*p != '\0') return false; return true; } bool checkB(char *p) { if (*p++ != '>') return false; if (*p++ != '^') return false; while (*p++ == 'Q') { if (*p++ != '=') return false; } p--; if (*p++ != '~' || *p++ != '~') return false; if (*p != '\0') return false; return true; } int main(void) { int n; char str[256]; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", str); if (checkA(str)) { puts("A"); } else if (checkB(str)) { puts("B"); } else { puts("NA"); } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool n[486848] = {}; int main() { string str, x = " "; int N; cin >> N; for (int i = 0; i < N; i++) { cin >> str; for (int j = 0; j < 2; j++) x[j] = str[j]; if (x == ">'" && str[str.size() - 1] == '~') { bool f = true; int C = 0; int mid = (2 + str.size() - 2) / 2; for (int j = 2; j <= str.size() - 2; j++) { if (j != mid && str[j] != '=') { f = false; } else if (j == mid && str[j] != '#') f = false; if (str[j] == '=') C++; } if (C % 2 != 0) f = false; if (f == true) cout << "A" << endl; else cout << "NA" << endl; } else if (x == ">^" && str[str.size() - 1] == '~' && str[str.size() - 2] == '~') { bool f = true; int C = 0; for (int j = 2; j < str.size() - 2; j++) { C++; if (C % 2 == 0 && str[j] != '=') f = false; if (C % 2 == 1 && str[j] != 'Q') f = false; } if (C % 2 != 0) f = false; if (f == true) cout << "B" << endl; else cout << "NA" << endl; } else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main(void) { int n; scanf("%d", &n); while (n-- > 0) { char snake[256] = {0}; int i; char *kind; int equal = 0; int tilda = 0; int sharp = 0; scanf("%s", snake); if (strncmp(">'", snake, 2) == 0) kind = "A"; else if (strncmp(">^", snake, 2) == 0) kind = "B"; else kind = "NA"; for (i = 2; snake[i] != 0 && *kind != 'N'; i++) { if (*kind == 'A') { switch (snake[i]) { case '=': sharp == 0 ? equal++ : equal--; break; case '#': sharp++; break; case '~': tilda++; break; } if (sharp > 1 || tilda > 1 || equal < 0) kind = "NA"; } else { switch (snake[i]) { case 'Q': i += snake[i + 1] == '='; break; case '~': tilda++; break; } if (tilda > 2 || snake[i] == 'Q') kind = "NA"; } } if (*kind == 'A' && equal != 0) kind = "NA"; puts(kind); } 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, i, j; string str; cin >> n; for (i = 0; i < n; i++) { cin >> str; if (str[0] == '>') { if (str[1] == '\'') { int num = 0; for (j = 2; j < str.size(); j++) { if (str[j] == '=') num++; else if (num > 0 && str[j] == '#') { for (j += 1; j < str.size(); j++) { if (j == str.size() - 1 && str[j] == '~' && num == 0) cout << "A" << endl; else if (j != str.size() - 1 && str[j] == '=') num--; else { cout << "NA" << endl; break; } } break; } else { cout << "NA" << endl; break; } } } else if (str[1] == '^') { for (j = 2; j < str.size(); j++) { if (j == str.size() - 2 && str[j] == '~' && str[j + 1] == '~') { cout << "B" << endl; break; } if (j == str.size() - 2 && str[j] != '~' || str[j + 1] != '~') { cout << "NA" << endl; break; } else if ((j % 2 == 0 && str[j] != 'Q') || (j % 2 == 1 && str[j] != '=')) { cout << "NA" << endl; break; } } } } else cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { StringBuilder sb = new StringBuilder(); int n = int.Parse(Console.ReadLine()); while (n-- > 0) { string input = Console.ReadLine().Trim(); if (input[0] != '>') { sb.AppendLine("NA"); continue; } switch (input[1]) { case '\'': if (input.Length % 2 == 1) sb.AppendLine("NA"); else { int idx = 2, count = 0; while (input[idx] == '=' && idx < input.Length) { count++; idx++; } string temp = new string(Enumerable.Repeat('=', count).ToArray()); string makeA = ">'" + temp + "#" + temp + "~"; if (input == makeA) sb.AppendLine("A"); else sb.AppendLine("NA"); } break; case '^': if (input.Length % 2 == 1) sb.AppendLine("NA"); else { int vol = input.Length / 2 - 2; string makeB = ">^"; for (int i = 0; i < vol; i++) { makeB += "Q="; } makeB += "~~"; if (input == makeB) sb.AppendLine("B"); else sb.AppendLine("NA"); } break; default: sb.AppendLine("NA"); break; } } Console.Write(sb); } } }
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; string s; for (int i = 0; i < n; ++i) { cin >> s; int m = s.size(); string res; if (s.size() < 6 || s.size() % 2 == 1) { res = "NA"; } else if (s.substr(0, 2) == ">'" && s[m - 1] == '~') { res = "A"; if (s[m / 2] != '#') { res = "NA"; } for (int j = 2; j <= m - 2; ++j) { if (j == m / 2) continue; if (s[j] != '=') { res = "NA"; break; } } } else if (s.substr(0, 2) == ">^" && s.substr(m - 2, 2) == "~~") { res = "B"; for (int j = 2; j <= m - 4; j += 2) { if (s[j] != 'Q' || s[j + 1] != '=') { res = "NA"; break; } } } 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
python3
for _ in [0]*int(input()): s=input() if s[1]=='\'': a=s[2:-1].split('#') print(['NA','A'][set(a[0])==set(a[1])=={'='} and len(set(a))==1]) else: s=s[2:-2] print(['NA','B'][len(s)==2*s.count('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
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 ++ "~" 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 main() { int n, a, c, f; string str = "\0"; cin >> n; for (int i = 0; i < n; ++i) { cin >> str; c = f = 0; a = 2; if (str[0] == '>') { if (str[1] == '\'') { while (str[a] == '=') { ++a; ++c; } if (str[a] != '#') goto end; ++a; while (str[a] == '=') { ++a; ++f; } if (str[a] == '~' && c == f) cout << "A" << endl; else goto end; } else if (str[1] == '^') { while (str[a] == 'Q' && str[a + 1] == '=') { a += 2; } if (str[a] == '~' && str[a + 1] == '~') cout << "B" << endl; else goto end; } else goto end; } else { end: cout << "NA" << endl; } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { string str; int N; cin >> N; for (int i = 0; i < N; i++) { cin >> str; string x = " "; for (int j = 0; j < 2; j++) x[j] = str[j]; if (str[0] == '>') { if (str[1] == '\'' && str[str.size() - 1] == '~') { bool f = true; int C = 0; int mid = (2 + str.size() - 2) / 2; for (int j = 2; j <= str.size() - 2; j++) { if (j != mid && str[j] != '=') { f = false; } else if (j == mid && str[j] != '#') f = false; if (str[j] == '=') C++; } if (C % 2 != 0) f = false; if (f == true) cout << "A" << endl; else cout << "NA" << endl; } else if (str[1] == '^' && str[str.size() - 1] == '~' && str[str.size() - 2] == '~') { bool f = true; int C = 0; for (int j = 2; j < str.size() - 2; j++) { C++; if (C % 2 == 0 && str[j] != '=') f = false; if (C % 2 == 1 && str[j] != 'Q') f = false; } if (C % 2 != 0) f = false; if (f == true) cout << "B" << endl; else cout << "NA" << endl; } } else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string judgeSnakeType(string s) { if (s.find(">'") == 0 && s.find("~") == s.size() - 1) { s.erase(s.size() - 1, 1); s.erase(0, 2); int cnt = 0; while (s.size() > 0 && s[0] == '=') { if (s[0] == '=') { s.erase(0, 1); cnt++; } } if (s[0] != '#') return "NA"; s.erase(0, 1); while (s.size() > 0 && s[0] == '=') { if (s[0] == '=') { s.erase(0, 1); cnt--; } } if (s.size() == 0 && cnt == 0) return "A"; else return "NA"; } else if (s.find(">^") == 0 && s.find("~~") == s.size() - 2) { s.erase(s.size() - 2, 2); s.erase(0, 2); while (s.size() > 0 && s.size() % 2 == 0) { if (s[0] == 'Q' && s[1] == '=') { s.erase(0, 2); } else { return "NA"; } } return s == "" ? "B" : "NA"; } else { return "NA"; } return "NA"; } void solve(string snake) { cout << judgeSnakeType(snake) << endl; } int main() { int d; cin >> d; string snake; for (int i = 0; i < d; i++) { cin >> snake; solve(snake); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); while (n-- > 0) { String snake = sc.next(); if (snake.indexOf('#') > 0 && snake.charAt(0) == '>' && snake.charAt(1) == '\'' && snake.charAt(snake.length() - 1) == '~') { String[] l = snake.split("#"); if (l[0].length() - 1 == l[1].length() && l[0].length() + l[1].length() + 1 == snake.length()) { System.out.println("A"); } else { System.out.println("NA"); } } else if (snake.charAt(0) == '>' && snake.charAt(1) == '^' && snake.charAt(snake.length() - 2) == '~' && snake.charAt(snake.length() - 1) == '~' && snake.replaceAll("Q=", "").equals(">^~~")) { System.out.println("B"); } else { System.out.println("NA"); } } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int hoge = 0; hoge < n; hoge++) { string s; cin >> s; int state = 0; if (s.size() <= 5) { cout << "NA" << endl; continue; } if (s[0] == '>' && s[1] == '\'') state = 1; else if (s[0] == '>' && s[1] == '^') state = 2; int cal = 0, cnt = 0; bool mybool = true, flag = true, key; if (state) { for (int i = 0; i < s.size(); i++) { if (i == 0 || i == 1) continue; if (state == 1) { if (s[i] == '#') mybool = false; else if (mybool && s[i] == '=') cnt++; else if (mybool == false && s[i] == '=') cnt--; else if (s[i] == '~' && i == s.size() - 1) continue; else flag = false; } else if (state == 2) { if (!(s[s.size() - 1] == '~' && s[s.size() - 2] == '~')) flag = false; if (i >= s.size() - 2) continue; if ((s[i] == 'Q' && s[i + 1] == '=')) { i++; } else flag = false; } } if (state == 1 && cnt == 0 && flag) cout << "A" << endl; else if (state == 2 && 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
UNKNOWN
char s[102],a[101],b[101],t,t2;A(){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
UNKNOWN
chkA ('>':'\'':s) = chkA_1 s chkA s = False chkA_1 ('=':s) = let n = 1 + (length . takeWhile (== '=')) s in chkA_2 n $ dropWhile (== '=') s chkA_1 s = False chkA_2 n ('#':s) = chkA_3 n s chkA_2 n s = False chkA_3 n ('=':s) = let m = 1 + (length . takeWhile (== '=')) s in if n == m then chkA_4 $ dropWhile (== '=') s else False chkA_3 n s = False chkA_4 ('~':[]) = True chkA_4 s = False chkB ('>':'^':s) = chkB_1 s chkB s = False chkB_1 ('Q':'=':s) = chkB_1 s chkB_1 ('~':'~':[]) = True chkB_1 s = False ans s = let a = chkA s b = chkB s in if a then "A" else if b then "B" else "NA" main = do n <- getLine c <- getContents let n'= read n :: Int i = take n' $ lines c o = map ans i mapM_ putStrLn o
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); cout << tmp << endl; if (tmp.size() % 2 != 0 && tmp[tmp.size() / 2] == '#' && tmp.substr(0, tmp.size() / 2) == tmp.substr(tmp.size() / 2 + 1, 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
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int hoge = 0; hoge < n; hoge++) { string s; cin >> s; int state = 0; if (s[0] == '>' && s[1] == '\'') state = 1; else if (s[0] == '>' && s[1] == '^') state = 2; int cal = 0, cnt = 0; bool mybool = true, flag = true, key; if (state) { for (int i = 0; i < s.size(); i++) { if (i == 0 || i == 1) continue; if (state == 1) { if (s[i] == '#') mybool = false; else if (mybool && s[i] == '=') cnt++; else if (mybool == false && s[i] == '=') cnt--; else if (s[i] == '~' && i == s.size() - 1) continue; else flag = false; } else if (state == 2) { if (!(s[s.size() - 1] == '~' && s[s.size() - 2] == '~')) flag = false; if (i >= s.size() - 2) continue; if (!(s[i] == 'Q' && s[i + 1] == '=')) flag = false; else i++; } } if (state == 1 && cnt == 0 && flag) cout << "A" << endl; else if (state == 2 && 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.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
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s; cin >> s; if (s[0] == '>') { if (s[1] == '\'') { int sum = 0; for (int i = 0; i < s.size(); i++) if (s[i] == '=') sum++; if (s.size() % 2 == 0 && s[s.size() / 2] == '#' && sum == s.size() - 4 && s[s.size() - 1] == '~') cout << 'A' << endl; else goto L; } else if (s[1] == '^') { int c = 2; if (s.size() % 2) goto L; while (c < s.size() - 3) { if (s[c] != 'Q') goto L; c++; if (s[c] != '=') goto L; c++; } if (s[c] == '~' && s[c + 1] == '~') cout << 'B' << endl; else goto L; } else goto L; } else goto L; if (0) L: 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[201] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 201; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 201; j++) { if (snake[j] == '=') { count--; } else if (snake[j] == '~') { idx = j; break; } else { break; } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 201; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2)) && j > 3) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
for _ in [0]*int(input()): s=input() if s[:2]==">'" and s[-1]=='~' and '#' in s: s=s[2:-1].split('#') print(['NA','A'][set(s[0])==set(s[1])=={'='} and len(set(s))==1]) elif s[:2]=='>^' and s[-2:]=='~~': s=s[2:-2] print(['NA','B'][len(s)==2*s.count('Q=') and len(s)>0])
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const double EPS = 1e-12; const double PI = acos(-1.0); int main() { int n; cin >> n; for (int i = (0); i <= ((n)-1); ++i) { string s; cin >> s; string h = s.substr(0, 2); if (h == ">'") { s += "!"; if (s.find('#') != string::npos) { int pos = s.find('#'); int size = pos - 2; for (int i = (0); i <= ((pos - 2) - 1); ++i) { if (s[i + 2] == s[i + pos + 1] && s[i + 2] == '=') { } else { cout << "NA" << endl; goto next; } } if (s[pos + size + 1] == '~') { cout << "A" << endl; goto next; } else { cout << "NA" << endl; goto next; } } else { cout << "NA" << endl; goto next; } } else if (h == ">^") { s += "!!"; int b = 2; while (s.substr(b, 2) == "Q=") { b += 2; } if (s.substr(b, 2) == "~~") { cout << "B" << endl; goto next; } else { cout << "NA" << endl; goto next; } } else { cout << "NA" << endl; goto next; } next:; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, a, c, f; string str = "\0"; cin >> n; for (int i = 0; i < n; ++i) { cin >> str; c = f = 0; a = 2; if (str[0] == '>') { if (str[1] == '\'') { while (str[a] == '=') { ++a; ++c; } if (str[a] != '#' || c == 0) goto end; ++a; while (str[a] == '=') { ++a; ++f; } if (str[a] == '~' && c == f) cout << "A" << endl; else goto end; } else if (str[1] == '^') { while (str[a] == 'Q' && str[a + 1] == '=') { a += 2; } if (str[a] == '~' && str[a + 1] == '~') cout << "B" << endl; else goto end; } else goto end; } else { end: 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 isOutOfStr(int ind, string str) { return ind >= str.length(); } int main(void) { int n; cin >> n; while (n--) { string str; cin >> str; if (!isOutOfStr(1, str) && str[0] == '>' && str[1] == '\'') { int sharp_cnt = 0; int ind; ind = 2; if (!isOutOfStr(ind, str) && str[ind] != '=') { cout << "NA" << endl; continue; } for (;; ind++) { if (isOutOfStr(ind, str) || str[ind] != '=') { break; } sharp_cnt++; } if (isOutOfStr(ind, str) || str[ind] != '#') { cout << "NA" << endl; continue; } ind++; bool flg = true; for (int i = 0; i < sharp_cnt; i++, ind++) { if (isOutOfStr(ind, str) || str[ind] != '=') { cout << "NA" << endl; flg = false; break; } } if (!flg) continue; if (!isOutOfStr(ind, str) && str[ind] == '~' && ind == str.length() - 1) cout << "A" << endl; else { cout << "NA" << endl; } } else if (str[0] == '>' && str[1] == '^') { int ind; ind = 2; int flg = true; for (;; ind += 2) { if (isOutOfStr(ind, str) || !(str[ind] == 'Q' && str[ind + 1] == '=')) { break; } } if (!isOutOfStr(ind, str) && !isOutOfStr(ind + 1, str) && str[ind] == '~' && str[ind + 1] == '~' && ind + 1 == str.length() - 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; 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; string res = species[2]; for (i = 0; i < n; ++i) { 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; bool flag = false; for (j = 2; j < len; ++j) { if (str[j] == '=') { if (!flag) { ++prev; } else { ++after; } continue; } else if (str[j] == '#') { flag = true; continue; } else if (j == len - 1 && str[j] == '~' && flag && prev != 0 && after != 0 && prev == after) { res = species[0]; } else { res = species[2]; break; } } } 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
cpp
#include <bits/stdc++.h> using namespace std; string solv(string s) { int ss = s.size(); if (s[0] != '>' || s[ss - 1] != '~') return "NA"; if (s[ss - 2] == '~') { if (s[1] != '^') return "NA"; for (int i = 0; i < ss - 2; i++) { if (s[i] == 'Q' && s[i + 1] == '=') return "B"; } } else { if (s[1] != '\'') return "NA"; int a = 0, f = 0; for (int i = 1; i < ss - 1; i++) { if (s[i] == '=' && !f) a++; if (s[i] == '#') f = 1; if (f && !a) return "NA"; if (s[i] == '=' && f) a--; } return a ? "NA" : "A"; } return "NA"; } int main() { int n; cin >> n; string s; while (n--) { cin >> s; cout << solv(s) << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int z = 0; z < n; z++) { string a; cin >> a; string b = a.substr(0, 2), c = a.substr(a.length() - 2, 2); if (b == ">'") { if (c[1] == '~') { int d[2] = {0, 0}, e = 0; bool f = false; for (int i = 2; i < a.length() - 1; i++) { if (a[i] == '=') { while (a[i] == '=') { i++; d[e]++; } e++; } if (a[i] == '#' && e == 1) { f = true; } } if (f == true && d[0] == d[1]) { cout << "A" << endl; goto stop; } } } if (b == ">^") { if (c == "~~") { for (int i = 2; i < a.length() - 2; i++) { string d = a.substr(i, 2); if (d == "Q=") { cout << "B" << endl; goto stop; } } } } cout << "NA" << endl; stop:; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int in; cin >> in; for (int i = 0; i < in; i++) { int status = 0; string snake; cin >> snake; if (snake[0] != '>') { cout << "NA" << endl; continue; } if (snake[1] == '^') { for (int j = 2; j < snake.size() - 2; j += 2) { if (snake[j] != 'Q' || snake[j + 1] != '=') { cout << "NA" << endl; status = 1; break; } } if (snake[snake.size() - 2] == '~' && snake[snake.size() - 1] == '~' && status == 0) { cout << "B" << endl; } continue; } else if (snake[1] == '\'') { int head = 0, tale = 0, join; for (int j = 2; j < snake.size(); j++) { if (snake[j] == '#') { join = j; break; } head++; } for (int j = join + 1; j < snake.size() - 1; j++) { tale++; } if (head == tale && snake[snake.size() - 1] == '~') { cout << "A" << endl; continue; } } cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
chkA ('>':'\'':s) = chkA_1 s chkA s = False chkA_1 ('=':s) = chkA_2 n $ dropWhile (== '=') s where n = 1 + (length . takeWhile (== '=')) s chkA_1 s = False chkA_2 n ('#':s) = chkA_3 n s chkA_2 n s = False chkA_3 n ('=':s) = if n == m then chkA_4 $ dropWhile (== '=') s else False where m = 1 + (length . takeWhile (== '=')) s chkA_3 n s = False chkA_4 ('~':[]) = True chkA_4 s = False chkB ('>':'^':s) = chkB_1 s chkB s = False chkB_1 ('Q':'=':s) = chkB_2 s chkB_2 ('Q':'=':s) = chkB_2 s chkB_2 ('~':'~':[]) = True chkB_2 s = False ans s = let a = chkA s b = chkB s in if a then "A" else if b then "B" else "NA" main = do n <- getLine c <- getContents let n'= read n :: Int i = take n' $ lines c o = map ans i mapM_ putStrLn o
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() { char data[110]; int a, b, i, n, c, j, len, temp; scanf("%d", &n); for (i = 0; i < n; i++) { a = b = 0; if (scanf("%s", data) == EOF) break; ; len = strlen(data); if (len >= 6 && len % 2 == 0) { if (data[0] == '>' && data[1] == '\'' && data[2] == '=') { c = 0; for (j = 2; j < len; j++) { if (data[j] != '=') break; c++; } temp = j; if (temp != len) { if ((len - 4) / 2 == c && data[temp] == '#') { c = 0; for (j = temp + 1; j < len; j++) { if (data[j] != '=') break; c++; } if (j == (len - 1)) { if ((len - 4) / 2 == c && data[j] == '~') a = 1; } } } } if (data[0] == '>' && data[1] == '^' && data[2] == 'Q' && data[3] == '=') { c = 0; for (j = 2; j < len; j += 2) { if (data[j] == 'Q' && data[j + 1] == '=') c++; else break; } if (j == (len - 2)) { if (data[j] == '~' && data[j + 1] == '~') b = 1; } } } if (a == 1 && b == 0) printf("A\n"); else if (a == 0 && b == 1) 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
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 "NA" } else if (s(1) == '^') { // maybeB var isB = true for(i<-2 until s.length-2 by 2) { if(s(i)!='Q' || s(i+1)!='=') { isB = false } } if(isB && s(s.length-2)=='~' && s(s.length-1)=='~') "B" else "NA" } else { "NA" } } else "NA" } def main(args:Array[String]) = { val n = readInt for(i<-1 to n) { val s = readLine.trim println(find(s)) } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <stdio.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') { // printf("%d\n", i); break; } } if (snake[0] == '>') { if (snake[1] == '\'') { for (j = 2; j < i; j++) { if (snake[j] == '=') { bodyacnt++; } else if (snake[j] == '#'){ break; } } else nacnt++; 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; string judgeSnakeType(string s) { if (s.find(">'") == 0 && s.find("~") == s.size() - 1) { s.erase(s.size() - 1, 1); s.erase(0, 2); int cnt = 0; while (s.size() > 0 && s[0] == '=') { if (s[0] == '=') { s.erase(0, 1); cnt++; } } if (s[0] != '#' || cnt == 0) return "NA"; s.erase(0, 1); while (s.size() > 0 && s[0] == '=') { if (s[0] == '=') { s.erase(0, 1); cnt--; } } if (s.size() == 0 && cnt == 0) return "A"; else return "NA"; } else if (s.find(">^") == 0 && s.find("~~") == s.size() - 2) { s.erase(s.size() - 2, 2); s.erase(0, 2); while (s.size() > 0 && s.size() % 2 == 0) { if (s[0] == 'Q' && s[1] == '=') { s.erase(0, 2); } else { return "NA"; } } return s == "" ? "B" : "NA"; } else { return "NA"; } return "NA"; } void solve(string snake) { cout << judgeSnakeType(snake) << endl; } int main() { int d; cin >> d; string snake; for (int i = 0; i < d; i++) { cin >> snake; solve(snake); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A(char snake[]) { int i, num; if (snake[0] != '>' || snake[1] != '\'') { return (0); } i = 2; num = 0; while (snake[i] == '=') { i++; num++; } if (num == 0) { return (0); } if (snake[i++] != '#') { return (0); } while (snake[i] == '=') { i++; num--; } if (snake[i] != '~') { return (0); } if (num == 0) { return (1); } return (0); } int B(char snake[]) { int i; if (snake[0] != '>' || snake[1] != '^') { return (0); } i = 2; while (snake[i] == 'Q' && snake[i + 1] == '=') { i += 2; } if (i == 2) { return (0); } if (snake[i] == '~' || snake[i + 1] == '~') { return (1); } return (0); } int main(void) { int i, n; char snake[256]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", snake); if (A(snake)) { puts("A"); } else if (B(snake)) { puts("B"); } else { puts("NA"); } } return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool kind_a(string str) { if (str[0] != '>' || str[1] != '\'' || str[str.size() - 1] != '~') { return false; } string su = str.substr(2, str.size() - 3); for (int i = 0; i < su.size(); ++i) { int j = su.size() - 1 - i; if (i >= j) break; if (su[i] != '=' || su[i] != su[j]) { return false; } } return su[(su.size() - 1) / 2] == '#'; } bool kind_b(string str) { if (str[0] != '>' || str[1] != '^' || str[str.size() - 2] != '~' || str[str.size() - 1] != '~') { return false; } string su = str.substr(2, str.size() - 4); for (int i = 0; i < su.size(); ++i) { int j = su.size() - 1 - i; if (i >= j) break; if (!(su[i] == 'Q' && su[j] == '=' || su[j] == 'Q' && su[i] == '=')) { return false; } } return true; } string solve(string str) { if (kind_a(str)) { return "A"; } else if (kind_b(str)) { return "B"; } else { return "NA"; } } int main() { int n; cin >> n; while (n--) { string str; cin >> str; cout << solve(str) << 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; 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] == '~')) 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; template <class T> void debug(T a) { for (auto i : a) cout << i << endl; } int dx[4] = {0, -1, 1, 0}, dy[4] = {1, 0, 0, -1}; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string a; cin >> a; bool ok = true; string ans; if (a[0] == '>' && a[1] == '\'') ans = "A"; else if (a[0] == '>' && a[1] == '^') ans = "B"; else ok = false; if (ans == "A") { int c = 0; for (int j = 2; j < a.size(); j++) { if (a[j] == '=') c++; else break; } if (c > a.size() / 2) { ok = false; goto end; } if (a[2 + c] != '#') { ok = false; goto end; } int d = 0; for (int j = 2 + c + 1; j < a.size(); j++) { if (a[j] == '=') d++; else break; } if (d != c) { ok = false; goto end; } int e = 0; for (int j = 2 + c + d + 1; j < a.size(); j++) { if (a[j] == '~') e++; else { ok = false; goto end; } } if (e != 1) ok = false; } if (ans == "B") { int j; for (j = 2; j < a.size() - 1; j += 2) { if (a[j] != 'Q' || a[j + 1] != '=') { break; } } if (a[j] != '~' || a[j + 1] != '~') ok = false; if (j != a.size() - 2) ok = false; } end: if (ok) cout << ans << 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 n; string s; int check() { if (s.size() < 6) return 0; if (s[0] != '>') return 0; if (s[1] == '\'') { int cnt = 0, cntp = 0; for (int i = 2; i < s.size() - 1; i++) { if (s[i] != '=') break; cnt++; cntp++; } if (s[2 + cnt] != '#') return 0; for (int i = cnt + 3; i < s.size(); i++) { if (s[i] != '=') break; cnt--; cntp++; } if (cnt) return 0; if (2 + cntp + 2 != s.size()) return 0; return (s[2 + cntp + 1] == '~' ? 1 : 0); } if (s[1] == '^') { int cnt = 0; for (int i = 2; i < s.size() - 2; i += 2) { if (s[i] != 'Q' || s[i + 1] != '=') break; cnt += 2; } if (cnt + 4 != s.size()) return 0; return ((s[cnt + 2] == '~' && s[cnt + 3] == '~') ? 2 : 0); } return 0; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { cin >> s; cout << check() << 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[210] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { snake[i] = getchar(); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 210; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 210; j++) { if (snake[j] == '=') { count--; } else if (snake[j] == '~') { idx = j; break; } else { return (0); } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 210; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2)) && j > 3) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; int check(string S) { if (S[0] != '>' || S[S.size() - 1] != '~') { return 0; } if (S[1] == '\'') { if (S.substr(2, S.size() - 3).find_first_not_of("#=", 0) != string::npos) return 0; string tmpB = S.substr(2, S.find('#') - 2); string tmpA = S.substr(S.find('#') + 1, S.size() - (S.find('#') + 2)); return tmpB.size() == tmpA.size() ? 1 : 0; } if (S[1] == '^' && S[S.size() - 2] == '~') { if (S.substr(2, S.size() - 4).find_first_not_of("Q=", 0) != string::npos) return 0; for (int i = 2; i < S.size() - 2; i += 2) { if (S[i] != 'Q' && S[i + i] != '=') return 0; } return 2; } return 0; } int main() { int N; cin >> N; vector<string> res{"NA", "A", "B"}; string S; while (cin >> S) { cout << res[check(S)] << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { bool judge = false; string s; cin >> s; if (s[0] == '>') { if (s[1] == '\'' && s[s.size() - 1] == '~') { if (s[s.size() / 2] == '#' && !(s.size() & 1)) cout << "A" << endl; else judge = true; } else if (s[1] == '^' && s[s.size() - 1] == s[s.size() - 2] && s[s.size() - 1] == '~') { for (int i = 2; i < s.size() - 2; i++) { if ((!(i & 1) && s[i] != 'Q') || (i & 1 && s[i] != '=')) judge = true; } if (!judge) cout << "B" << endl; } else judge = true; } else judge = true; if (judge) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const double Eps = 1e-6; using namespace std; int main() { char buf[256]; int n; cin.getline(buf, sizeof(buf)); sscanf(buf, "%d", &n); while (n--) { memset(buf, '\0', sizeof(buf)); cin.getline(buf, sizeof(buf)); if (strlen(buf) < 3) { puts("NA"); continue; } 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] & 1) == 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, "~~")) 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> 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 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
UNKNOWN
gets.to_i.times do case line=gets.chomp when line=~/>'=+#=+~~/o puts :A when line=~/>^(:?Q=)+~~/o 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 in; int isA() { if (in[0] != '>') return 0; if (in[1] != '\'') return 0; if (!(in[in.length() - 1] == '~' && in[in.length() - 2] == '=')) return 0; int data[2] = {0, 0}; int status = 0; for (int i = 2; i < in.length() - 1; i++) { if (in[i] == '#') status = 1; if (in[i] == '=') data[status]++; } if (data[0] && data[0] == data[1]) return 1; return 0; } int isB() { if (in[0] != '>') return 0; if (in[1] != '^') return 0; if (!(in[in.length() - 1] == '~' && in[in.length() - 2] == '~')) return 0; for (int i = 2; i < in.length() - 3; i += 2) { if (!(in[i] == 'Q' && in[i + 1] == '=')) return 0; } return 1; } int main() { int num; cin >> num; for (int i = 0; i < num; i++) { cin >> in; if (isA()) cout << "A" << endl; else if (isB()) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
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().Trim(); 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 || 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 != "") return NA; return "B"; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string in; int isA() { if (in[0] != '>') return 0; if (in[1] != '\'') return 0; if (!(in[in.length() - 1] == '~' && in[in.length() - 2] == '=')) return 0; int data[2] = {0, 0}; int status = 0; for (int i = 2; i < in.length() - 1; i++) { if (in[i] == '#') status = 1; if (in[i] == '=') data[status]++; } if (data[0] && data[0] == data[1]) return 1; return 0; } int isB() { if (in[0] != '>') return 0; if (in[1] != '^') return 0; if (!(in[in.length() - 1] == '~' && in[in.length() - 2] == '~')) return 0; for (int i = 2; i < in.length() - 2; i += 2) { if (!(in[i] == 'Q' && in[i + 1] == '=')) return 0; } return 1; } int main() { int num; cin >> num; for (int i = 0; i < num; i++) { cin >> in; if (isA()) cout << "A" << endl; else if (isB()) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n; string s; bool check() { if (s.size() < 6) return 0; if (s[0] != '>') return 0; if (s[1] != '\'') { int cnt = 0; for (int i = 2; i < s.size() - 1; i++) { if (s[i] != '=') break; cnt++; } if (s[2 + cnt] != '#') return 0; for (int i = cnt + 3; i < s.size(); i++) { if (s[i] != '=') break; cnt--; } if (cnt) return 0; if (2 + cnt + 1 != s.size()) return 0; return s[2 + cnt] == '~' ? 1 : 0; } if (s[1] != '^') { int cnt = 0; for (int i = 2; i < s.size() - 2; i += 2) { if (s[i] != 'Q' || s[i + 1] != '=') break; cnt += 2; } if (cnt + 4 != s.size()) return 0; return (s[cnt + 2] == '~' && s[cnt + 3] == '~') ? 2 : 0; } return 0; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { cin >> s; printf("%s\n", !check() ? "NA" : (check() == 1 ? "A" : "B")); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
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++) { dou = false; 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
UNKNOWN
char s[101],a[101],b[101],t,t2;A(){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 main() { int n; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; if (s.substr(0, 2) == ">\'") { if (s[s.length() - 1] != '~') cout << "NA" << endl; else { int cnt = 0, pos = 2; bool flag = true; for (;; pos++) { if (s[pos] == '#') break; if (s[pos] == '=') cnt++; else { flag = false; break; } } if (!flag) cout << "NA" << endl; else { pos++; for (int j = 0; j < cnt; j++) { if (s[pos + j] != '=') { flag = false; break; } } if (s[pos + cnt] != '~') flag = false; if (!flag) cout << "NA" << endl; else cout << "A" << endl; } } } else if (s.substr(0, 2) == ">^") { if (s.length() % 2) cout << "NA" << endl; else { bool flag = true; for (int i = 1; i < s.length() / 2; i++) { if (i != s.length() / 2 - 1 && s.substr(i * 2, 2) != "Q=") flag = false; if (i == s.length() / 2 - 1 && s.substr(i * 2, 2) != "~~") flag = false; } if (flag) 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 checkA(char str[]) { int i; int cnt = 0; if (str[strlen(str) - 1] != '~') return 0; for (i = 2; i < strlen(str); i++) { if (str[i] == '=') cnt++; else if (str[i] == '#') break; else return 0; } i++; while (i < strlen(str)) { if (i == strlen(str) - 1) { if (cnt == 0) { printf("A\n"); return 1; } else return 0; } else { if (str[i] == '=') cnt--; else return 0; } i++; } return 0; } int checkB(char str[]) { int i; if (strlen(str) <= 4 || str[strlen(str) - 2] != '~' || str[strlen(str) - 1] != '~') return 0; for (i = 2; i < strlen(str) - 2; i++) { if (i % 2 == 0) { if (str[i] != 'Q') return 0; } else { if (str[i] != '=') return 0; } } printf("B\n"); return 1; } int main() { int n, i; int c; char snk[210]; scanf("%d", &n); for (i = 0; i < n; i++) { c = 0; scanf("%s", snk); if (snk[0] == '>' && snk[1] == '\'') c = checkA(snk); if (snk[0] == '>' && snk[1] == '^') c = checkB(snk); if (c == 0) printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <stdio.h> #include <math.h> int main(){ int syucnt[1000]={0},n,i,t,l,gou=0; char input[10000]; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%s",input); l = strlen(input); if(input[l-1]=='~'&&input[l-2]=='~'&&input[0]=='>'&&input[1]=='^'){//B種の調べ for(t=2;t<=l-4;t=t+2){ if(input[t]=='Q'&&input[t+1]=='='){ gou++; } } if(gou*2==l-4){ puts("B"); }else puts("NA");; gou=0; }else if(input[l/2]=='#'&&input[l-1]=='~'&&(l-4)%2==0&&input[0]=='>'&&input[1]=='\''){ int j=2; for(t=0;t<(l-4)/2;t++){ if(input[j]=='='&&input[l-j]=='='){ gou++; } j++; } if(gou==((l-4)/2)){ puts("A"); }else puts("NA"); gou=0; }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 i, n, state, cc; char snake[20000]; int main() { for (scanf("%d", &n); n > 0; n--) { scanf("%s", snake); if (strncmp(snake, ">'", 2) == 0 && snake[strlen(snake) - 1] == '~' && strlen(snake) % 2 == 0) { for (i = 2; i < strlen(snake) - 1; i++) { if (snake[i] != (i == strlen(snake) / 2 ? '#' : '=')) break; } if (i >= strlen(snake) - 1) { printf("A\n"); continue; } } else if (strncmp(snake, ">^", 2) == 0 && strncmp(&snake[strlen(snake) - 2], "~~", 2) == 0 && strlen(snake) % 2 == 0) { for (i = 2; i < strlen(snake) - 2; i++) { if (snake[i] != (i % 2 ? '=' : 'Q')) break; } if (i >= strlen(snake) - 2) { printf("B\n"); continue; } } 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; while (N--) { string str; cin >> str; bool Aflag, Bflag; Aflag = Bflag = true; if (str.length() < 2) { cout << "NA" << endl; continue; } 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() { int n; string s; cin >> n; for (int u = 0; u < n; u++) { cin >> s; bool a = true, b = true; if (s[0] != '>' || s.size() % 2 != 0) a = false, b = false; if (s[1] != '\'' || s[s.size() - 1] != '~') a = false; if (s[1] != '^' || s[s.size() - 1] != '~' || s[s.size() - 2] != '~') b = false; if (a) { if (s[s.size() / 2] != '#') a = false; int count = 0; for (int i = 2; i < s.size() - 1; i++) if (s[i] != '=') count++; if (count != 1) a = false; if (a) cout << "A" << endl; } if (b) { for (int i = 2; i < s.size() - 2; i++) { if (i % 2 == 0 && s[i] != 'Q') b = false; if (i % 2 == 1 && s[i] != '=') b = false; } if (b) cout << "B" << endl; } if (!a && !b) 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 in; cin >> in; for (int i = 0; i < in; i++) { int status = 0; string snake; cin >> snake; if (snake[0] != '>') { cout << "NA" << endl; continue; } if (snake[1] == '^') { for (int j = 2; j < snake.size() - 2; j += 2) { if (snake[j] != 'Q' || snake[j + 1] != '=') { cout << "NA" << endl; status = 1; break; } } if (snake[snake.size() - 2] == '~' && snake[snake.size() - 1] == '~' && status == 0) { cout << "B" << endl; } continue; } else if (snake[1] == '\'') { int head = 0, tale = 0, join; for (int j = 2; j < snake.size(); j++) { if (snake[j] == '#') { join = j; break; } head++; } for (int j = join + 1; j < snake.size() - 1; j++) { if (snake[j] != '=') { cout << "NA" << endl; status = 1; break; } tale++; } if (head == tale && snake[snake.size() - 1] == '~' && status == 0) { cout << "A" << endl; continue; } } cout << "NA" << endl; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> 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] == '#') { i++; break; } else { goto NA; } } for (; i < s.length() - 1; i++) { if (s[i] == '=') num2++; else if (s[i] != '=') { goto NA; } } if (num1 == num2 && s[s.length() - 1] == '~') { cout << "A" << endl; goto end; } else { goto NA; } } 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; goto end; } else { goto NA; } } NA: 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
cpp
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { return x * x; } const double EPS = 1e-10; const double PI = acos(-1.0); const int DX[] = {0, 1, 0, -1}; const int DY[] = {-1, 0, 1, 0}; int solve(string snake) { if (snake[0] == '>' && snake[1] == '\'') { int i = 2; while (snake[i] == '=') { i++; } if (snake[i] != '#') return 0; int length = i - 2; i++; while (snake[i] == '=') { i++; } int length2 = i - 3 - length; if (length2 != length) return 0; if (snake[i] = '~' && i == snake.length() - 1) { return 1; } } else if (snake[0] == '>' && snake[1] == '^') { int i = 2; while (snake[i] == 'Q' && snake[i + 1] == '=') { i += 2; } if (snake[i] == '~' && snake[i + 1] == '~' && i + 1 == snake.length() - 1) { return 2; } } return 0; } int main(int argc, char const *argv[]) { int n; cin >> n; for (int i = (0); i < (n); ++i) { string snake; cin >> snake; string ans; switch (solve(snake)) { case 0: ans = "NA"; break; case 1: ans = "A"; break; case 2: ans = "B"; 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
UNKNOWN
#include <bits/stdc++.h> int A_snake(char snake[]); int B_snake(char snake[]); int main(void) { int quantity, i; char snake[300] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 300; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 300; j++) { if (snake[j] == '=') { count--; } else if (snake[j] != '=') { idx = j; break; } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 300; j += 2) { if (strncmp(str, "Q=", 2) != 0 || strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2))) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { char s[201] = {0}; int i, n, j, c, h = 0; scanf("%d", &n); for (i = 0; i < n; i++) { h = 0; scanf("%s", s); if (s[0] == '>') { if (s[1] == '\'') { c = 0; for (j = 2; s[j] == '='; j++) c++; if (s[j++] == '#') { for (; s[j] == '='; j++) c--; if (c == 0 && s[j] == '~' && s[j + 1] == 0) h = 1; } } if (s[1] == '^') { h = 2; for (j = 2; s[j] == 'Q'; j += 2) { if (s[j + 1] != '=') { h = 0; break; } } if (!(s[j] == '~' && s[j + 1] == '~' && s[j + 2] == 0)) h = 0; } } if (h == 0) printf("NA\n"); if (h == 1) printf("A\n"); if (h == 2) 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; 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] == '^' && snake[i][2] == 'Q' && snake[i][3] == '=') { if (snake[i][len - 2] == '~' && snake[i][len - 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
python3
# Aizu Problem 00139: Snakes # import sys, math, os, copy # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def is_A_snake(snake): if snake[1] != "'": return False snake = snake[2:-1] segments = snake.split('#') L = len(segments[0]) target = '=' * L for segment in segments: if segment != target: return False return True def is_B_snake(snake): if snake[1] != "^" or snake[-2] != '~' or snake[2] != 'Q' or snake[-3] != '=': return False snake = snake[2:-2] L = len(snake) return snake == "Q=" * (L // 2) n = int(input()) for _ in range(n): snake = input().strip() if snake[0] != '>' or snake[-1] != '~': print("NA") else: if '#' in snake: print("A" if is_A_snake(snake) else "NA") else: print("B" if is_B_snake(snake) else "NA")
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
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 == 1) { b = true; } if (a) { for (unsigned j = 2; j < str.size() - 1; j++) { if ((j != (str.size() - 3) / 2 + 2) && str[j] != '=') { a = false; break; } } if (str[(str.size() - 3) / 2 + 2] != '#' || str[str.size() - 1] != '~') a = false; } if (b) { for (unsigned j = 2; j < str.size() - 2; 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
UNKNOWN
#include <bits/stdc++.h> int A_snake(char snake[]); int B_snake(char snake[]); int main(void) { int quantity, i; char snake[210] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { snake[i] = getchar(); if (snake[i] == EOF) break; if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 210; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 210; j++) { if (snake[j] == '=') { count--; } else if (snake[j] == '~') { idx = j; break; } else { return (0); } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 210; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2)) && j > 3) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool isSnakeA(string snake) { if (snake.substr(0, 2) != ">'" || snake[snake.length() - 1] != '~') { return false; } snake.erase(snake.begin(), snake.begin() + 2); snake.erase(snake.end() - 1, snake.end()); size_t pos = snake.find('#'); if (pos == string::npos || snake.substr(0, pos) != snake.substr(pos + 1, snake.length() - pos)) { return false; } return true; } bool isSnakeB(string snake) { if (snake.substr(0, 2) != ">^" || snake.substr(snake.length() - 2, 2) != "~~") { return false; } snake.erase(snake.begin(), snake.begin() + 2); snake.erase(snake.end() - 2, snake.end()); if (snake.length() % 2 != 0) { return false; } while (snake.empty() == false) { if (snake.substr(0, 2) != "Q=") { return false; } snake.erase(snake.begin(), snake.begin() + 2); } return true; } int main() { int n; cin >> n; while (n--) { 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; 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 == 0) cout << "NA" << endl; } } 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 0; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; static const double eps = 10e-9; bool isA(string str) { if (str[0] != '>') return false; if (str[1] != '\'') return false; int hist[] = {0, 0}; for (int i = 2, j = 0; i < str.size() - 1; i++) { if (str[i] == '=') { hist[j]++; } else if (str[i] == '#') j++; } if (hist[0] != hist[1]) return false; if (hist[0] == 0 || hist[1] == 0) return false; if (str[str.size() - 1] != '~') return false; return true; } bool isB(string str) { if (str.substr(0, 2) != ">^") return false; string rear = str.substr(2, str.size() - 2); bool isok = false; int i; for (i = 2; i < rear.size();) { if (rear.substr(i, 2) == "Q=") { isok = true; i += 2; } else break; } return (isok && rear.substr(i, 2) == "~~") && (i + 2 == rear.size()); } int main() { int n; while (~scanf("%d", &n)) { for (int i = 0; i < n; i++) { string str; cin >> str; if (isA(str)) cout << "A" << endl; else if (isB(str)) cout << "B" << endl; else cout << "NA" << endl; } } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
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] != '=') 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
python3
# -*- coding: utf-8 -*- import sys import os N = int(input()) def is_A(s): if s[0:2] != ">'": return False if s[-1] != '~': return False body = s[2:-1] if len(body) % 2 == 0: return False # body = '==#==' center_index = len(body) // 2 if body[center_index] != '#': return False if body.count('#') != 1: return False 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 len(body) % 2 != 0: return False elif 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
UNKNOWN
#include <bits/stdc++.h> int main(void) { char str[201]; int i, j, n, cnt1, cnt2, flag; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", str); cnt1 = 0; cnt2 = 0; flag = 0; if (str[0] == '>') { if (str[1] == '\'') { for (j = 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt1++; if (str[j + 1] == '#') break; } for (j = cnt1 + 2; str[j] != '\0'; j++) { if (str[j] == '=') cnt2++; } if (cnt1 == cnt2 && str[cnt1 + cnt2 + 3] == '~' && str[cnt1 + cnt2 + 4] == '\0') { printf("A\n"); flag = 1; } } else if (str[1] == '^') { for (j = 2; str[j] != '\0'; j++) { if (j % 2 == 0) { if (str[j] == 'Q' && str[j + 1] == '=') { if (str[j + 2] == '~' && str[j + 3] == '~' && str[j + 4] == '\0') { printf("B\n"); flag = 1; } } } } } } if (flag == 0) printf("NA\n"); } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { 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; }
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) == '~' && snake.indexOf('=') >= 2){ 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; break; } } 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() { string str; int n; cin >> n; while (n--) { cin >> str; int idx = 2; int cnt = 0; bool flg = true; if (str[0] == '>' && str[1] == 39) { bool used = false; while (idx < str.size() && str[idx] == '=') { used = true; cnt++; idx++; } if (str[idx] == '#') { idx++; while (idx < str.size() && str[idx] == '=') { cnt--; idx++; } } if (cnt == 0 && used) { cout << "A" << endl; flg = false; } } else if (str[0] == '>' && str[1] == '^') { while (idx + 1 < str.size() && str[idx] == 'Q' && str[idx + 1] == '=') { idx += 2; cnt++; } if (cnt > 0 && str[idx] == '~' && str[idx + 1] == '~') { cout << "B" << endl; flg = false; } } if (flg) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { string str; int n; cin >> n; while (n--) { cin >> str; int idx = 2; int cnt = 0; bool flg = true; if (str[0] == '>' && str[1] == 39) { bool used = false; while (idx < str.size() && str[idx] == '=') { used = true; cnt++; idx++; } idx++; while (idx < str.size() && str[idx] == '=') { cnt--; idx++; } if (cnt == 0 && used) { cout << "A" << endl; flg = false; } } else if (str[0] == '>' && str[1] == '^') { while (idx + 1 < str.size() && str[idx] == 'Q' && str[idx + 1] == '=') { idx += 2; cnt++; } if (cnt > 0 && str[idx] == '~' && str[idx + 1] == '~') { cout << "B" << endl; flg = false; } } if (flg) cout << "NA" << endl; } }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int A_snake(char snake[]); int B_snake(char snake[]); int main(void) { int quantity, i; char snake[201] = {0}; scanf("%d", &quantity); for (i = 0; i < quantity; i++) { scanf("%s", snake); if (snake[0] != '>') { puts("NA"); } else if (snake[1] == '\'') { if (A_snake(snake)) { puts("A"); } else { puts("NA"); } } else if (snake[1] == '^') { if (B_snake(snake)) { puts("B"); } else { puts("NA"); } } else { puts("NA"); } } return (0); } int A_snake(char snake[]) { int j, idx = 0, count = 0; for (j = 2; j < 201; j++) { if (snake[j] != '=' && snake[j] != '#') if (snake[j] != '~') return (0); if (snake[j] == '=') { count++; } else if (snake[j] == '#') { idx = j; break; } } for (j = idx + 1; j < 201; j++) { if (snake[j] == '=') { count--; } else if (snake[j] == '~') { idx = j; break; } else { return (0); } } if (count == 0) { if (snake[idx] == '~' && snake[idx + 1] == '\0') return (1); else return (0); } else { return (0); } return (0); } int B_snake(char snake[]) { int j, idx, count = 0; char *str; str = &snake[2]; for (j = 2; j < 201; j += 2) { if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++; if (!(strncmp(str, "~~", 2)) && j > 3) { idx = j; break; } str += 2; } if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) { if (snake[idx + 2] == '\0') { return (1); } else { return (0); } } else return (0); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int check_a(char *snake) { int n; if (snake[strlen(snake) - 1] != '~') { return (0); } snake[strlen(snake) - 1] = '\0'; if (*snake != '=') { return (0); } n = 0; while (*snake != '#') { if (*snake != '=') { return (0); } n++; snake++; } snake++; while (n > 0) { if (*snake != '=') { return (0); } n--; snake++; } if (*snake != '\0') { return (0); } return (1); } int check_b(char *snake) { int n; if (snake[strlen(snake) - 1] != '~' && snake[strlen(snake) - 2] != '~') { return (0); } snake[strlen(snake) - 2] = '\0'; if (*snake != 'Q') { return (0); } while (*snake != '\0') { if (*snake != 'Q') { return (0); } snake++; if (*snake != '=') { return (0); } snake++; } return (1); } int main(void) { int n; char snake[1000]; int i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", snake); if (snake[0] == '>') { if (snake[1] == '\'') { if (check_a(&snake[2]) == 1) { printf("A\n"); continue; } } else if (snake[1] == '^') { if (check_b(&snake[2]) == 1) { printf("B\n"); continue; } } } 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
chkA ('>':'\'':s) = chkA_1 s chkA s = False chkA_1 ('=':s) = let n = 1 + (length . takeWhile (== '=')) s in chkA_2 n $ dropWhile (== '=') s chkA_1 s = False chkA_2 n ('#':s) = chkA_3 n s chkA_2 n s = False chkA_3 n ('=':s) = let m = 1 + (length . takeWhile (== '=')) s in if n == m then chkA_4 $ dropWhile (== '=') s else False chkA_3 n s = False chkA_4 ('~':[]) = True chkA_4 s = False chkB ('>':'^':s) = chkB_1 s chkB s = False chkB_1 ('Q':'=':s) = chkB_1 s chkB_1 ('~':'~':[]) = True chkB_1 s = False ans s = let a = chkA s b = chkB s in if a then "A" else if b then "B" else "NA" main = do _ <- getLine c <- getContents let i = lines c o = map ans i mapM_ putStrLn o
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 hoge = 0; hoge < n; hoge++) { string s; cin >> s; int state = 0; if (s[0] == '>' && s[1] == '\'') state = 1; else if (s[0] == '>' && s[1] == '^') state = 2; int cal = 0, cnt = 0; bool mybool = true, flag = true, key; if (state) { for (int i = 0; i < s.size(); i++) { if (i == 0 || i == 1) continue; if (state == 1) { if (s[i] == '#') mybool = false; else if (mybool && s[i] == '=') cnt++; else if (mybool == false && s[i] == '=') cnt--; else if (s[i] == '~' && i == s.size() - 1) continue; else flag = false; } else if (state == 2) { if (!(s[s.size() - 1] == '~' && s[s.size() - 2] == '~')) flag = false; if (i >= s.size() - 2) continue; if ((s[i] == 'Q' && s[i + 1] == '=')) { i++; } else flag = false; } } if (state == 1 && cnt == 0 && flag) cout << "A" << endl; else if (state == 2 && 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
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; } } 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 if (snake[j] != '~') { puts("NA"); break; } else { break; } } if (snake[j] == '~' && snake[j + 1] == '~') { puts("B"); } else { puts("NA"); } break; } else { puts("NA"); break; } } else { puts("NA"); break; } } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; 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) { if (S.find_first_not_of("#=", 2) != sz - 1) { return 0; } S = S.substr(2, sz - 3); sz = S.size(); auto pos = S.find("#"); if (S.find("#", pos + 1) != string::npos) { return 0; } return sz - 1 - pos == pos ? 1 : 0; } return 0; } bool check_B(string S) { auto sz = S.size(); if (S.find(">^") == 0 && S.find("~~") == sz - 2 && sz >= 6) { 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
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 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 (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
cpp
#include <bits/stdc++.h> using namespace std; string s; int main() { int n, t, now; cin >> n; while (n--) { cin >> s; if (s.size() >= 6 && s.substr(0, 3) == ">'=") { t = 0; while (s[3 + (t++)] == '=') ; if (s[3 + t - 1] != '#') cout << "NA" << endl; else if (4 + 2 * t != s.size() || s.substr(3 + t, t) != s.substr(2, t)) { cout << "NA" << endl; } else if (s[3 + 2 * t] == '~') cout << "A" << endl; } else if (s.size() >= 6 && s.substr(0, 4) == ">^Q=") { now = 4; int pre = 0; while (1) { if (s.size() - now < 2) { pre = 1; break; } if (s.substr(now, 2) != "Q=") break; now += 2; } if (pre == 1) cout << "NA" << endl; else if (s.size() - now == 2 && s.substr(now, 2) == "~~") { 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
def is_a?(s) l = s.size n = (l-4)/2 return false if l.odd? return true if s.last == '~' && s[2,n] == s[-(n+1),n] && s[2,n].all?{|x| x=='='} && s[2+n] == '#' return false end def is_b?(s) l = s.size return false unless s[-2,2].all?{|x| x=='~'} s[2..-3].each_slice(2) do |q,e| return false if q != 'Q' || e != '=' end return true end gets.to_i.times do snake = gets.chomp.chars if snake.first != '>' puts "NA" next end a_or_b = snake[1] case a_or_b when "'" if is_a?(snake) puts "A" next end when '^' if is_b?(snake) puts "B" next end end puts "NA" 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
python3
# -*- coding: utf-8 -*- import sys import os N = int(input()) def is_A(s): if s[0:2] != ">'": return False if s[-1] != '~': return False body = s[2:-1] if len(body) % 2 == 0: return False # body = '==#==' center_index = len(body) // 2 if body[center_index] != '#': return False if body.count('#') != 1: return False 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 len(body) % 2 != 0: return False elif body.count('Q=') > 0 and 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> 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 j = 2; while (s[j++] == 'Q' && s[j++] == '=') ; j--; if (s[j++] != '~' || s[j++] != '~') ans = "NA"; if (j != s.size()) 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 (++j != s.size()) 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; using namespace std; int main() { int n; while (cin >> n, n) { for (int x = 0; x < n; ++x) { string line; cin >> line; string sol = "NA"; int j = line.find('#'); if (line.find('#') != string::npos) { bool flag = false; string a = ""; string b = ""; for (int x = 2; x < line.size() - 1; ++x) { if (line[x] == '#') { flag = true; continue; } if (!flag) { a += line[x]; } else { b += line[x]; } } if (a == b) sol = "A"; } else { bool flag = true; for (int x = 2; x < line.size() - 3;) { if (line[x] != 'Q' || line[x + 1] != '=') flag = false; x++; x++; } if (flag) sol = "B"; } cout << sol << endl; } } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; for (int i = 0; i < (n); i++) { cin >> s; string ans; if (s[0] == '>' && s[s.size() - 1] == '~') { if (s[1] == '\'') { ans = "A"; for (int i = 2; i < s.size() - 1; i++) { if (i == s.size() / 2) { if (s[i] != '#') { ans = "NA"; break; } } else { if (s[i] != '=') { ans = "NA"; break; } } } } else if (s[1] == '^' && s[s.size() - 2] == '~') { ans = "B"; for (int i = 2; i < s.size() - 2; i += 2) { if (s[i] != 'Q' || s[i + 1] != '=') { ans = "NA"; break; } } } else ans = "NA"; } else { 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 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] == '\'') { a = true; } if (str[0] == '>' && str[1] == '^') { b = true; } if (a) { for (unsigned j = 2; j < str.size() - 1; j++) { if ((j != (str.size() - 3) / 2 + 2) && str[j] != '=') { a = false; break; } } if (str[(str.size() - 3) / 2 + 2] != '#' || str[str.size() - 1] != '~') a = false; } if (b) { for (unsigned j = 2; j < str.size() - 2; 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) { string s; int n; cin >> n; while (n--) { cin >> s; if (s[0] == '>') { if (s[1] == '\'') { int cnt1 = 0; int i; for (i = 2; s[i] == '='; i++) { cnt1++; } if (s[i] != '#') { cout << "NA" << endl; goto skip; } else i++; int cnt2 = 0; for (; s[i] == '='; i++) { cnt2++; } if (cnt1 == cnt2 && s[i] == '~') cout << "A" << endl; else cout << "NA" << endl; } else if (s[1] == '^') { int x = 2; while (s[x] == 'Q' && s[x + 1] == '=') x += 2; if (s[x] == '~' && s[x + 1] == '~' && x + 2 == s.size()) { cout << "B" << endl; } } else cout << "NA" << endl; } skip:; } return 0; }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int i, n; string s; cin >> n; while (n--) { cin >> s; if (s[0] == '>' && s[1] == '\'' && s.size() % 2 == 0) { for (i = 2; i < s.size(); i++) { if (i == s.size() / 2 && s[i] != '#') break; if (i == s.size() / 2) { i++; continue; } if (i == s.size() - 1 && s[i] == '~') { cout << "A" << endl; goto L; } if (s[i] != '=') { cout << i; break; } } } else if (s[0] == '>' && s[1] == '^') { 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; void solve() { int n; cin >> n; while (n--) { string snake; cin >> snake; if (snake.size() < 4) { cout << "NA" << endl; } else if (snake[0] == '>' && snake[1] == '\'' && snake[snake.size() - 1] == '~') { bool first = true; int count1 = 0; int count2 = 0; for (int i = 2; i < snake.size() - 1; ++i) { if (snake[i] == '=') { if (first) { ++count1; } else { ++count2; } } else if (snake[i] == '#') { first = false; } } if (count1 == count2) { cout << "A" << endl; } else { cout << "NA" << endl; } } else if (snake[0] == '>' && snake[1] == '^' && snake[snake.size() - 2] == '~' && snake[snake.size() - 1] == '~') { bool flag = true; for (int i = 2; i < snake.size() - 2; i += 2) { if (snake[i] != 'Q' || snake[i + 1] != '=') { flag = false; break; } } if (flag) { cout << "B" << endl; } else { cout << "NA" << endl; } } else { cout << "NA" << endl; } } } int main() { solve(); return (0); }
p00139 Snakes
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends with "~~" after "> ^" followed by one or more "Q =". Example of type A:>'==== # ==== ~>'== # == ~ Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~ Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do. Input The input is given in the following format: n S1 S2 :: Sn The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to. Output Print the i-th snake type A, B or NA on line i. Example Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output A B NA
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~" ], "output": [ "A\nB\nNA" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { char s[201]; int n; fscanf(stdin, "%" "d", &n); while (n--) { fscanf(stdin, "%" "s", &s); int i, f = 0; if (s[1] == '\'') { int l, r; l = r = 0; for (i = 2; s[i] == '=' && s[i] != '\0'; l++, i++) ; for (++i; s[i] == '=' && s[i] != '\0'; r++, i++) ; if ((l == r) && l != 0) puts("A"); else f = 1; } else if (s[1] == '^') { int q, e; q = e = 0; for (i = 2; (s[i] != '~' && s[i] != '~~') && s[i] != '\0'; i++) { if (s[i] == 'Q') q++; else if (s[i] == '=') e++; } if (q == e && q != 0) puts("B"); else f = 1; } if (f) 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 Eps = 1e-6; using namespace std; int main() { char buf[256]; int n; cin.getline(buf, sizeof(buf)); sscanf(buf, "%d", &n); while (n--) { memset(buf, '\0', sizeof(buf)); cin.getline(buf, sizeof(buf)); if (strlen(buf) < 3) { puts("NA"); continue; } 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] & 1) == 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 (!strcmp(p + i, "~~")) 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { private static BufferedReader br = null; static { br = new BufferedReader(new InputStreamReader(System.in)); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int cnt = parseNum(); while (cnt-- > 0) { parseSnake(); } } private static void parseSnake() { int typ = 0; String str = null; if ((str = parseStdin()) != null) { int len = str.length(); String mid = null; if (str.startsWith(">'")) { if (str.endsWith("=~")) { mid = str.substring(2, len-1); if (mid.lastIndexOf("#") == (mid.length()/2)) { typ = 1; } } } else if (str.startsWith(">^")) { if (str.endsWith("=~~")) { mid = str.substring(2, len-2); if (mid.matches("(Q=)+")) { typ = 2; } } } } switch (typ) { case 1: System.out.println("A"); break; case 2: System.out.println("B"); break; default: System.out.println("NA"); break; } } private static int parseNum() { int num = 0; String str = null; if ((str = parseStdin()) != null) { num = Integer.parseInt(str); } return num; } private static String parseStdin() { String stdin = null; try { String tmp = br.readLine(); if (tmp != null) { if (!tmp.isEmpty()) stdin = tmp; } } catch (IOException e) {} return stdin; } }