Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int A_snake(char snake[]);
int B_snake(char snake[]);
int main(void) {
int quantity, i;
char snake[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 if (snake[0] == '\n') {
puts("NA");
} else {
puts("NA");
}
}
return (0);
}
int A_snake(char snake[]) {
int j, idx = 0, count = 0;
for (j = 2; j < 200; j++) {
if (snake[j] != '=' && snake[j] != '#')
if (snake[j] != '~') return (0);
if (snake[j] == '=') {
count++;
} else if (snake[j] == '#') {
idx = j;
break;
}
}
for (j = idx + 1; j < 200; j++) {
if (snake[j] == '=') {
count--;
} else if (snake[j] != '=') {
idx = j;
break;
}
}
if (count == 0) {
if (snake[idx] == '~' && snake[idx + 1] == '\0')
return (1);
else
return (0);
} else {
return (0);
}
}
int B_snake(char snake[]) {
int j, idx, count = 0;
char *str;
str = &snake[2];
for (j = 2; j < 200; j += 2) {
if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++;
if (!(strncmp(str, "~~", 2))) {
idx = j;
break;
}
str += 2;
}
if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) {
if (snake[idx + 2] == '\0') {
return (1);
} else {
return (0);
}
} else
return (0);
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | package Snakes;
import java.io.*;
import java.util.regex.Pattern;
public class Main {
Pattern a = Pattern.compile(">\\'(=+)#\\1~");
Pattern b = Pattern.compile(">\\^(Q=)+~~");
public static void main(String[] args) throws Exception {
Main me = new Main();
BufferedReader bfr = new BufferedReader(
new InputStreamReader(System.in));
int num = Integer.parseInt(bfr.readLine());
String res;
for (int i = 0; i < num; i++) {
res = me.judge(bfr.readLine());
System.out.println(res);
}
}
private String judge(String str) {
String res;
if (a.matcher(str).matches()) {
res = "A";
} else if (b.matcher(str).matches()) {
res = "B";
} else {
res = "NA";
}
return res;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
int num;
int i, j, k, l;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
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;
}
}
for (k = j; k < i; k++) {
if (snake[k] == '=') {
midcnt++;
} else if (snake[k] == '~') {
endacnt++;
if (endacnt == 2) {
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] == '~') {
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;
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) {
return 0;
}
S = S.substr(2, sz - 3);
sz = S.size();
if (S.find_first_not_of("#=", 0) != string::npos) {
return 0;
}
auto pos = S.find("#");
if (S.find("#", pos + 1) != string::npos) {
return 0;
}
if (S[sz / 2] != '#' || sz % 2 == 0) {
return 0;
}
return 1;
}
bool check_B(string &S) {
auto sz = S.size();
if ((S.find(">^Q=") != 0 && S.find("~~") != sz - 2) || sz < 6) {
return 0;
}
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;
}
int main() {
int N;
cin >> N;
for (int i = 0; i < (N); i++) {
string S;
cin >> S;
string res{"NA"};
if (check_A(S)) {
res = "A";
}
if (check_B(S)) {
res = "B";
}
cout << res << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string ss;
string snakeA(string::iterator it) {
int count = 0;
for (; it != ss.end() && *it == '='; it++, count++)
;
if (it == ss.end() || *it != '#') return "NA";
it++;
for (; it != ss.end() && *it == '='; it++, count--)
;
if (it == ss.end() || *it != '~') return "NA";
it++;
if (*it || count) return "NA";
return "A";
}
string snakeB(string::iterator it) {
while (true) {
if (it == ss.end() || *it++ != 'Q') return "NA";
if (it == ss.end() || *it++ != '=') return "NA";
if (it == ss.end()) return "NA";
if (*it == '~') break;
}
if (*++it == '~' && !*++it) return "B";
return "NA";
}
string snake(string ss) {
string::iterator it = ss.begin();
if (*it++ != '>') return "NA";
if (*it == '\'')
return snakeA(++it);
else if (*it == '^')
return snakeB(++it);
else
return "NA";
}
int main() {
int n;
for (cin >> n, cin.ignore(); n--;) {
getline(cin, ss);
cout << snake(ss) << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string vbString(int Number, string Character) {
string res = "";
for (int i = 0; i < Number; i++) res += Character;
return res;
}
string checksnake(string s) {
string t;
for (int i = 1; i < 60; i++) {
t = ">'" + vbString(i, "=") + "#" + vbString(i, "=") + "~";
if (t == s) return "A";
}
for (int i = 1; i < 60; i++) {
t = ">^" + vbString(i, "Q=") + "~~";
if (t == s) return "B";
}
return "NA";
}
int main() {
string s;
int n, i = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> s;
cout << checksnake(s) << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
char snake[200];
int num;
int i, j, k, l;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endcnt = 0;
int nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
break;
}
}
if (snake[0] == '>') {
if (snake[1] == '\'') {
for (j = 2; j < i; j++) {
if (snake[j] == '=') {
bodyacnt++;
} else if (snake[j] == '#') {
break;
}
}
for (k = j; k < i; k++) {
if (snake[k] == '=') {
midcnt++;
} else if (snake[k] == '~') {
endcnt++;
if (endcnt == 1) {
break;
}
}
}
} else if (snake[1] == '^') {
for (j = 2; j < i / 2; j += 2) {
if (snake[j] == 'Q' && snake[j + 1] == '=') {
bodybcnt++;
} else if (snake[i] == !'Q' && snake[i] != '=' && snake[i] != '~')
nacnt++;
}
if (snake[i - 2] == '~' && snake[i - 1] == '~') {
endcnt++;
}
}
}
if (bodybcnt > 0 && endcnt == 1 && nacnt == 0) {
printf("B\n");
} else if (bodyacnt == midcnt && endcnt == 1 && nacnt == 0) {
printf("A\n");
} else if (l != 0)
printf("NA\n");
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
string s;
int n;
cin >> n;
while (n--) {
cin >> s;
if (s[1] == '\'') {
int cnt1 = 0;
int i;
for (i = 2; s[i] == '='; i++) {
cnt1++;
}
if (s[i] != '#') {
cout << "NA" << endl;
goto skip;
} else
i++;
int cnt2 = 0;
for (; s[i] == '='; i++) {
cnt2++;
}
if (cnt1 == cnt2 && s[i] == '~')
cout << "A" << endl;
else
cout << "NA" << endl;
} else if (s[1] == '^') {
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 | 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());
for (int i = 0; i < n; i++)
{
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[] arr = temp.Split('#');
List<int> idx = new List<int>();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] != "") idx.Add(i);
}
if (idx.Count != 2) return NA;
if (arr[idx[0]].Length != arr[idx[1]].Length) return NA;
if (!arr[idx[0]].All(n => n == '=')) return NA;
if (!arr[idx[1]].All(n => n == '=')) return NA;
return "A";
}
static string CheckB(string s)
{
string tale = s.Substring(s.Length - 2, 2);
if (tale != "~~") return NA;
string temp = s.Substring(2, s.Length - 4);
temp = temp.Replace("Q=", "");
if (temp.Length != 0) return NA;
return "B";
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | # -*- coding: utf-8 -*-
import sys
import os
import math
N = int(input())
def is_A(s):
if s[0:2] != ">'":
return False
if s[-1] != '~':
return False
body = s[2:-1]
if len(body) % 2 == 0:
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int i, eq1, eq2;
string ret = "NA";
string s;
cin >> s;
if (s.length() > 100)
while (1)
;
if (s.substr(0, 3) == ">'=") {
i = 2;
eq1 = 0;
while (s[i] == '=' && i < s.length()) i++, eq1++;
if (s[i] != '#') goto label;
i++;
eq2 = 0;
while (s[i] == '=' && i < s.length()) i++, eq2++;
if (i == s.length() - 1 && s[i] == '~' && eq1 == eq2) ret = "A";
} else if (s.substr(0, 4) == ">^Q=") {
for (i = 2; i + 1 < s.length() - 2; i += 2) {
if (s[i] == 'Q' && s[i + 1] == '=') {
} else
goto label;
}
if (s[s.length() - 1] == '~' && s[s.length() - 2] == '~' &&
s[s.length() - 3] == '=' && s[s.length() - 4] == 'Q')
ret = "B";
}
label:;
cout << ret << 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() {
char data[110];
int i, j, n, p, l, t, temp, a, b, temp1;
scanf("%d", &n);
getchar();
for (t = 0; t < n; t++) {
for (j = 0; j < 101; j++) {
scanf("%c", &data[j]);
if (data[j] == '\n') {
data[j] = '\0';
l = j;
break;
}
}
a = 0;
b = 0;
if (l > 5) {
if (data[0] == '>' && data[1] == '\'' && data[2] == '=') {
i = 3;
while (data[i] == '=') {
i++;
}
if (data[i] == '#') {
temp = 1;
temp1 = i - 2;
i++;
for (j = 0; j < temp1; j++, i++) {
if (data[i] != '=') temp = 0;
}
if (temp == 1 && data[i] == '~') a = 1;
}
} else if (data[0] == '>' && data[1] == '^' && data[2] == 'Q' &&
data[3] == '=') {
temp = 1;
for (i = 4; i + 3 < l; i += 2) {
if (data[i] != 'Q' || data[i + 1] != '=') temp = 0;
}
if (temp == 1 && data[i] == '~' && data[i + 1] == '~') b = 1;
}
}
if (a == 1)
printf("A\n");
else if (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 | cpp | #include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
int main(void) {
int n;
while (n--) {
string snake;
cin >> snake;
if (snake[0] == '>' && snake[1] == '\'' && snake[snake.size() - 1] == '~') {
int count = 0;
int end;
for (int i = 2; i < snake.size() && snake[i] == '='; i++) {
count++;
end = i;
}
end++;
if (count && snake[end] == '#' && end + count + 2 == snake.size()) {
bool yes = true;
for (int i = end + 1; i < snake.size() - 1; i++) {
if (snake[i] != '=') yes = false;
}
if (yes) {
cout << "A" << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
} else if (snake[0] == '>' && snake[1] == '^' &&
snake[snake.size() - 1] == '~' &&
snake[snake.size() - 2] == '~') {
bool yes = true;
for (int i = 2; i < snake.size() - 2; i++) {
if (i % 2 == 0 && snake[i] != 'Q') yes = false;
if (i % 2 == 1 && snake[i] != '=') yes = false;
}
if (yes) {
cout << "B" << endl;
} else {
cout << "NA" << endl;
}
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
char data[110];
int a, b, i, n, c, j, len, temp, p = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
a = b = 0;
if (scanf("%s", data) == EOF) p = 1;
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");
if (p == 1) 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;
string vbString(int Number, string Character) {
string res = "";
for (int i = 0; i < Number; i++) res += Character;
return res;
}
string checksnake(string s) {
string t;
for (int i = 1; i < 60; i++) {
t = ">\'" + vbString(i, "=") + "#" + vbString(i, "=") + "~";
if (t == s) return "A";
}
for (int i = 1; i < 60; i++) {
t = ">^" + vbString(i, "Q=") + "~~";
if (t == s) return "B";
}
return "NA";
}
int main() {
string s;
int n, i = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> s;
cout << checksnake(s) << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
const double EPS = 1e-12;
const double PI = acos(-1.0);
int main() {
int n;
cin >> n;
for (int i = (0); i <= ((n)-1); ++i) {
string s;
cin >> s;
string h = s.substr(0, 2);
if (h == ">'") {
s += "!";
if (s.find('#') != string::npos) {
int pos = s.find('#');
int size = pos - 2;
for (int i = (0); i <= ((pos - 2) - 1); ++i) {
if (s[i + 2] == s[i + pos + 1] && s[i + 2] == '=') {
} else {
cout << "NA" << endl;
goto next;
}
}
if (s[pos + size + 1] == '~' && s[pos + size + 2] == '!') {
cout << "A" << endl;
goto next;
} else {
cout << "NA" << endl;
goto next;
}
} else {
cout << "NA" << endl;
goto next;
}
} else if (h == ">^") {
s += "!!";
int b = 2;
bool flag = false;
while (s.substr(b, 2) == "Q=") {
b += 2;
flag = true;
}
if (s.substr(b, 2) == "~~" && s.substr(b + 2, 2) == "!!" && flag) {
cout << "B" << endl;
goto next;
} else {
cout << "NA" << endl;
goto next;
}
} else {
cout << "NA" << endl;
goto next;
}
next:;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string in;
int isA() {
if (in.length() < 5) return 0;
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.length() < 5) return 0;
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;
string S;
int n;
string solve(string T) {
int chain = 0, ok = 0;
if (T.size() >= 3) {
if (T[T.size() - 1] == '~') {
if (T.substr(0, 2) == ">'") {
for (int i = 2; i < T.size() - 1; i++) {
if (T[i] == '#') {
ok++;
} else {
if (ok == 0) {
chain++;
} else {
chain--;
}
}
}
if (ok == 1 && chain == 0) {
return "A";
}
}
if (T.substr(0, 2) == ">^" && T[T.size() - 2] == '~') {
for (int i = 2; i < T.size() - 2; i += 2) {
if (T.substr(i, 2) != "Q=") {
goto E;
}
}
return "B";
E:;
}
}
}
return "NA";
}
int main() {
cin >> n;
for (int h = 0; h < n; h++) {
cin >> S;
cout << solve(S) << endl;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
const string species[] = {"A", "B", "NA"};
string str = "";
int n;
while (getline(cin, str)) {
stringstream ssn(str);
ssn >> n;
if (n == 0) {
break;
}
int i, j;
for (i = 0; i < n; ++i) {
string res = species[2];
getline(cin, str);
if (str.empty()) {
break;
}
int len = str.length();
if (str[0] == '>') {
if (str[1] == '\'') {
res = species[0];
} else if (str[1] == '^') {
res = species[1];
} else {
res = species[2];
}
}
if (res == species[0] || res == species[1]) {
if (res == species[0]) {
int prev = 0;
int after = 0;
int mid = 0;
bool flag = false;
for (j = 2; j < len - 1; ++j) {
if (str[j] == '=') {
if (!flag) {
++prev;
} else {
++after;
}
continue;
} else if (str[j] == '#') {
flag = true;
++mid;
continue;
} else {
break;
}
}
if (j == len - 1) {
if (str[j] == '~' && flag && mid == 1 && prev != 0 && after != 0 &&
prev == after) {
res = species[0];
} else {
res = species[2];
}
} else {
res = species[2];
}
} else {
for (j = 2; j < len - 2; j += 2) {
if (str[j] == 'Q' && str[j + 1] == '=') {
continue;
} else {
break;
}
}
if (j == len - 2 && str[j] == '~' && str[j + 1] == '~') {
res = species[1];
} else {
res = species[2];
}
}
}
cout << res << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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] == '^') {
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 | gets.to_i.times do
s = gets.chomp
if s =~ /^>'(=+)#\1~$/
puts ?A
elsif s =~ /^>^(Q=)+(?:.*)~$/
puts ?B
else
puts 'NA'
end
end |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
} 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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, j, fa, fb, acount, acount2, i;
string data;
cin >> n;
getline(cin, data);
for (j = 0; j < n; j++) {
fa = 0;
fb = 0;
acount = acount2 = 0;
getline(cin, data);
if (data[0] == '>' && data[1] == '\'') {
fa = 1;
i = 2;
while (data[i] == '=') {
acount++;
i++;
}
if (data[i] != '#') fa = 0;
i++;
while (data[i] == '=') {
acount2++;
i++;
}
if (i != data.length() - 1) fa = 0;
if (acount != acount2) fa = 0;
if (data[data.length() - 1] != '~') {
fa = 0;
}
}
if (data[0] == '>' && data[1] == '^') {
fb = 1;
for (i = 2; i < data.length() - 3; i = i + 2) {
if (data[i] != 'Q' || data[i + 1] != '=') fb = 0;
}
if (i != data.length() - 2) fb = 0;
if (data[data.length() - 1] != '~' || data[data.length() - 2] != '~')
fb = 0;
}
if (fa == 1)
cout << "A" << endl;
else if (fb == 1)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int Tc;
string s;
while (cin >> Tc) {
while (Tc--) {
cin >> s;
int const N = s.size();
bool NA = 0;
bool isA;
if (s[0] != '>') NA = 1;
if (s[1] == '\'') {
for (int i = 2; i < (N - 3) / 2 + 2; i++)
if (s[i] != '=') NA = 1;
if (s.substr(2, (N - 3) / 2) + "~" != s.substr(3 + (N - 3) / 2)) NA = 1;
if (s[(N - 3) / 2 + 2] != '#') NA = 1;
isA = 1;
} else if (s[1] == '^') {
if (!(s[2] == 'Q' && s[3] == '=')) NA = 1;
int cnt;
for (cnt = 2; cnt < N - 2; cnt += 2) {
if (!(s[cnt] == 'Q' && s[cnt + 1] == '=')) NA = 1;
}
if (!(s[cnt] == '~' && s[cnt + 1] == '~')) NA = 1;
isA = 0;
} else {
NA = 1;
}
if (NA)
cout << "NA" << endl;
else if (isA)
cout << "A" << endl;
else
cout << "B" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | def is_a?(s)
s =~ />[^=]*(=+)#(=+)~$/
unless $1 == nil || $2 == nil
return s && $1.size == $2.size
end
false
end
def is_b?(s)
s =~ />\^(Q=)+~~$/
end
n = gets.chomp.to_i
n.times do
s = gets.chomp
if is_a?(s)
puts :A
elsif is_b?(s)
puts :B
else
puts :NA
end
end |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
int f1 = 0, f2 = 0, k = -1;
bool f;
for (int i = 0; i < s.size(); i++)
if (s[i] == '>') k = i;
if (k == -1) {
printf("NA\n");
continue;
}
if (s[k + 1] == '^') {
f = false;
for (int i = k; i < s.size() - 1; i++)
if (s[i] == 'Q' && s[i + 1] == '=') f = true;
if (f && s[s.size() - 1] == '~' && s[s.size() - 2] == '~') {
printf("B\n");
continue;
}
}
int cnt = 0;
for (int i = k; i < s.size(); i++) {
if (s[i] == '=') {
while (s[i] == '=') {
cnt++;
i++;
}
k = i;
break;
}
}
f = false;
for (int i = k; i < s.size(); i++) {
if (s[i] == '#') {
k = i;
f = true;
}
}
if (f) {
for (int i = k; i < s.size(); i++) {
if (s[i] == '=') {
while (s[i] == '=') {
cnt--;
i++;
}
break;
}
}
if (cnt == 0 && s[s.size() - 1] == '~') {
printf("A\n");
continue;
}
}
printf("NA\n");
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
int n;
string s;
cin >> n;
rep(i, n) {
cin >> s;
string ans;
if (s[0] == '>'&&s[s.size() - 1] == '~') {
if (s[1] == '\'') {
ans = "A";
for (int i = 2; i < s.size() - 1) {
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 | UNKNOWN | #include <bits/stdc++.h>
int main() {
int num;
int i, j, k, l;
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
bodyacnt = 0;
bodybcnt = 0;
midcnt = 0;
endacnt = 0;
endbcnt = 0;
nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
break;
}
}
if (snake[0] == '>') {
if (snake[1] == '\'' && i % 2 == 0) {
for (j = 2; j < i / 2 + 1; j++) {
if (snake[j] == '=') {
bodyacnt++;
} else if (snake[j] == '#') {
break;
}
}
for (k = j; k < i - 1; k++) {
if (snake[k] == '=') {
midcnt++;
}
}
if (snake[i - 1] == '~' && snake[i - 2] != '~') {
endacnt++;
}
} else if (snake[1] == '^' && i % 2 == 0) {
for (j = 2; j < i - 3; j += 2) {
if (snake[j] == 'Q' && snake[j + 1] == '=') {
bodybcnt++;
} else
nacnt = 1;
}
if (snake[i - 2] == '~' && snake[i - 1] == '~' && snake[i - 3] != '~') {
endbcnt++;
}
}
}
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;
static const double eps = 10e-9;
bool isA(string str) {
if (str.size() >= 1 && str[0] != '>') return false;
if (str.size() >= 2 && 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.size() >= 1 && str[0] != '>') return false;
if (str.size() >= 2 && str[1] != '^') return false;
if (str.size() <= 3) return false;
string rear = str.substr(2, str.size() - 2);
bool isok = false;
int i;
for (i = 0; i + 1 < rear.size();) {
if (rear.substr(i, 2) == "Q=") {
isok = true;
i += 2;
} else
break;
}
return (i + 2 == rear.size() && isok && rear.substr(i, 2) == "~~");
}
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) {
string str;
cin >> str;
if (isA(str))
cout << "A" << endl;
else if (isB(str))
cout << "B" << endl;
else
cout << "NA" << endl;
}
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
bool snakeA(const string &s) {
auto it = begin(s);
int cnt = 0;
if (*it++ != '>') return false;
if (*it++ != '\'') return false;
while (true) {
const char c = *it++;
if (c == '#')
break;
else if (c == '=')
++cnt;
else
return false;
}
while (cnt--) {
if (*it++ != '=') return false;
}
if (*it++ != '~') return false;
return it == end(s);
}
bool snakeB(const string &s) {
auto it = begin(s);
if (*it++ != '>') return false;
if (*it++ != '^') return false;
while (true) {
const char c = *it++;
if (c == '~')
break;
else if (c != 'Q')
return false;
if (*it++ != '=') return false;
}
if (*it++ != '~') return false;
return it == end(s);
}
bool solve(bool first) {
string s;
cin >> s;
if (snakeA(s))
cout << "A" << endl;
else if (snakeB(s))
cout << "B" << endl;
else
cout << "NA" << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(2);
bool first = true;
int N;
cin >> N;
while (N-- && solve(first)) {
first = false;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int D = 0; D < n; ++D) {
string s;
cin >> s;
if (s.compare(0, 2, ">'") == 0) {
int bef_eq = 0;
int aft_eq = 0;
int pos_shp = 0;
int pos_tld = 0;
for (int i = 2; i < s.length(); ++i) {
switch (s[i]) {
case '=':
if (pos_shp == 0)
++bef_eq;
else
++aft_eq;
break;
case '#':
pos_shp = i;
break;
case '~':
pos_tld = i;
break;
}
}
if (bef_eq && aft_eq && pos_shp && bef_eq == aft_eq &&
pos_tld == s.length() - 1)
cout << "A\n";
else
cout << "NA\n";
} else if (s.compare(0, 2, ">^") == 0) {
int cnt_qeq = 0;
bool invalid = false;
if (s.length() <= 2 || s.length() % 2 == 1) invalid = true;
for (int i = 2; i < s.length() && !invalid; i += 2) {
if (s.compare(i, 2, "Q=") == 0)
++cnt_qeq;
else if (s.compare(i, 2, "~~") == 0 && i == s.length() - 2)
break;
else
invalid = true;
}
if (invalid)
cout << "NA\n";
else
cout << "B\n";
} else {
cout << "NA\n";
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import Control.Monad
main :: IO ()
main = do
n <- readLn
ls <- replicateM n getLine
mapM_ putStrLn $ solve ls
solve :: [String] -> [String]
solve = map check
where
check :: String -> String
check (x:y:r)
| x /= '>' = "NA"
| y == '\'' = checkA r
| y == '^' = checkB r
| otherwise = "NA"
where
checkA :: String -> String
checkA s
| s == [] = "NA"
| last s /= '~' = "NA"
| filter ('=' /=) s /= "#~" = "NA"
| reverse s' == s' = "A"
| otherwise = "NA"
where s' = init s
checkB :: String -> String
checkB s
| s == [] = "NA"
| (last s /= '~') || ((last . init $ s) /= '~') = "NA"
| checkB2 (init (init s)) = "B"
| otherwise = "NA"
where
checkB2 :: String -> Bool
checkB2 [] = True
checkB2 [x] = False
checkB2 (x:y:r) = (x == 'Q') && (y == '=') && (checkB2 r) |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
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 (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 | import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Text.Parsec
import Text.Parsec.String
import Test.HUnit
main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
n <- getl toInt
xs <- replicateM n getLine
mapM_ putStrLn $ solve xs
solve :: [String] -> [String]
solve = map snake
snake :: String -> String
snake s
| a = "A"
| b = "B"
| otherwise = "NA"
where
a = either (\_ -> False) id (parse snakeA "" s)
b = either (\_ -> False) id (parse snakeB "" s)
snakeA :: Parser Bool
snakeA = do
string ">'"
a <- many1 (char '=')
char '#'
b <- many1 (char '=')
char '~'
return $ length a == length b
snakeB :: Parser Bool
snakeB = do
string ">^"
many1 (string "Q=")
string "~~"
return True
toInt :: String -> Int
toInt s = read s
getl :: (String -> a) -> IO a
getl f = f <$> getLine
tests :: [Test]
tests = [
"test1" ~: Right True ~=? parse snakeA "" ">'======#======~",
"test2" ~: Right False ~=? parse snakeA "" ">'======#=====~",
"test3" ~: False ~=? either (\_ -> False) id (parse snakeA "" ">^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~"),
"test4" ~: Right True ~=? parse snakeB "" ">^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~",
"test5" ~: False ~=? either (\_ -> False) id (parse snakeB "" ">^Q=Q=Q=Q=Q=Q=Q=Q=Q=~"),
"test6" ~: "A" ~=? snake ">'======#======~",
"test7" ~: "B" ~=? snake ">^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~",
"test8" ~: "NA" ~=? snake ">'===#====~"
] |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <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";
} 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 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] == '#') 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;
}
}
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;
void solve() {
int n;
cin >> n;
while (n--) {
string str;
cin >> str;
if (str[0] == '>' && str[1] == '\'' && str[str.size() - 1] == '~') {
int count[2] = {0, 0};
int pos = 0;
for (int i = 2; i < str.size(); ++i) {
if (str[i] == '=') {
count[pos]++;
} else if (str[i] == '#') {
pos++;
}
}
if (count[0] == count[1]) {
cout << "A" << endl;
} else {
cout << "NA" << endl;
}
} else if (str[0] == '>' && str[1] == '^' && str[str.size() - 2] == '~' &&
str[str.size() - 1] == '~') {
for (int i = 2; i < str.size() - 1; ++i) {
if (str[i] == 'Q' && str[i + 1] == '=') {
cout << "B" << endl;
goto NEXT;
}
}
cout << "NA" << endl;
} else {
cout << "NA" << endl;
}
NEXT:;
}
}
int main() {
solve();
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
while (n--) {
string snake;
cin >> snake;
if (snake.size() < 4) {
cout << "NA" << endl;
} else if (snake[0] == '>' && snake[1] == '\'' &&
snake[snake.size() - 1] == '~') {
bool first = true;
int count1 = 0;
int count2 = 0;
for (int i = 2; i < snake.size() - 1; ++i) {
if (snake[i] == '=') {
if (first) {
++count1;
} else {
++count2;
}
} else if (snake[i] == '#') {
first = false;
}
}
if (count1 == count2 && count1 >= 1) {
cout << "A" << endl;
} else {
cout << "NA" << endl;
}
} else if (snake[0] == '>' && snake[1] == '^' &&
snake[snake.size() - 2] == '~' &&
snake[snake.size() - 1] == '~') {
bool flag = true;
int count = 0;
for (int i = 2; i < snake.size() - 2; i += 2) {
if (snake[i] != 'Q' || snake[i + 1] != '=') {
flag = false;
break;
}
if (snake[i] == 'Q' && snake[i + 1] == '=') {
++count;
}
}
if (flag && count) {
cout << "B" << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
}
}
int main() {
solve();
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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() - 1 - 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 | #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;
scanf("%s", data);
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int Tc;
string s;
while (cin >> Tc) {
while (Tc--) {
cin >> s;
int const N = s.size();
bool NA = 0;
bool isA;
if (s[0] != '>') NA = 1;
if (s[1] == '\'') {
if (s.substr(2, (N - 3) / 2) + "~" != s.substr(3 + (N - 3) / 2)) NA = 1;
if (s[(N - 3) / 2 + 2] != '#') NA = 1;
isA = 1;
} else if (s[1] == '^') {
if (!(s[2] == 'Q' && s[3] == '=')) NA = 1;
int cnt;
for (cnt = 2; cnt < N - 2; cnt += 2) {
if (!(s[cnt] == 'Q' && s[cnt + 1] == '=')) NA = 1;
}
if (!(s[cnt] == '~' && s[cnt + 1] == '~')) NA = 1;
isA = 0;
} else {
NA = 1;
}
if (NA)
cout << "NA" << endl;
else if (isA)
cout << "A" << endl;
else
cout << "B" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string vbString(int Number, string Character) {
string res = "";
for (int i = 0; i < Number; i++) res += Character;
return res;
}
string checksnake(string s) {
string t;
for (int i = 1; i < 600; i++) {
t = ">'" + vbString(i, "=") + "#" + vbString(i, "=") + "~";
if (t == s) return "A";
}
for (int i = 1; i < 600; i++) {
t = ">^" + vbString(i, "Q=") + "~~";
if (t == s) return "B";
}
return "NA";
}
int main() {
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
cout << checksnake(s) << endl;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string snake;
cin >> snake;
string s = snake.substr(0, 2);
if (s != ">^" && s != ">\'") {
puts("NA");
continue;
}
if (s == ">\'") {
int a = 0;
int p = 2;
for (int i = 2; i < (int)snake.size(); i++, p++) {
if (snake[i] == '#') break;
a++;
}
int b = 0, q = p + 1;
p += 2;
for (int i = q; i < (int)snake.size(); i++, p++) {
if (snake[i] == '~') break;
b++;
}
if (a == b && p == (int)snake.size()) {
puts("A");
} else {
puts("NA");
}
} else {
bool ok = true;
int p = 0;
string ss = "";
for (int i = 2; i < (int)snake.size() - 2; i++, p++) {
ss += snake[i];
if (p == 1) {
p = -1;
if (ss != "Q=") {
ok = false;
break;
}
ss = "";
}
}
int len = (int)snake.size();
if (snake[len - 2] == '~' && snake[len - 1] == '~' && ok) {
puts("B");
} else {
puts("NA");
}
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n, i, c1, c2, f;
char s[201];
scanf("%d", &n);
while (n--) {
scanf("%s", s);
f = 0;
if (s[1] == '\'') {
c1 = c2 = 0;
for (i = 2; s[i] != '#'; i++) {
if (s[i] != '=') {
break;
}
c1++;
}
for (i++; s[i] != '~'; i++) {
if (s[i] != '=') {
break;
}
c2++;
}
if (c1 == c2 && s[i + 1] == '\0') {
f = 1;
}
if (f) {
puts("A");
} else {
puts("NA");
}
} else if (s[1] == '^') {
for (i = 2; s[i] != '~'; i = i + 2) {
if (!(s[i] == 'Q' && s[i + 1] == '=')) {
break;
}
}
if (s[i] == '~' && s[i + 1] == '~' && s[i + 2] == 0) {
f = 1;
}
if (f) {
puts("B");
} else {
puts("NA");
}
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int D = 0; D < n; ++D) {
string s;
cin >> s;
if (s.compare(0, 2, ">'") == 0) {
int bef_eq = 0;
int aft_eq = 0;
int shp = 0;
int pos_shp = 0;
int pos_tld = 0;
for (unsigned int i = 2; i < s.length() && pos_tld == 0; ++i) {
switch (s[i]) {
case '=':
if (shp == 0)
++bef_eq;
else
++aft_eq;
break;
case '#':
shp++;
break;
case '~':
pos_tld = i;
break;
default:
shp = 2;
break;
}
}
if (bef_eq && aft_eq && pos_tld && bef_eq == aft_eq && shp == 1)
cout << "A\n";
else
cout << "NA\n";
} else if (s.compare(0, 2, ">^") == 0) {
int cnt_qeq = 0;
int pos_tltl = 0;
bool invalid = false;
if (s.length() <= 2 || s.length() % 2 == 1) invalid = true;
for (unsigned int i = 2; i < s.length() && !invalid; i += 2) {
if (s.compare(i, 2, "Q=") == 0)
++cnt_qeq;
else if (s.compare(i, 2, "~~") == 0) {
pos_tltl = i;
break;
} else
invalid = true;
}
if (pos_tltl != s.length() - 2) {
invalid = true;
}
if (invalid)
cout << "NA\n";
else
cout << "B\n";
} else {
cout << "NA\n";
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int q = 0; q < n; q++) {
string str;
cin >> str;
if (str[0] != '>') {
cout << "NA" << endl;
continue;
} else if (str[1] != '\'' && str[1] != '^') {
cout << "NA" << endl;
continue;
}
int flg = 0, sum;
if (str[1] == '\'') {
int t = 0;
sum = 0;
for (int i = 2; i < str.size(); i++) {
if (str[i] == '=')
t++;
else if (str[i] == '#' && sum == 0)
sum = t, t = 0;
else if (str[i] == '~' && i == str.size() - 1 && sum == t)
flg = 1;
else
break;
}
}
if (str[1] == '^' && flg == 0) {
flg = 0;
for (int i = 2; i < str.size(); i++) {
if (i % 2 == 0 && str[i] != 'Q') break;
if (i % 2 == 1 && str[i] != '=') break;
if (str[str.size() - 2] == '~' && str[str.size() - 1] == '~' &&
i == str.size() - 3) {
flg = 2;
break;
}
}
}
if (flg == 0)
cout << "NA" << endl;
else if (flg == 1)
cout << "A" << endl;
else if (flg == 2)
cout << "B" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int max, num;
int total;
int i;
char snake[201];
scanf("%d", &max);
for (num = 0; num < max; num++) {
scanf("%s", snake);
if (strlen(snake) < 2 || snake[0] != '>') {
printf("NA\n");
continue;
}
if (snake[1] == '\'') {
total = 0;
i = 2;
while (snake[i] == '=') {
i++;
num++;
}
if (snake[i] != '#' || num <= 0)
printf("NA\n");
else {
i++;
while (snake[i] == '=') {
i++;
num--;
}
if (num != 0)
printf("NA\n");
else if (snake[i] != '~' || snake[i + 1] != 0)
printf("NA\n");
else
printf("A\n");
}
} else if (snake[1] == '^') {
i = 2;
while (snake[i] == 'Q' && snake[i + 1] == '=') i += 2;
if (i == 2)
printf("NA\n");
else if (snake[i] != '~' || snake[i + 1] != '~' || snake[i + 2] != 0)
printf("NA\n");
else
printf("B\n");
} else
printf("NA\n");
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
void printNA() { cout << "NA" << endl; }
void judgeB(string s) {
if (s.substr(s.size() - 2, 2) != "~~") {
printNA();
return;
}
for (int i = 2; i < s.size() - 3; i += 2) {
if (s.substr(i, 2) != "Q=") {
printNA();
return;
}
}
cout << "B" << endl;
}
void judgeA(string s) {
int len = 0;
int i;
for (i = 2; s[i] == '='; i++) {
len++;
}
if (len == 0 || s.size() < i || s[i] != '#') {
printNA();
return;
}
if (s.size() < 2 + 2 * len) {
printNA();
return;
}
for (i++; i <= 2 + 2 * len; i++) {
if (s[i] != '=') {
printNA();
return;
}
}
if (s.size() == i || s[i] != '~') {
printNA();
} else {
cout << "A" << endl;
}
}
int main() {
int n;
cin >> n;
for (int c = 0; c < n; c++) {
string s;
cin >> s;
if (s.substr(0, 2) == ">'") {
judgeA(s);
} else if (s.substr(0, 2) == ">^") {
judgeB(s);
} 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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args)throws IOException{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(isr);
StringBuilder source;
int n = Integer.valueOf(reader.readLine());
for(int i = 0; i < n; i++){
source = new StringBuilder(reader.readLine());
if(source.substring(0, 2).equals(">'")){
char ch[] = source.substring(2, source.length() - 1).toCharArray();
int flag = 0, count = 0;
for(char var : ch){
if(flag == 0 && var == '=') count++;
else if(flag == 1 && var == '=') count--;
else if(flag == 0 && var == '#') flag = 1;
else{
flag = 2;
break;
}
}
if(count != 0 || flag == 2) System.out.println("NA");
else System.out.println("A");
}else if(source.substring(0, 2).equals(">^")){
char ch[] = source.substring(2, source.length() - 2).toCharArray();
int flag = 1, currect = 0;
for(char var : ch){
if(flag != currect && var == 'Q'){
currect = 1;
}else if(flag != currect && var == '='){
currect = 0;
}else{
System.out.println("NA");
flag = 2;
break;
}
flag = flag == 1 ? 0 : 1;
}
if(flag != 2) System.out.println("B");
}else System.out.println("NA");
}
reader.close();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
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] == '~')
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] == '~') {
cout << "B" << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
for (int x = 0; x < n; ++x) {
string line;
cin >> line;
string sol = "NA";
if (line.find('#') != string::npos) {
bool flag = false;
string a = "";
string b = "";
for (int x = 2; x < line.size() - 1; ++x) {
if (line[x] == '#') {
flag = true;
continue;
}
if (!flag) {
a += line[x];
} else {
b += line[x];
}
}
if (line.size() > 3 && line[0] == '>' && line[1] == '\'' &&
line[line.size() - 1] == '~' && a == b)
sol = "A";
} else {
bool flag = true;
for (int x = 2; line.size() > 4 && x < (line.size() - 3); x += 2) {
if (line[x] != 'Q' || line[x + 1] != '=') flag = false;
}
if (line.size() > 4 && line[0] == '>' && line[1] == '^' &&
line[line.size() - 1] == '~' && line[line.size() - 2] == '~' && flag)
sol = "B";
}
cout << sol << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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 '\'':
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 '^':
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<iostream>
#include<string>
using namespace std;
int main(void){
string str;
int n;
cin>>n;
while(n--){
cin>>str;
int ca = 0;
int cntsha = 0;
bool a = true;
if(str.size()%2 == 0){
if(str[str.size() / 2] == '#')str[str.size()/2] = '=';
for(int i = 2 ; i < str.size() - 1 ; i ++){
if(str[i] != '='){
a = false;
break;
}
}
if(a)ca = 1;
}
if(ca != 1){
bool b = true;
for(int i = 2 ; i < str.size() - 2 ; i ++){
//cout<<str[i];
if(i%2){
if(str[i] != '='){
b = false;
//cout<<i<<endl;
break;
}
}else{
if(str[i] != 'Q'){
b = false;
//cout<<i<<endl;
break;
}
}
}
if(b){
ca = 2;
}
}
if(ca == 1){
cout<<"A"<<endl;
}else if(ca == 2){
cout<<"B"<<endl;
}else{
cout<<"NA"<<endl;
}
}
}
#include<iostream>
#include<string>
using namespace std;
int main(void){
string str;
int n;
cin>>n;
while(n--){
cin>>str;
int ca = 0;
int cntsha = 0;
bool a = true;
if(str.size()%2 == 0){
if(str[str.size() / 2] == '#')str[str.size()/2] = '=';
for(int i = 2 ; i < str.size() - 1 ; i ++){
if(str[i] != '='){
a = false;
break;
}
}
if(a)ca = 1;
}
if(ca != 1){
bool b = true;
for(int i = 2 ; i < str.size() - 2 ; i ++){
//cout<<str[i];
if(i%2){
if(str[i] != '='){
b = false;
//cout<<i<<endl;
break;
}
}else{
if(str[i] != 'Q'){
b = false;
//cout<<i<<endl;
break;
}
}
}
if(b){
ca = 2;
}
}
if(ca == 1){
cout<<"A"<<endl;
}else if(ca == 2){
cout<<"B"<<endl;
}else{
cout<<"NA"<<endl;
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
scanf("%s", data);
for (j = 0;; j++) {
if (data[j] == '\0') {
len = j;
break;
}
}
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 | cpp | #include <bits/stdc++.h>
const int INF = 10000000;
using namespace std;
int main() {
int n;
string s;
cin >> n;
for (int k = 0; k < (int)(n); k++) {
cin >> s;
if (s.length() < 2) {
cout << "NA" << endl;
goto end;
} else if (s[0] == '>' && s[1] == '\'') {
int num1 = 0, num2 = 0, i;
for (i = 2; i < s.length() - 1; i++) {
if (s[i] == '=')
num1++;
else if (s[i] == '#')
break;
else {
cout << "NA" << endl;
goto end;
}
}
for (; i < s.length() - 1; i++) {
if (s[i] == '=') num2++;
}
if (num1 == num2 && s[s.length() - 1] == '~') {
cout << "A" << endl;
} else {
cout << "NA" << endl;
goto end;
}
} else if (s[0] == '>' && s[1] == '^') {
bool f = true;
for (int i = 2; i < s.length() - 2; i++) {
if (i % 2 == 0 && s[i] != 'Q')
f = false;
else if (i % 2 == 1 && s[i] != '=')
f = false;
}
if (f && s[s.length() - 2] == '~' && s[s.length() - 1] == '~') {
cout << "B" << endl;
} else {
cout << "NA" << endl;
goto end;
}
}
end:;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(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 endcnt = 0;
int nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
break;
}
}
if (snake[0] == '>') {
if (snake[1] == '\'') {
for (j = 2; j < i; j++) {
if (snake[j] == '=') {
bodyacnt++;
} else if (snake[j] == '#') {
break;
}
}
for (k = j; k < i; k++) {
if (snake[k] == '=') {
midcnt++;
} else if (snake[k] == '~') {
endcnt++;
if (endcnt == 1) {
break;
}
}
}
} else if (snake[1] == '^') {
for (j = 2; j < i / 2; j += 2) {
if (snake[j] == 'Q' && snake[j + 1] == '=') {
bodybcnt++;
} else if (snake[i] == !'Q' && snake[i] != '=' && snake[i] != '~')
nacnt++;
}
if (snake[i - 2] == '~' && snake[i - 1] == '~') {
endcnt++;
}
} else
nacnt++;
}
if (bodybcnt > 0 && endcnt == 1 && nacnt == 0) {
printf("B\n");
} else if (bodyacnt == midcnt && endcnt == 1 && nacnt == 0) {
printf("A\n");
} else if (l != 0)
printf("NA\n");
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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] != '>') return 0;
if (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[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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int a = 0, b = 0, cnt[2] = {0, 0};
string in;
cin >> in;
for (int i = 0; i < in.size(); i++) {
if (a == 0 && in[i] == '>') a = 1;
if (a == 1 && in[i] == '=') cnt[0]++;
if (a == 1 && in[i] == '#') a = 2;
if (a == 2 && in[i] == '=') cnt[1]++;
if (a == 2 && in[i] == '~' && i == in.size() - 1) a = 3;
}
for (int i = 0; i < in.size(); i += 2) {
if (b == 0 && in[i] == '>' && in[i + 1] == '^') b = 1;
if (b == 1 && in[i] == 'Q' && in[i + 1] == '=') b = 2;
if (b == 2 && in[i] == '~' && in[i + 1] == '~' && i + 1 == in.size() - 1)
b = 3;
}
if (a == 3 && cnt[0] == cnt[1]) {
cout << "A" << endl;
} else if (b == 3) {
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;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
char snake[256] = {0};
int check(int len) {
if (len % 2 == 1) return 10000000;
if (snake[0] == '>') {
if (snake[1] == 39) {
if (snake[len - 1] != '~') return 10000000;
int cnt = 0;
int x = 0;
for (int i = 0; i < (len); ++i) {
if (snake[i] == '#') {
cnt++;
x = i;
}
}
if (cnt != 1) return 10000000;
for (int i = 2; i < x; ++i) {
if (snake[i] != '=') return 10000000;
}
for (int i = x + 1; i < len - 1; ++i) {
if (snake[i] != '=') return 10000000;
}
return (x - 2 == len - x - 2) ? 1 : 10000000;
} else if (snake[1] == '^') {
if (snake[len - 1] != '~' || snake[len - 2] != '~') return 10000000;
for (int i = 2; i < len - 2; i += 2) {
if (snake[i] != 'Q' || snake[i + 1] != '=') return 10000000;
}
return 0;
}
}
return 10000000;
}
int main() {
int n;
scanf("%d", &n);
for (int q = 0; q < (n); ++q) {
memset(snake, 0, sizeof(snake));
scanf("%s", snake);
int len = strlen(snake);
int res = check(len);
(res == 1) ? puts("A") : (res == 0) ? puts("B") : 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;
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 {
int a = 0, f = 0;
for (int i = 1; i < ss - 1; i++) {
if (s[i] == '=' && !f) a++;
if (s[i] == '#') f = 1;
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;
string vbString(int Number, string Character) {
string res = "";
for (int i = 0; i < Number; i++) res += Character;
return res;
}
string checksnake(string s) {
string t;
for (int i = 1; i < 60; i++) {
t = ">\'" + vbString(i, "=") + "#" + vbString(i, "=") + "~";
if (t == s) return "A";
}
for (int i = 1; i < 60; i++) {
t = ">^" + vbString(i, "Q=") + "~~";
if (t == s) return "B";
}
return "NA";
}
int main() {
string s;
int n, i = 0;
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
getline(cin, s);
cout << checksnake(s) << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main
{
public static void main(String arg[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
while(n-->0)
{
char ch[] = in.next().toCharArray();
if(ch.length<6)
{
System.out.println("NA");
continue;
}
int counta =0;
int countb =0;
boolean flag=false;
if(ch[0]=='>'&&ch[1]=='\'' &&ch[ch.length-1]=='~')
{
int co=2;
while(ch[co]!='#')
{
if(ch[co]=='=')
counta++;
co++;
if(co==ch.length-1)
break;
}
while(ch[co]!='~')
{
if(ch[co]=='=')
countb++;
co++;
}
if(counta==countb&&counta>0)
System.out.println("A");
else
System.out.println("NA");
continue;
}
else
if(ch[0]=='>'&&ch[1]=='^' &&ch[ch.length-1]=='~'&&ch[ch.length-2]=='~')
{
int co=2;
while(ch[co]!='~')
{
if(ch[co]=='Q'&&ch[co+1]=='=')
flag = true;
else
{
flag = false;
break;
}
co+=2;
}
}
System.out.println(flag==true ? "B":"NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, j;
cin >> N;
while (N--) {
int runcnt = 0, j;
char S[150];
cin >> S;
if (S[0] == '>' && S[1] == 39) {
int K = 0;
for (j = 2;; j++) {
if (S[j] == '=') {
runcnt++;
K = 1;
} else if (S[j] == '#') {
break;
} else {
cout << "NA" << endl;
break;
goto end;
}
}
for (int i = j + 1;; i++) {
if (S[i] == '=') {
runcnt--;
} else if (runcnt == 0 && S[i] == '~' && K == 1) {
cout << "A" << endl;
break;
} else {
cout << "NA" << endl;
break;
}
}
} else if (S[0] == '>' && S[1] == '^') {
int F = 0;
for (j = 2;;) {
if (S[j] == 'Q' && S[j + 1] == '=') {
j += 2;
F = 1;
} else if (S[j] == '~' && S[j + 1] == '~' && F == 1) {
cout << "B" << endl;
goto end;
} else {
cout << "NA" << endl;
break;
}
}
} else
cout << "NA" << endl;
end:;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static readonly string NA = "NA";
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
int n = int.Parse(Console.ReadLine());
while (n-- > 0)
{
string s = Console.ReadLine();
string head = s.Substring(0, 2);
switch (head)
{
case ">'":
sb.AppendLine(CheckA(s));
break;
case ">^":
sb.AppendLine(CheckB(s));
break;
default:
sb.AppendLine(NA);
break;
}
}
Console.Write(sb);
}
static string CheckA(string s)
{
if (s[s.Length - 1] != '~') return NA;
string temp = s.Substring(2, s.Length - 3);
string[] t = temp.Split('#');
if (t.Length != 2 || t[0].Length != t[1].Length) return NA;
for (int i = 0; i < t[0].Length; i++)
{
if (t[0][i] != '=') return NA;
if (t[1][i] != '=') return NA;
}
return "A";
}
static string CheckB(string s)
{
string tale = s.Substring(s.Length - 2, 2);
if (tale != "~~") return NA;
string temp = s.Substring(2, s.Length - 4);
temp = temp.Replace("Q=", "");
if (temp.Length != 0) return NA;
return "B";
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
for(int i = 0; i < n; i++){
char[] str = sc.nextLine().toCharArray();
boolean is_na = false;
boolean is_a = false;
if(str[0] == '>'){
if(str[1] == '\'' ){
int len = 0;
int count = 0;
boolean flag = false;
for(int j = 2; j < str.length; j++){
if(count == 0 && flag == true){
len = j;
break;
}
if(str[j] == '='){
count += flag ? -1 : 1;
}else if(str[j] == '#'){
flag = true;
}
}
if(len == str.length-1 && str[len] == '~'){
is_a = true;
}else{
is_na = true;
}
}else if(str[1] == '^'){
for(int j = 0; j < (str.length - 4)/2; j++){
if(str[j*2 + 2] != 'Q' || str[j*2 + 2 + 1] != '='){
is_na = true;
}
}
if(str[str.length -2] == '~' && str[str.length -1] == '~'){
is_a = false;
}
}else{
is_na = true;
}
}else{
is_na = true;
}
System.out.println(is_na ? "NA" : is_a ? "A" : "B");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int A_snake(char snake[]);
int B_snake(char snake[]);
int main(void) {
int quantity, i;
char snake[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");
}
}
}
return (0);
}
int A_snake(char snake[]) {
int j, idx = 0, count = 0;
for (j = 2; j < 199; j++) {
if (snake[j] == '=') {
count++;
} else if (snake[j] == '#') {
idx = j;
break;
}
}
for (j = idx + 1; j < 199; j++) {
if (snake[j] == '=') {
count--;
} else if (snake[j] != '=') {
idx = j;
break;
}
}
if (count == 0) {
if (snake[idx] == '~' && snake[idx + 1] == '\0')
return (1);
else
return (0);
} else {
return (0);
}
}
int B_snake(char snake[]) {
int j, idx, count = 0;
char *str;
str = &snake[2];
for (j = 2; j < 198; j += 2) {
if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++;
if (snake[j] == '~' && snake[j + 1] == '~') {
idx = j;
break;
}
str += 2;
}
if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) {
if (snake[idx + 2] == '\0') return (1);
} else
return (0);
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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() - 3; j += 2) {
if (str[j] == 'Q' && str[j + 1] != '=') {
b = false;
break;
}
}
if (str[str.size() - 2] != '~' || str[str.size() - 1] != '~') b = false;
}
if (a)
cout << "A" << endl;
else if (b)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
int num;
int i, j, k, l;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
break;
}
}
if (snake[0] == '>') {
if (snake[1] == '\'') {
for (j = 2; j < i; j++) {
if (snake[j] == '=') {
bodyacnt++;
} else if (snake[j] == '#') {
break;
}
}
for (k = j; k < i; k++) {
if (snake[k] == '=') {
midcnt++;
} else if (snake[k] == '~') {
endacnt++;
if (endacnt == 2) {
nacnt++;
}
}
}
} else 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;
int main() {
char buf[210];
int bi, n, eqc, ti;
cin >> n;
for (int i = 0; i < n; i++) {
bi = 0;
cin >> buf;
if (buf[bi++] != '>') {
cout << "NA" << endl;
continue;
}
if (buf[bi] == '\'') {
bi++;
eqc = 0;
while (buf[bi + eqc] == '=') eqc++;
if (buf[bi + eqc] != '#') {
cout << "NA" << endl;
continue;
}
bi += eqc + 1;
for (ti = 0; ti < eqc; ti++)
if (buf[bi + ti] != '=') break;
if (ti < eqc) {
cout << "NA" << endl;
continue;
}
bi += ti;
if (buf[bi] == '~' && buf[bi + 1] == '\0')
cout << "A" << endl;
else
cout << "NA" << endl;
} else if (buf[bi] == '^') {
bi++;
cout << "dbg " << buf[bi] << buf[bi + 1] << endl;
while (buf[bi] == 'Q' && buf[bi + 1] == '=') bi += 2;
cout << "dbg " << buf[bi] << buf[bi + 1] << endl;
if (buf[bi] == '~' && buf[bi + 1] == '~') {
if (buf[bi + 2] == '\0')
cout << "B" << endl;
else
cout << "NA" << endl;
} else
cout << "NA" << endl;
} else {
cout << "NA" << endl;
continue;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | t;short*p;Q(){for(;*p=='=Q';p++);}main(i,a,s){for(;~scanf("%[^\n]\n",s);i=0)i||puts(sscanf(s,">^%[Q=]~%c%c",a,&t,a)-2||t-'~'|(Q(p=a),*p&7|p==a)?sscanf(s,">'%[=]#%[=]%c%c",a,s,&t,a)-3||t-'~'|strcmp(a,s)?"NA":"A":"B");} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
bool check_A(string S) {
auto sz = S.size();
if (S.find(">'") == 0 && S.find("~") == sz - 1 && sz >= 6) {
S = S.substr(2, sz - 3);
sz = S.size();
if (S.find_first_not_of("#=", 0) != string::npos) {
return 0;
}
auto pos = S.find("#");
if (S.find("#", pos + 1) != string::npos) {
return 0;
}
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 | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
int num;
int i, j, k, l;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
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;
}
}
for (k = j; k < i; k++) {
if (snake[k] == '=') {
midcnt++;
} else if (snake[k] == '~') {
endacnt++;
if (endacnt == 2) {
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;
int solve(string &s) {
int t = -1;
if (s.length() < 3) return -1;
if (s.length() >= 3 && s.substr(0, 2) == ">'" &&
s[(int)s.length() - 1] == '~')
t = 0;
if (s.length() >= 4 && s.substr(0, 2) == ">^" &&
s.substr((int)s.length() - 2) == "~~")
t = 1;
if (t == -1) return -1;
if (t) {
for (int i = 2; i + 2 < s.length(); i += 2)
if (s.substr(i, 2) != "Q=") return -1;
return t;
} else {
int c1 = 0, c2 = 0, i = 2;
for (; i + 1 < s.length() && s[i] == '='; ++i) ++c1;
if (s[i++] != '#') return -1;
for (; i + 1 < s.length() && s[i] == '='; ++i) ++c2;
if (c1 != c2 || s[i] != '~' || i + 1 != (int)s.length()) return -1;
return t;
}
return -1;
}
int main() {
int T;
cin >> T;
for (int t = 0; t < (int)(T); ++t) {
string s;
cin >> s;
int ans = solve(s);
cout << (ans == 0 ? "A" : (ans == 1 ? "B" : "NA")) << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <algorithm>
using namespace std;
int main() {
int Tc; string s;
while(cin>>Tc) {
while(Tc--) {
cin >> s;
int const N = s.size();
bool NA = 0;
bool isA;
if(s[0] != '>') NA = 1;
if(s[1] == '\'') {
for(int i=2; i<(N-3)/2+2; i++) if(s[i]!='=') NA=1;
if(s.substr(2, (N-3)/2) + "~" != s.substr(3+(N-3)/2)) NA = 1;
if(s[(N-3)/2+2] != '#') NA = 1;
isA = 1;
}
else if(s[1] == '^') {
int cnt;
for(cnt=2; cnt<N-2; cnt+=2) {
if(!(s[cnt] == 'Q' && s[cnt+1] == '=')) NA = 1;
}
if(!(s[cnt] == '~' && s[cnt+1] == '~')) NA = 1;
if(cnt+2 != N) NA = 1
isA = 0;
}
else {
NA = 1;
}
if(NA) cout << "NA" << endl;
else if(isA) cout << "A" << endl;
else cout << "B" << endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
char data[101];
int a, b, i, n, c, j, len, temp;
scanf("%d", &n);
for (i = 0; i < n; i++) {
a = b = 0;
scanf("%s", data);
for (j = 0;; j++) {
if (data[j] == '\0') {
len = j;
break;
}
}
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 | #include <bits/stdc++.h>
int main(void) {
int quantity, i, j, idx, count = 0;
char snake[200] = {0};
scanf("%d", &quantity);
for (i = 0; i < quantity; i++) {
scanf("%s", snake);
if (snake[0] != '>') {
puts("NA");
break;
} else if (snake[1] == '\'') {
for (j = 2; j < 199; j++) {
if (snake[j] == '=') {
count++;
} else if (snake[j] == '#') {
idx = j;
break;
}
}
for (j = idx + 1; j < 199; j++) {
if (snake[j] != '=') {
idx = j;
break;
}
count--;
}
if (count == 0) {
if (snake[idx] == '~')
puts("A");
else
puts("NA");
} else {
puts("NA");
}
} else if (snake[1] == '^') {
for (j = 2; j < 198; j += 2) {
if (snake[j] == 'P') count++;
if (snake[j + 1] == '=') count--;
if (snake[j] == '~' && snake[j + 1] == '~') break;
}
if (count == 0) {
puts("B");
} else {
puts("NA");
}
}
}
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | 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=='='}
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 | 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;
while (s.size() - 1 - now >= 2) {
if (s.substr(now, 2) != "Q=") break;
now += 2;
}
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 | #include <stdio.h>
int main(int argc, const char * argv[])
{
int num;
int i, j, k, l;
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
snake[200] = {0};
bodyacnt = 0;
bodybcnt = 0;
midcnt = 0;
endacnt = 0;
endbcnt = 0;
nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
// 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 | python3 | n = int(input())
for i in range(n):
s = input()
if s[:2] == ">'" and s[-1] == '~' and len(s) % 2 == 0:
temp = ">'" + '=' * (s.count('=')//2) + '#' + '=' * (s.count('=')//2) + '~'
if s == temp:
print('A')
continue
elif s[:2] == ">^" and s[-2:] == '~~' and len(s) % 2 == 0:
temp = ">^" + 'Q=' * ((len(s)-4)//2) + '~~'
if s == temp:
print('B')
continue
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() {
int n, i, j;
char s[100001];
scanf("%d", &n);
while (n--) {
scanf("%s", s);
if (s[0] != '>') {
printf("NA");
continue;
}
if (s[1] == '\'') {
for (i = 3; s[i] == '='; i++)
;
for (j = 1; s[i - j] == '=' && s[i + j] == '='; j++)
;
if (i - j == 1 && s[i + j] == '~' && s[i + j + 1] == 0 && s[i] == '#' &&
i - 3)
printf("A\n");
else
printf("NA\n");
} else if (s[1] == '^') {
for (i = 2; s[i] == 'Q' && s[i + 1] == '='; i += 2)
;
if (s[i] == '~' && s[i + 1] == '~' && s[i + 2] == 0 && i - 2)
printf("B\n");
else
printf("NA\n");
} else
printf("NA\n");
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
} else 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;
} 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 <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]=='~'){//B種の調べ
for(t=2;t<=l-4;t=t+2){
if(input[t]=='Q'&&input[t+1]=='='){
gou++;
}
}
if(gou*2==l-4){
syucnt[i]=2;
}else syucnt[i]=3;
gou=0;
}else if(input[l/2]=='#'&&input[l-1]=='~'&&(l-4)%2==0){
int j=2;
for(t=0;t<(l-4)/2;t++){
if(input[j]=='='&&input[l-j]=='='){
gou++;
}
j++;
}
if(gou==((l-4)/2)){
syucnt[i]=1;
}else syucnt[i]=3;
gou=0;
}else syucnt[i]=3;
}
for(i=0;i<n;i++){//出力
if(syucnt[i]==1){
puts("A");
}else if(syucnt[i]==2){
puts("B");
}else if(syucnt[i]==3){
puts("NA");
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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[201];
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 | cpp | #include <iostream>
#define NA cout << "NA" << endl; goto LABEL
using namespace std;
int main() {
int snakeCount;
cin >> snakeCount;
for(int loopCount = 0; loopCount < snakeCount; loopCount++) {
char arr[201];
???in >> arr;
int i = 0;
if(arr[i]!='>') {
NA;
}
i++;
if(arr[i]=='\'') {
int equalCount = 0;
bool mode = false;
for(int j = i+1; j < 201; j++) {
if(arr[j]=='=') {
if(!mode) {
equalCount++;
}else {
equalCount--;
}
}else if(arr[j]=='#') {
if(!mode && equalCount>0) {
mode = !mode;
}else {
NA;
}
}else if(arr[j]=='~') {
if(arr[j+1]=='\0'&&equalCount==0&&mode) {
cout << "A" << endl;
goto LABEL;
}else {
NA;
}
}else {
NA;
}
}
}else if(arr[i]=='^') {
int count = 0;
for(int j = i+1; j < 201; j++) {
if(arr[j]=='Q'&&arr[j+1]=='=') {
j++;
count++;
continue;
}else if(arr[j]=='~'&&arr[j+1]=='~'&&arr[j+2]=='\0'&&count>0) {
cout<< "B" << endl;
goto LABEL;
}else {
NA;
}
}
}else {
NA;
}
LABEL:;
}
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 | # AOJ 0139 Snakes
# Python3 2018.6.19 bal4u
import re
# A >'======#======~
# B >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
pa = ">'(=*)#(=*)~$"
pb = ">\\^(Q=)+~~$"
for i in range(int(input())):
s = input()
r = re.match(pa, s)
if r and r.group(1) == r.group(2): print('A')
elif re.match(pb, s): print('B')
else: print('NA')
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
const double EPS = 1e-12;
const double PI = acos(-1.0);
int main() {
int n;
cin >> n;
for (int i = (0); i <= ((n)-1); ++i) {
string s;
cin >> s;
string h = s.substr(0, 2);
if (h == ">'") {
s += "!";
if (s.find('#') != string::npos) {
int pos = s.find('#');
int size = pos - 2;
for (int i = (0); i <= ((pos - 2) - 1); ++i) {
if (s[i + 2] == s[i + pos + 1] && s[i + 2] == '=') {
} else {
cout << "NA" << endl;
goto next;
}
}
if (s[pos + size + 1] == '~' && s[pos + size + 1] == '!') {
cout << "A" << endl;
goto next;
} else {
cout << "NA" << endl;
goto next;
}
} else {
cout << "NA" << endl;
goto next;
}
} else if (h == ">^") {
s += "!!";
int b = 2;
while (s.substr(b, 2) == "Q=") {
b += 2;
}
if (s.substr(b, 2) == "~~" && s.substr(b + 2, 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;
string s;
cin >> n;
for (int u = 0; u < n; u++) {
cin >> s;
bool a = true, b = true;
if (!(s[0] == '>' && s[1] == '\'' && s[s.size() - 1] == '~' &&
s[s.size() / 2] == '#' && s.size() % 2 == 0))
a = false;
if (!(s[0] == '>' && s[1] == '^' && s[s.size() - 2] == '~' &&
s[s.size() - 1] == '~' && s.size() % 2 == 0))
b = false;
if (a) {
for (int i = 2; i < s.size() - 1; i++) {
if (i != s.size() / 2 && s[i] != '=') a = false;
}
}
if (b) {
for (int i = 2; i < s.size() - 2; i++) {
if ((i % 2 == 0 && s[i] != 'Q') || (i % 2 == 1 && s[i] != '='))
b = false;
}
}
if (a) cout << "A" << endl;
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 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);
bool f = true;
for (int j = 0; j < ss.size(); j++) {
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 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;
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;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python2 | import re
def A(s):
if s.count('#') != 1 or s[-1] != '~':
return False
a, b = s[:-1].split('#')
return a.count('=') == b.count('=') == len(a)
def B(s):
return re.match('^(Q=)+~~$', s)
N = input()
for i in range(N):
s = raw_input()
a = 'NA'
if s.startswith(">'"):
if A(s[2:]):
a = 'A'
if s.startswith('>^'):
if B(s[2:]):
a = 'B'
print(a) |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string get_str(int c, string s) {
string ret = "";
for (int i = 0; i < c; i++) ret += s;
return ret;
}
string check(string s) {
string t;
for (int i = 1; i < 60; i++) {
t = ">\'" + get_str(i, "=") + "#" + get_str(i, "=") + "~";
if (s == t) return "A";
}
for (int i = 1; i < 60; i++) {
t = ">^" + get_str(i, "Q=") + "~~";
if (s == t) return "B";
}
return "NA";
}
int main() {
int n;
string snake;
cin >> n;
while (n--) {
char c;
cin >> snake;
cout << check(snake) << 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 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;
for (ind = 0; ind < str.length(); ind += 2) {
if (!(str[ind] == '>' && str[ind + 1] == '\'')) break;
}
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] == '~')
cout << "A" << endl;
else {
cout << "NA" << endl;
}
} else if (str[0] == '>' && str[1] == '^') {
int ind;
for (ind = 0; ind < str.length(); ind += 2) {
if (!(str[ind] == '>' && str[ind + 1] == '^')) break;
}
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] == '~') {
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;
char str_input[110] = {NULL};
void f_syokika();
int f_A(int);
bool f_B();
const char str_A[] = ">'=#~";
const char str_B[] = ">^Q=~~";
int main(void) {
int n = 0;
cin >> n;
for (int i = 0; i < n; i++) {
f_syokika();
cin >> str_input;
bool flag_A = false;
bool flag_B = false;
int ikoru = 0;
int count_h_A = 0;
int count_h_B = 0;
bool flag_NA = true;
int count = 0;
if (str_input[count++] == str_A[count_h_A]) {
count_h_A++;
count_h_B++;
if (str_input[1] == str_A[count_h_A]) {
count_h_A++;
count++;
while (str_input[count] != '\0') {
if (str_input[count] != '=' && str_input[count] != '#' &&
str_input[count] != '~') {
break;
}
if (str_input[count] == '#') {
int kettei = 0;
if ((kettei = f_A(count)) == -1) {
cout << "NA" << endl;
break;
}
if (str_input[kettei] == '~' && str_input[kettei + 1] == '\0') {
cout << "A" << endl;
} else {
cout << "NA" << endl;
}
}
count++;
}
} else if (str_input[1] == str_B[count_h_B]) {
count_h_B++;
count++;
if (f_B() == true) {
cout << "B" << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
}
return 0;
}
void f_syokika() {
for (int i = 0; i < 110; i++) {
str_input[i] = '\0';
}
}
int f_A(int index) {
int usiro = index - 1;
int mae = index + 1;
int count_usiro = 0;
int count_mae = 0;
while (true) {
if (usiro < 0) {
break;
}
if (str_input[usiro] != '=') {
break;
}
count_usiro++;
usiro--;
}
while (str_input[mae] == '=') {
mae++;
count_mae++;
}
if (count_usiro == count_mae && count_usiro != 0) {
return mae;
}
return -1;
}
bool f_B() {
int count_Q = 0;
int count_ikoru = 0;
int i = 2;
while (str_input[i] == 'Q') {
count_Q++;
i += 2;
}
i = 3;
while (str_input[i] == '=') {
count_ikoru++;
i += 2;
}
if (count_Q != count_ikoru || count_Q == 0) {
return false;
}
if (str_input[i - 1] == '~' && str_input[i] == '~' &&
str_input[i + 1] == '\0') {
return true;
}
return false;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main {
/**
* @param args
*/
int solve(String str)
{
final int HEAD=0;
final int EYE_A=1;
final int EYE_B=2;
final int BODY_A1=3;
final int BODY_A2=4;
final int BODY_B=5;
final int STOMACH_A=6;
final int TAIL_A=7;
final int TAIL_B=8;
int state=-1;
int count=0;
for(int i=0;i<str.length();++i)
{
switch(str.charAt(i))
{
case '>':
if(state==-1){state=HEAD;}
else{return 2;}
break;
case '\'':
if(state==HEAD){state=EYE_A;}
else{return 2;}
break;
case '^':
if(state==HEAD){state=EYE_B;}
else{return 2;}
break;
case 'Q':
if(state==EYE_B){state=BODY_B;}
if(state!=BODY_B||++i>=str.length()||str.charAt(i)!='='){return 2;}
break;
case '=':
if(state==EYE_A||state==BODY_A1){state=BODY_A1;++count;}
else if(state==STOMACH_A||state==BODY_A2){state=BODY_A2;--count;}
else{return 2;}
break;
case '#':
if(state==BODY_A1){state=STOMACH_A;}
else{return 2;}
break;
case '~':
if(state==BODY_A2&&count==0){state=TAIL_A;}
else if(state==BODY_B){state=TAIL_B;count=1;}
else if(state==TAIL_B){++count;}
else{return 2;}
break;
}
}
if(state==TAIL_B&&count!=2)return 2;
return (state==TAIL_A)?0:((state==TAIL_B)?1:2);
}
void io()
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;++i)
{
String str=sc.next();
switch(solve(str))
{
case 0:
System.out.println('A');
break;
case 1:
System.out.println('B');
break;
case 2:
System.out.println("NA");
break;
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main().io();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main
{
public static void main(String arg[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
while(n-->0)
{
char ch[] = in.next().toCharArray();
int counta =0;
int countb =0;
boolean flag=false;
if(ch[0]=='>'&&ch[1]=='\'' &&ch[ch.length-1]=='~')
{
int co=2;
while(ch[co]!='#')
{
if(ch[co]=='=')
counta++;
co++;
}
while(ch[co]!='~')
{
if(ch[co]=='=')
countb++;
co++;
}
if(counta==countb&&counta>0)
{
System.out.println("A");
continue;
}
else
{
System.out.println("NA");
continue;
}
}
else
if(ch[0]=='>'&&ch[1]=='^' &&ch[ch.length-1]=='~'&&ch[ch.length-2]=='~')
{
int co=2;
while(ch[co] != '~')
{
if(ch[co]=='Q'&&ch[co+1]=='=')
flag = true;
else
{
flag = false;
break;
}
co+=2;
}
}
System.out.println(flag==true ? "B":"NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
bool a[4] = {}, b[3] = {};
int cnt = 0;
for (int j = 0; j < s.size(); j++) {
if (s[j] == '>') {
if (!a[1]) a[0] = true;
if (s[j + 1] == '^') b[0] = true;
} else if (a[0] && s[j] == '=') {
a[1] = true;
cnt++;
} else if (b[0] && s.substr(j, 2) == "Q=") {
b[1] = true;
} else if (a[1] && s[j] == '#') {
a[0] = false;
a[2] = true;
} else if (a[2] && s[j] == '=') {
cnt--;
} else if (a[1] && cnt == 0 && j + 1 == s.size() && s[j] == '~') {
a[3] = true;
} else if (b[1] && j + 2 == s.size() && s.substr(j, 2) == "~~") {
b[2] = true;
}
}
if (a[3])
cout << 'A' << endl;
else if (b[2])
cout << 'B' << endl;
else
cout << "NA" << endl;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
char data[110];
int a, b, i, n, c, j, len, temp;
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++) {
a = b = 0;
for (j = 0; j < 101; j++) {
scanf("%c", &data[j]);
if (data[j] == '\n') {
data[j] = '\0';
len = j;
break;
}
}
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 | #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[0] != '>' && (s[1] != '^' || s[1] != '\'')) f = 1;
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 - 1] != '~' && 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>
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;
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-10;
const double PI = acos(-1.0);
int main() {
int n;
cin >> n;
for (int t = (0); t < (n); ++t) {
string s;
cin >> s;
if (s[0] != '>') goto na;
if (s[1] == '\'') {
int state = 0;
int cnt1 = 0;
int cnt2 = 0;
for (int i = (2); i < (s.size()); ++i) {
if (s[i] == '=' && state == 0) {
cnt1++;
} else if (s[i] == '#' && state == 0) {
state = 1;
} else if (s[i] == '=' && state == 1) {
state = 2;
cnt2++;
} else if (s[i] == '=' && state == 2) {
cnt2++;
} else if (s[i] == '~' && state == 2) {
state = 3;
} else {
state = -1;
break;
}
}
if (state == 3 && cnt1 == cnt2) {
goto a;
} else {
goto na;
}
} else if (s[1] == '^') {
int state = 0;
int flag = 0;
for (int i = (2); i < (s.size()); ++i) {
if (s[i] == 'Q' && state == 0) {
state = 1;
} else if (s[i] == '=' && state == 1) {
state = 0;
flag = 1;
} else if (s[i] == '~' && state == 0) {
state = 2;
} else if (s[i] == '~' && state == 2) {
state = 3;
} else {
state = -1;
break;
}
}
if (state == 3) {
goto b;
} else {
goto na;
}
} else {
goto na;
}
a:
cout << "A" << endl;
continue;
b:
cout << "B" << endl;
continue;
na:
cout << "NA" << endl;
continue;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.