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": []
} | CORRECT | cpp | #include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
string str;
cin>>str;
if(str[0]!='>')cout<<"NA"<<endl;
else{
if(str[1]=='\''&&str[2]=='='){
int e=2;
for(;str[e]=='=';e++);
if(str[e]=='#'){
int f=e+1;
for(;str[f]=='=';f++);
if(e==f-e+1&&str[f]=='~'&&str[f+1]=='\0')cout<<"A"<<endl;
else cout<<"NA"<<endl;
}
else cout<<"NA"<<endl;
}
else if(str[1]=='^'&&str[2]=='Q'){
int e,flg=0;
for(e=2;str[e]=='Q';e+=2){
if(str[e+1]!='='){
cout<<"NA"<<endl;
flg=1;
break;
}
}
if(!flg){
if(str[e]=='~'&&str[e+1]=='~'&&str[e+2]=='\0')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": []
} | CORRECT | cpp | #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
typedef unsigned long long ull;
int Judge(string &s){
if(s[0] != '>') return -1;
if(s.size() < 2) return -1;
if(s[1] == '\''){
if(s[s.size()-1] != '~') return -1;
int len = sz(s) - 3;
if(len < 3 || len % 2 == 0) return -1;
FOR(i,(len-1)/2){
if(s[2+i] != '=' || s[2+len/2+1+i] != '=') return -1;
}
if(s[2+len/2] != '#') return -1;
return 0;
} else if(s[1] == '^'){
if(s[s.size()-1] != '~' || s[s.size()-2] != '~')return -1;
int len = sz(s) - 4;
if(len < 2 || len % 2 != 0) return -1;
FOR(i,len/2){
if(s[2+2*i] != 'Q' || s[2+2*i+1] != '=') return -1;
}
return 1;
} else {
return -1;
}
}
int main(){
int n; cin>>n;
string out[] = {"NA","A","B"};
FOR(i,n){
string s; cin>>s;
int a = Judge(s);
cout << out[a+1] << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | for r in range(input()):
snake=raw_input()
L=len(snake)
if L>5 and snake == ">'" + "="*((L-4)/2) + "#" + "="*((L-4)/2) + "~":
print "A"
elif L>5 and snake == ">^" + "Q="*((L-4)/2) + "~~":
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": []
} | CORRECT | cpp | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
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;
else if(str.substr(0,2)==">'"&&str[str.size()-1]=='~'&&str.size()%2==0){
string ss=str.substr(2,str.size()-3);
if(ss.size()>=3){
bool f=true;
for(int j = 0; j < ss.size(); j++){
if(j==0){
if(ss[j]!='='){
f=false;
break;
}
}
else if(j==(ss.size()/2)){
if(ss[j]!='#'){
f=false;
break;
}
}
else{
if(ss[j]!='='){
f=false;
break;
}
}
}
if(f)
cout<<"A"<<endl;
else
cout<<"NA"<<endl;
}
else{
cout<<"NA"<<endl;
}
}
else if(str.substr(0,2)==">^"&&str.substr(str.size()-2,2)=="~~"&&str.size()%2==0){
string ss=str.substr(2,str.size()-4);
bool f=true;
if(ss.size()>=2){
for(int j = 0; j < ss.size(); j+=2){
if(ss.substr(j,2)!="Q="){
f=false;
break;
}
}
if(f)
cout<<"B"<<endl;
else
cout<<"NA"<<endl;
}
else
cout<<"NA"<<endl;
}
else
cout<<"NA"<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
import java.util.regex.*;
class Main {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
for (int ii = 0; ii < n; ii++) {
String str = scanner.nextLine();
Pattern pa = Pattern.compile("^>'(=+)#\\1~$");
Pattern pb = Pattern.compile("^>\\^(?:Q=)+~~$");
Matcher ma = pa.matcher(str);
Matcher mb = pb.matcher(str);
if (ma.matches()) {
System.out.println("A");
} else if (mb.matches()) {
System.out.println("B");
} else {
System.out.println("NA");
}
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
int i,j;
int n;
vector<string> s;
cin>>n;
for(i=0;i<n;i++){
string str;
cin>>str;
s.push_back(str);
}
for(i=0;i<n;i++){
if(s[i].find(">'")==0){
if(s[i].find("~")==s[i].length()-1){
if(s[i].find("#")!=-1){
if(s[i].find("#")-2==s[i].length()-s[i].find("#")-2){
int len;
string str;
str=s[i].substr(2,s[i].find("#")-2);
len=str.length();
if(len>0){
for(j=0;j<len;j++){
if(str[j]!='=')
break;
}
if(j==len){
str=s[i].substr(s[i].find("#")+1,s[i].find("#")-2);
len=str.length();
for(j=0;j<len;j++){
if(str[j]!='=')
break;
}
if(j==len){
cout<<"A"<<endl;
continue;
}
}
}
}
}
}
}else if(s[i].find(">^")==0){
if(s[i].find("~~")==s[i].length()-2){
int len;
string str;
str=s[i].substr(2,s[i].length()-4);
len=str.length();
if(len>1&&len%2==0){
for(j=0;j<len;j+=2){
if(str[j]!='Q')
break;
}
if(j==len){
for(j=1;j<len;j+=2){
if(str[j]!='=')
break;
}
if(j==len+1){
cout<<"B"<<endl;
continue;
}
}
}
}
}
cout<<"NA"<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
string str;
int N;
cin>>N;
for(int i=0;i<N;i++){
cin>>str;
string x=" ";
if(str[0]=='>'){
for(int j=0;j<2;j++)
x[j]=str[j];
if(str[1]=='\''&&str[str.size()-1]=='~'){
bool f=true;int C=0;
int mid=(2+str.size()-2)/2;
for(int j=2;j<=str.size()-2;j++)
{if(j!=mid&&str[j]!='='){f=false;}
else if(j==mid&&str[j]!='#')f=false;
if(str[j]=='=')C++;
}
if(C%2!=0||C==0)f=false;
if(f==true)cout<<"A"<<endl;
else cout<<"NA"<<endl;
}
else if(str[1]=='^'&&str[str.size()-1]=='~'&&str[str.size()-2]=='~'){
bool f=true;int C=0;
for(int j=2;j<str.size()-2;j++)
{
C++;
if(C%2==0&&str[j]!='=')f=false;
if(C%2==1&&str[j]!='Q')f=false;
}
if(C%2!=0||C==0)f=false;
if(f==true)cout<<"B"<<endl;
else cout<<"NA"<<endl;
}
else cout<<"NA"<<endl;
}
else cout<<"NA"<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static BufferedReader br = null;
static {
br = new BufferedReader(new InputStreamReader(System.in));
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int cnt = parseNum();
while (cnt-- > 0) {
parseSnake();
}
}
private static void parseSnake() {
int typ = 0;
String str = null;
if ((str = parseStdin()) != null) {
int len = str.length();
if (len > 2 && len%2 == 0) {
if (str.charAt(0) == '>') {
if (str.charAt(1) == '\'' && len > 3) {
if (str.charAt(len-1) == '~' && str.charAt(len-2) == '=') {
if (str.charAt(2) == '=') {
char stc = 0;
int mid = 2+(len-4)/2;
for (int i = 2; i < len-1; i++) {
stc = str.charAt(i);
typ = (i == 2) ? 1 : typ;
if ((stc != '=' && stc != '#') || (stc == '#' && i != mid) || (stc != '#' && i == mid)) {
typ = 0;
break;
}
}
}
}
}
else if (str.charAt(1) == '^' && len > 4) {
if (str.charAt(len-1) == '~' && str.charAt(len-2) == '~' && str.charAt(len-3) == '=') {
char sc1 = 0;
char sc2 = 0;
for (int i = 2; i+1 < len-2; i += 2) {
typ = (i == 2) ? 2 : typ;
sc1 = str.charAt(i);
sc2 = str.charAt(i+1);
if (sc1 != 'Q' || sc2 != '=') {
typ = 0;
break;
}
}
}
}
}
}
}
switch (typ) {
case 1:
System.out.println("A");
break;
case 2:
System.out.println("B");
break;
default:
System.out.println("NA");
break;
}
}
private static int parseNum() {
int num = 0;
String str = null;
if ((str = parseStdin()) != null) {
num = Integer.parseInt(str);
}
return num;
}
private static String parseStdin() {
String stdin = null;
try {
String tmp = br.readLine();
if (tmp != null) {
if (!tmp.isEmpty()) stdin = tmp;
}
}
catch (IOException e) {}
return stdin;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | n = int(input())
ans_list = []
for i in range(n):
s = input()
if s[0] == "~" and s[-1] == ">":
s = s[::-1]
if s[0] == ">" and s[1] == "'" and s[-2] == "=" and s[-1] == "~":
check_s = s[2:-1].split("#")
if len(check_s) == 2:
front = check_s[0]
back = check_s[1]
if front == back and set(front) == {"="}:
ans = "A"
else:
ans = "NA"
else:
ans = "NA"
elif s[0] == ">" and s[1] == "^" and s[-2] == "~" and s[-1] == "~":
check_s = s[2:-2]
check_list = set(check_s.split("Q="))
if check_list == {""} and "Q=" in check_s:
ans = "B"
else:
ans = "NA"
else:
ans = "NA"
ans_list.append(ans)
for a in ans_list:
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": []
} | CORRECT | python3 | # AOJ 0139 Snakes
# Python3 2018.6.19 bal4u
import re
pa = ">'(=+)#(=+)~$" # A >'======#======~
pb = ">\^(Q=)+~~$" # B >^Q=Q=Q=Q=Q=Q=Q=Q=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": []
} | CORRECT | cpp | #include<iostream>
using namespace std;
int n;
string str;
bool check_A(string t){
int cnt=0,i=0,cnt2=0;
while(t[i]=='='){cnt++;i++;}
if(t[i]!='#')return false;
if(cnt==0)return false;
if((int)t.size()==i)return false;
i++;
while(t[i]=='='){cnt2++;i++;}
if(cnt!=cnt2)return false;
if((int)t.size()!=i+1)return false;
if(t[i]!='~')return false;
return true;
}
bool check_B(string t){
int i=0,cnt=0;
while(i+1<(int)t.size()&&t[i]=='Q'&&t[i+1]=='='){
i+=2;
cnt++;
}
if(cnt==0)return false;
if(i+2!=(int)t.size())return false;
if(t[i]=='~'&&t[i+1]=='~')return true;
return false;
}
int main(){
cin>>n;
while(n--){
cin>>str;
if(str[0]=='>'&&str[1]=='\''){
if(check_A(str.substr(2))){
cout<<'A'<<endl;
}else{
cout<<"NA"<<endl;
}
}else if(str[0]=='>'&&str[1]=='^'){
if(check_B(str.substr(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": []
} | CORRECT | cpp |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }
int main()
{
int n;
cin >> n;
while(n--)
{
string snk;
cin >> snk;
if(snk.size() < 6 || snk.size() % 2 != 0 || (snk.substr(0, 2) != ">'" && snk.substr(0, 2) != ">^"))
{
cout << "NA" << endl;
}
else if(snk.substr(0, 2) == ">^")
{
if(snk.substr(2, 2) == "Q=" && snk.substr(snk.size() - 2, 2) == "~~")
{
for(int i = 4; i < snk.size() - 2; i += 2)
{
if(snk.substr(i, 2) != "Q=")
{
goto ng;
}
}
cout << "B" << endl;
}
else
{
ng:;
cout << "NA" << endl;
}
}
else
{
if(snk[(snk.size() - 3) / 2 + 2] == '#' && snk[snk.size() - 1] == '~')
{
rep(i, (snk.size() - 3) / 2)
{
if(snk[i + 2] != '=' || snk[i + 3 + (snk.size() - 3) / 2] != '=')
{
goto ng;
}
}
cout << "A" << endl;
}
else
{
cout << "NA" << endl;
}
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
String res = "NA";
String sna = br.readLine();
if (sna.length() < 6) {
System.out.println(res);
continue;
}
if (sna.startsWith(">\'")) {
sna = sna.substring(2);
if (sna.startsWith("=")) {
int eq1 = 0;
for (char c : sna.toCharArray()) {
if (c == '=')
eq1++;
else
break;
}
sna = sna.substring(eq1);
if (sna.startsWith("#")) {
sna = sna.substring(1);
int eq2 = 0;
for (char c : sna.toCharArray()) {
if (c == '=')
eq2++;
else
break;
}
if (eq1 == eq2) {
sna = sna.substring(eq2);
if (sna.equals("~")) {
res = "A";
}
}
}
}
} else if (sna.startsWith(">^")) {
sna = sna.substring(2);
int q = 0;
while (sna.startsWith("Q=")) {
sna = sna.substring(2);
q++;
}
if (q > 0) {
if (sna.equals("~~")) {
res = "B";
}
}
}
System.out.println(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": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
bool isA(const string& str, int indx) {
if(str[indx++] != '>')
return false;
if(str[indx++] != '\'')
return false;
int count0 = 0;
for(; indx < str.size(); indx++) {
if(str[indx] == '=')
count0++;
else
break;
}
if(indx >= str.size())
return false;
if(str[indx++] != '#' || count0 == 0)
return false;
int count1 = 0;
for(; indx < str.size(); indx++) {
if(str[indx] == '=')
count1++;
else
break;
}
if(count0 == count1 && indx + 1 == str.size() && str[indx] == '~')
return true;
return false;
}
bool isB(const string & str, int indx) {
if(str[indx++] != '>')
return false;
if(str[indx++] != '^')
return false;
int count = 0;
for(; indx + 1 < str.size(); indx += 2) {
if(string(str.begin() + indx, str.begin() + indx + 2) == "Q=")
count++;
else
break;
}
if(count > 0 && string(str.begin() + indx, str.begin() + indx + 2) == "~~" && indx + 2 == str.size())
return true;
return false;
}
int main() {
string str;
int n;
cin >> n;
for(int t = 0; t < n; t++) {
int type = 0;
cin >> str;
for(int i = 0; i < str.size(); i++) {
if(str[i] == '>') {
if(isA(str, i)) {
type = 1;
break;
}
else if(isB(str, i)) {
type = 2;
break;
}
}
}
switch(type) {
case 0:
cout << "NA" << endl;
break;
case 1:
cout << "A" << endl;
break;
case 2:
cout << "B" << endl;
break;
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | def checkA(s):
l = len(s)
if l % 2 == 0:
return False
ll = (l-1)//2
for i in range(ll):
if s[i] != "=" or s[l-1-i] != "=":
return False
if s[ll] != "#":
return False
return True
def checkB(s):
l = len(s)
if l % 2 == 1:
return False
ll = l // 2
for i in range(ll):
if s[2*i] != "Q" or s[2*i+1] != "=":
return False
return True
def check(s):
if len(s) < 6:
return "NA"
if s[0:2] == ">'" and s[-1:] == "~":
if checkA(s[2:-1]):
return "A"
else:
return "NA"
if s[0:2] == ">^" and s[-2:] == "~~":
if checkB(s[2:-2]):
return "B"
else:
return "NA"
return "NA"
N = int(input())
for i in range(N):
s = input()
print(check(s))
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.*;
import java.util.regex.*;
class Main {
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in));
String l;
// 入力行数を読み飛ばす
l = reader.readLine();
Pattern a = Pattern.compile(">'(=+)#\\1~");
Pattern b = Pattern.compile(">\\^(Q=)+~~");
while ((l = reader.readLine()) != null) {
Matcher ma = a.matcher(l);
Matcher mb = b.matcher(l);
if (ma.matches()) {
System.out.println("A");
} else if (mb.matches()) {
System.out.println("B");
} else {
System.out.println("NA");
}
}
} catch (IOException e) {}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
string repeat(int n, string s) {
string res = "";
for (int i=0; i<n; ++i)
res += s;
return res;
}
int main() {
int N; cin >> N;
for (int i=0; i<N; ++i) {
string snake; cin >> snake;
int len = snake.size();
if (len <= 4) {
cout << "NA" << endl; continue;
}
string body = repeat(len/2 - 2, "=");
string A = ">'" + body + "#" + body + "~";
if (snake == A) {
cout << "A" << endl; continue;
}
body = repeat(len/2 - 2, "Q=");
string B = ">^" + body + "~~";
if (snake == B) {
cout << "B" << endl; continue;
}
cout << "NA" << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#include <cstdio>
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;
bool flg = true;
int len = (int)snake.size();
for(int i = 2 ; i < len ; i++,p++){
if(snake[i] == '#') break;
else if(snake[i] == '=') a++;
else{
flg = false;
break;
}
}
if(!flg){
puts("NA");
continue;
}
int b = 0,q = p + 1;
for(int i = q ; i < len ; i++,p++){
if(snake[i] == '~') break;
else if(snake[i] == '=') b++;
else{
flg = false;
break;
}
}
if(!flg || a == 0 || b == 0 || a != b){
puts("NA");
continue;
}
if(a == b && snake[len-1] == '~'){
puts("A");
}else{
puts("NA");
}
}else{
bool ok = true;
int p = 0;
string ss = "";
int len = (int)snake.size();
if(len < 6 || len % 2){
puts("NA");
continue;
}
for(int i = 2 ; i < len-2 ; i++,p++){
ss += snake[i];
if(p == 1){
p = -1;
if(ss != "Q="){
ok = false;
break;
}
ss = "";
}
}
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 | char s[101];
A(){
char a[101],b[101],t,t2;
return sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&t2)==3&&t=='~'&&strlen(a)==strlen(b);
}
Q(char*a){
int i;
for(i=0;a[i];i+=2)
if(a[i]!='Q'||a[i+1]!='=')
return 0;
return i>=2;
}
B(){
char a[101],t,t2;
return sscanf(s,">^%[Q=]~%c%c",a,&t,&t2)==2&&t=='~';
}
main(){
scanf("%*d\n");
for(;~scanf("%[^\n]\n",s);){
if(A())
puts("A");
else if(B())
puts("B");
else
puts("NA");
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
char str[] = "特に意味のない文章";
int cut_i, cut_j;
int len, kaisu;
int hantei;
scanf("%d", &kaisu);
for (cut_i = 0; cut_i < kaisu; cut_i++) {
scanf("%s", str);
len = strlen(str);
hantei = 0;
if ((len < 5) || (str[0] != '>') || (len % 2 != 0)) {
printf("NA\n");
continue;
}
len--;
if ((str[1] == '\'') && (str[len] == '~')) {
cut_j = 2;
while (str[cut_j] == '=') {
hantei++;
cut_j++;
}
if (str[cut_j] != '#') {
printf("NA\n");
} else {
cut_j++;
while (str[cut_j] == '=') {
hantei--;
cut_j++;
}
if (hantei == 0) {
printf("A\n");
} else {
printf("NA\n");
}
}
} else if ((str[1] == '^') && (str[len - 1] == str[len]) &&
(str[len] == '~')) {
for (cut_j = 2; cut_j < len - 2; cut_j += 2) {
if ((str[cut_j] != 'Q') || (str[cut_j + 1] != '=')) {
hantei = -1;
}
}
printf("B\n");
} else {
printf("NA\n");
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 | char s[101],a[50],b[50],t;
Q(){
int i;
for(i=0;a[i];i+=2)
if(a[i]!='Q'||a[i+1]!='=')
return 0;
return 1;
}
main(){
scanf("%*d");
for(;~scanf("%s",s);){
if(sscanf(s,">'%[=]#%[=]~%c",a,b,&t)==2&&strlen(a)==strlen(b))
puts("A");
else if(sscanf(s,">^Q=%[Q=]~~%c",a,&t)==1&&Q())
puts("B");
else
puts("NA");
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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 + 1] == '=') j += 2;
if (s[j] != '~' || s[j + 1] != '~') ans = "NA";
j += 2;
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 main() {
const string species[] = {"A", "B", "NA"};
string str = "";
int n;
while (getline(cin, str)) {
stringstream ssn(str);
ssn >> n;
if (n == 0) {
break;
}
int i, j;
for (i = 0; i < n; ++i) {
string res = species[2];
getline(cin, str);
int len = str.length();
if (str[0] == '>') {
if (str[1] == '\'') {
res = species[0];
} else if (str[1] == '^') {
res = species[1];
} else {
res = species[2];
}
}
if (res == species[0] || res == species[1]) {
if (res == species[0]) {
int prev = 0;
int after = 0;
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;
continue;
} else {
break;
}
}
if (j == len - 1) {
if (str[j] == '~' && flag && prev != 0 && after != 0 &&
prev == after) {
res = species[0];
} else {
res = species[2];
}
} else {
res = species[2];
}
} else {
for (j = 2; j < len - 2; j += 2) {
if (str[j] == 'Q' && str[j + 1] == '=') {
continue;
} else {
break;
}
}
if (j == len - 2 && str[j] == '~' && str[j + 1] == '~') {
res = species[1];
} else {
res = species[2];
}
}
}
cout << res << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n;
scanf("%d", &n);
while (n-- > 0) {
char snake[256] = {0};
int equal = 0;
int i;
scanf("%s", snake);
if (snake[0] == '>' && snake[1] == '\'') {
for (i = 2; snake[i] == '='; i++, equal++)
;
if (snake[i] == '#') {
for (i++; snake[i] == '='; i++, equal--)
;
puts(snake[i] == '~' && !snake[i + 1] && !equal ? "A" : "NA");
} else {
puts("NA");
}
} else if (snake[0] == '>' && snake[1] == '^') {
for (i = 2; snake[i] == 'Q' && snake[i + 1] == '='; i += 2)
;
puts(snake[i] == '~' && snake[i + 1] == '~' && !snake[i + 2] ? "B"
: "NA");
} else {
puts("NA");
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
bool a = false, b = false;
string str;
cin >> str;
if (str[0] == '>' && str[1] == '\'' && str.size() % 2 == 0) {
a = true;
}
if (str[0] == '>' && str[1] == '^' && str.size() % 2 == 1) {
b = true;
}
if (a) {
for (unsigned j = 2; j < str.size() - 1; j++) {
if (j != (str.size() / 2) && str[j] != '=') {
a = false;
break;
}
}
if (str[str.size() / 2] != '#' || str[str.size() - 1] != '~') a = false;
}
if (b) {
for (unsigned j = 2; j < str.size() - 2; j += 2) {
if (str[j] != 'Q' || str[j + 1] != '=') {
b = false;
break;
}
}
if (str[str.size() - 2] != '~' || str[str.size() - 1] != '~') b = false;
}
if (a)
cout << "A" << endl;
else if (b)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int N;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
int p = 0;
try {
if (s[p++] != '>') goto NA;
int m = 0;
switch (s[p]) {
case '\'':
while (s[++p] == '=') m++;
if (s[p++] != '#') goto NA;
for (int j = 0; j < m; j++, p++)
if (s[p] != '=') goto NA;
if (s[++p] != '~') goto NA;
if (p != s.length()) goto NA;
cout << "A" << endl;
continue;
case '^':
p++;
for (; p < s.length() - 2; p++) {
if (p % 2 == 0 && s[p] != 'Q' || p % 2 == 1 && s[p] != '=') goto NA;
}
if (s[p++] != '~' && s[p] != '~') goto NA;
cout << "B" << endl;
continue;
}
} catch (string str) {
cout << "NA" << endl;
continue;
}
continue;
NA:
cout << "NA" << endl;
continue;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
char snake[200];
int n, cnt1 = 0, cnt2 = 0, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", snake);
j = 0;
while (1) {
if (snake[j] == '>') {
j++;
if (snake[j] == '\'') {
j++;
while (1) {
if (snake[j] == '=') {
j++;
cnt1++;
} else if (snake[j] == '#') {
j++;
while (1) {
if (snake[j] == '=') {
j++;
cnt2++;
} else if (snake[j] == '~') {
if (cnt1 == cnt2) {
puts("A");
break;
} else {
puts("NA");
break;
}
break;
} else {
puts("NA");
break;
}
}
break;
} else {
puts("NA");
break;
}
}
break;
} else if (snake[j] == '^') {
j++;
while (1) {
if (snake[j] == 'Q' && snake[j + 1] == '=') {
j += 2;
} else if (snake[j] != '~') {
puts("NA");
break;
} else {
break;
}
}
if (snake[j] == '~' && snake[j + 1] == '~') {
puts("B");
} else {
puts("NA");
}
break;
} else {
puts("NA");
break;
}
} else {
puts("NA");
break;
}
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
int len, n, i, j;
char s[201];
scanf("%d", &n);
while (n--) {
scanf("%s", s);
len = strlen(s);
if (s[0] == '>' && s[len - 1] == '~' && len % 2 == 0) {
if (s[1] == 39) {
for (i = 0; s[i + 2] == '='; i++)
;
if (s[i + 2] == '#') {
for (j = 0; s[j + i + 3] == '='; j++)
;
if (i == j && s[j + i + 3] == '~' && s[j + i + 4] == '\0') {
puts("A");
goto lend;
}
}
} else if (s[1] = '^' && s[len - 2] == '~') {
for (i = 2; s[i] == 'Q' && s[i + 1] == '='; i += 2)
;
if (s[i] == '~' && s[i + 1] == '~' && s[i + 2] == '\0') {
puts("B");
goto lend;
}
}
}
puts("NA");
lend:;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int check() {
if (s.size() < 6) return 0;
if (s[0] != '>') return 0;
if (s[1] == '\'') {
int cnt = 0, cntp = 0;
for (int i = 2; i < s.size() - 1; i++) {
if (s[i] != '=') break;
cnt++;
cntp++;
}
if (s[2 + cnt] != '#') return 0;
for (int i = cnt + 3; i < s.size(); i++) {
if (s[i] != '=') break;
cnt--;
cntp++;
}
if (cnt) return 0;
if (2 + cntp + 2 != s.size()) return 0;
return (s[2 + cntp + 1] == '~' ? 1 : 0);
}
if (s[1] == '^') {
int cnt = 0;
for (int i = 2; i < s.size() - 2; i += 2) {
if (s[i] != 'Q' || s[i + 1] != '=') break;
cnt += 2;
}
if (cnt + 4 != s.size()) return 0;
return ((s[cnt + 2] == '~' && s[cnt + 3] == '~') ? 2 : 0);
}
return 0;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s;
cout << s << ' ' << check() << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | char s[102];
A(){
char a[101],b[101],t,t2;
return sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&t2)==3&&t=='~'&&strlen(a)==strlen(b);
}
B(){
short*q=s,l=0;
if(*q=='^>'){
for(;*++q=='=Q';)l++;
if(l&&*q++=='~~'&&!*q&255)
return 1;
}
return 0;
}
main(){
scanf("%*d\n");
for(;~scanf("%[^\n]\n",s);){
if(A())
puts("A");
else if(B())
puts("B");
else
puts("NA");
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int predA(const char* s) {
int n = 0;
if (*(s++) != '>') return (0);
if (*(s++) != '\'') return (0);
if (*s != '=') return (0);
for (; *s == '='; ++s) ++n;
if (*(s++) != '#') return (0);
for (; *s == '='; ++s) --n;
if (n) return (0);
if (*(s++) != '~') return (0);
if (*(s++) != '\0') return (0);
return (1);
}
int predB(const char* s) {
if (*(s++) != '>') return (0);
if (*(s++) != '^') return (0);
if (*s != 'Q') return (0);
for (;;) {
if (*s != 'Q') break;
++s;
if (*(s++) != '=') return (0);
}
if (*(s++) != '~') return (0);
if (*(s++) != '~') return (0);
if (*(s++) != '\0') return (0);
return (1);
}
int main(int argc, char* argv[]) {
int n;
scanf("%d", &n);
while (n--) {
char s[128] = {0};
scanf(" %s", s);
puts(predA(s) ? "A" : predB(s) ? "B" : "NA");
}
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string ans;
string s;
cin >> s;
if (s[0] != '>') {
cout << "NA" << endl;
continue;
}
if (s[1] == '^') {
ans = 'B';
int j = 2;
if (s[j] != 'Q' || s[j + 1] != '=') ans = "NA";
while (s[j] == 'Q' && s[j + 1] == '=') j += 2;
if (s[j] != '~' || s[j + 1] != '~') ans = "NA";
j += 2;
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 && h1) 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 | import java.lang.*;
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
String s=sc.next();
if(s.matches("^>'(=+)#\\1~$"))
System.out.println("A");
else if(s.matches("^>\\^(Q=)+~~$"))
System.out.println("B");
else
System.out.println("NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n=int(input())
for times in range(n):
s=input()
ans="NA"
#A???????????§
if s[:2]==">'" and s[-1]=="~":
t=s[2:-1].split("#")
if len(t)==2:
valid=True
for v in t[0]:
if v!="=":
valid=False
break
if valid and t[0]==t[1]:
ans="A"
#B???????????§
elif s[:2]==">^" and s[-2:]=="~~":
t=s[2:-2]
if len(t)%2==0:
valid=True
for i in range(0,len(t),2):
if t[i:i+2]!="Q=":
valid=False
break
if valid:
ans="B"
print(ans) |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string afunc(string str) {
string res = "NA";
for (int i = 0, j = str.size() - 1; i <= j; i++, j--) {
if (i == j) {
if (str[i] == '#') {
res = "A";
}
} else if (str[i] != '=' || str[j] != '=') {
break;
}
}
return res;
}
string bfunc(string str) {
string res = "B";
for (int i = 0; i < str.size(); i += 2) {
if (str[i] != 'Q' || str[i + 1] != '=') {
res = "NA";
break;
}
}
return res;
}
int main() {
int n;
string str, res;
while (cin >> n && n) {
while (n--) {
cin >> str;
res = "NA";
if ('>' == str[0]) {
str.erase(str.begin());
int l = str.size();
if (str[0] == '\'' && str[l - 1] == '~') {
str.erase(str.end() - 1);
str.erase(str.begin());
if (str.size() % 2 == 1) {
res = afunc(str);
}
} else if (str[0] == '^' && str[l - 1] == str[l - 2] &&
str[l - 1] == '~') {
str.erase(str.end() - 1);
str.erase(str.end() - 1);
str.erase(str.begin());
if (str.size() % 2 == 0) {
res = bfunc(str);
}
}
}
cout << res << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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);
if (temp.Length % 2 != 0) return NA;
for (int i = 0; i < temp.Length; i += 2)
{
string t = temp.Substring(i, 2);
if (t != "Q=") return NA;
}
return "B";
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int 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;
} else 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++) {
if ((str[j] == 'Q' && str[j + 1] != '=') ||
(str[j] == '=' && str[j + 1] != 'Q')) {
b = false;
break;
}
}
if (str[str.size() - 2] != '~' || str[str.size() - 1] != '~') b = false;
}
if (a)
cout << "A" << endl;
else if (b)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
bool isA(string s) {
int cnt1 = 0;
for (int i = 2; i < s.size(); ++i) {
if (s[i] == '=') {
++cnt1;
} else if (s[i] == '#') {
break;
} else {
return false;
}
}
int cnt2 = 0;
for (int i = cnt1 + 3; i < s.size(); ++i) {
if (s[i] == '=') {
++cnt2;
} else if (s[i] == '~') {
return (cnt1 == cnt2 && i == s.size() - 1);
} else {
return false;
}
}
return false;
}
bool isB(string s) {
if (s.size() % 2) return false;
for (int i = 2; i < s.size(); i += 2) {
if (s[i] == 'Q' && s[i + 1] == '=') {
continue;
} else if (s[i] == '~' && s[i + 1] == '~') {
return i + 1 == s.size() - 1;
} else {
return false;
}
}
return false;
}
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
for (int i = 0; i < n; ++i) {
if (s[i][0] != '>' || s[i].size() == 2) {
cout << "NA" << endl;
continue;
}
if (s[i][1] == '\'') {
cout << ((isA(s[i])) ? "A" : "NA") << endl;
} else if (s[i][1] == '^') {
cout << ((isB(s[i])) ? "B" : "NA") << endl;
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
#include <algorithm>
#include <string>
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 | cpp | #include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 55;
const long long mod = 1e9 + 7;
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
long long n;
cin >> n;
while (n--) {
string s;
cin >> s;
if (s.size() < 4) {
puts("NA");
continue;
}
long long kind = 0;
long long sz = s.size();
if (s[0] == '>' && s[1] == '\'' && s[sz - 1] == '~')
kind = 1;
else if (s[0] == '>' && s[1] == '^' && s[sz - 1] == '~' &&
s[sz - 2] == '~' && sz % 2 == 0)
kind = 2;
else
kind = 3;
if (kind == 1) {
long long cnt = 0, cmp = 0;
for (long long i = 2; i < sz - 1 && kind != 3; i++) {
if (s[i] != '=' && s[i] != '#')
kind = 3;
else {
if (s[i] == '=')
cnt++;
else if (s[i] == '#' && !cmp)
cmp = cnt, cnt = 0;
else
kind = 3;
}
}
if (cnt != cmp) kind = 3;
} else if (kind == 2) {
for (long long i = 2; i < sz - 2 && kind != 3; i += 2) {
if (s.substr(i, 2) != "Q=") kind = 3;
}
}
if (kind == 1)
puts("A");
else if (kind == 2)
puts("B");
else if (kind == 3)
puts("NA");
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, f, i, m;
string s;
cin >> n;
while (n-- > 0) {
cin >> s;
f = 0;
if (s[1] == '\'') {
m = s.find('#');
if (m != string::npos) {
for (i = 1; s[m - i] == s[m + i];) i++;
if (i > 1 && m - i == 1 && m + i == s.size() - 1 && s[m + i] == '~')
f = 1;
}
} else if (s[1] == '^') {
for (i = 2; s[i] == 'Q' && s[i + 1] == '=';) i += 2;
if (i > 2 && i == s.size() - 2 && s[i] == '~' && s[i + 1] == '~') f = 2;
}
if (f)
puts(f == 1 ? "A" : "B");
else
puts("NA");
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string A(int s) {
string res = ">\'";
for (int i = 0; i < s / 2 - 2; i++) res += '=';
res += '#';
for (int i = 0; i < s / 2 - 2; i++) res += '=';
res += "~";
return res;
}
string B(int s) {
string res = ">^";
for (int i = 0; i < s / 2 - 2; i++) res += "Q=";
res += "~~";
return res;
}
int main(void) {
string str;
int n;
cin >> n;
while (n--) {
cin >> str;
B(str.size());
if (A(str.size()) == str)
cout << "A" << endl;
else if (B(str.size()) == str)
cout << "B" << endl;
else
cout << "NA" << endl;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int 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 | n = gets.to_i
n.times do
str = gets.chomp!
size = (str.size - 4) / 2
stra = ">'"
strb = ">^"
size.times do
stra += '='
strb += 'Q='
end
stra += '#'
size.times do
stra += '='
end
stra += "~"
strb += '~~'
puts stra
puts strb
if (str == stra)
puts "A";
elsif (str == strb)
puts "B";
else
puts "NA"
end
end |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <stdio.h>
#include <math.h>
int main(){
int syucnt[1000]={0},n,i,t,l,gou=0;
char input[10000];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s",input);
l = strlen(input);
if(input[l-1]=='~'&&input[l-2]=='~'){//B種の調べ
for(t=2;t<=l-4;t=t+2){
if(input[t]=='Q'&&input[t+1]=='='){
gou++;
}
}
if(gou*2==l-4){
puts("B");
}else puts("NA");;
gou=0;
}else if(input[l/2]=='#'&&input[l-1]=='~'&&(l-4)%2==0){
int j=2;
for(t=0;t<(l-4)/2;t++){
if(input[j]=='='&&input[l-j]=='='){
gou++;
}
j++;
}
if(gou==((l-4)/2)){
puts("A");
}else puts("NA");
gou=0;
}else puts("NA");
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | char s[201],a[201],b[201],t,t2;
Q(){
int i;
for(i=0;a[i];i+=2)
if(a[i]!='Q'||a[i+1]!='=')
return 0;
return i>=2;
}
main(){
scanf("%*d\n");
for(;~scanf("%[^\n]\n",s);){
if(sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&t2)==3&&t=='~'&&strlen(a)==strlen(b))
puts("A ");
else if(sscanf(s,">^%[Q=]~%c%c",a,&t,&t2)==2&&t=='~'&&Q())
puts("B");
else
puts("NA");
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
bool F = 0;
int main() {
cin >> n;
for (long long i = 0; i < (n); i++) {
cin >> s;
if (s[0] == '>' && s[s.size() - 1] == '~') {
if (s[1] == '\'') {
int icnt = 0;
bool f = 1;
for (long long j = (2); j < (s.size() - 1); j++) {
if (s[j] == '=') {
if (f) {
icnt++;
} else {
icnt--;
}
} else if (s[j] == '#') {
if (f)
f = 0;
else {
F = 1;
break;
}
} else {
F = 1;
break;
}
}
if (F == 0 && icnt == 0 && s.size() >= 6) {
cout << "A" << endl;
} else {
cout << "NA" << endl;
}
} else if (s[1] == '^' && s.size() % 2 == 0 && s.size() >= 6 &&
s[s.size() - 1] == '~' && s[s.size() - 2] == '~') {
for (long long j = (2); j < (s.size() - 2); j++) {
if (j % 2 == 0) {
if (s[j] != 'Q') {
F = 1;
break;
}
} else {
if (s[j] != '=') {
F = 1;
break;
}
}
}
if (F) {
cout << "NA" << endl;
} else {
cout << "B" << endl;
}
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | import scala.io.StdIn.{readInt,readLine}
object Main {
def find(s:String) = {
if(s.length<2) "NA"
else if(s(0)=='>') {
if(s(1) == ''') { // maybeA
var isA = true
val s2 = s.drop(2).dropRight(1)
if(s2(s2.length/2) != '#') isA = false
else {
val s3 = s2.split("#")
if(s3(0)!=s3(1) || s3(0).exists(_!='=')) isA = false
}
if(isA && s(s.length-1)=='~') "A" else "NA"
} else if (s(1) == '^') { // maybeB
var isB = true
for(i<-2 until s.length-2 by 2) {
if(s(i)!='Q' || s(i+1)!='=') {
isB = false
}
}
if(isB && s(s.length-2)=='~' && s(s.length-1)=='~') "B" else "NA"
} else {
"NA"
}
} else "NA"
}
def main(args:Array[String]) = {
val n = readInt
for(i<-1 to n) {
val s = readLine.trim
println(find(s))
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string str;
cin >> str;
if (str[0] != '>')
cout << "NA" << endl;
else {
if (str[1] == '\'' && str[2] == '=') {
int e = 2;
for (; str[e] == '='; e++)
;
if (str[e] == '#') {
int f = e + 1;
for (; str[f] == '='; f++)
;
if (e == f - e + 1 && str[f] == '~' && str[f + 1] == '\0')
cout << "A" << endl;
else
cout << "NA" << endl;
} else
cout << "NA" << endl;
} else if (str[1] == '^') {
int e;
for (e = 2; str[e] == 'Q'; e += 2) {
if (str[e + 1] != '=') {
cout << "NA" << endl;
break;
}
}
if (str[e] == '~' && str[e + 1] == '~' && str[e + 2] == '\0')
cout << "B" << endl;
else
cout << "NA" << endl;
} else
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int max, data;
int num;
int cut_i;
char hebi[] = "意味のない文章";
scanf("%d", &max);
for (data = 0; data < max; data++) {
scanf("%s", hebi);
if (strlen(hebi) < 2 || hebi[0] != '>') {
puts("NA");
continue;
}
if (hebi[1] == '\'') {
num = 0;
cut_i = 2;
while (hebi[cut_i] == '=') {
cut_i++;
num++;
}
if (hebi[cut_i] != '#' || num <= 0) {
puts("NA");
} else {
cut_i++;
while (hebi[cut_i] == '=') {
cut_i++;
num--;
}
if (num != 0) {
puts("NA");
} else if (hebi[cut_i] != '~' || hebi[cut_i + 1] != 0) {
puts("NA");
} else {
puts("A");
}
}
} else if (hebi[1] == '^') {
cut_i = 2;
while (hebi[cut_i] == 'Q' && hebi[cut_i + 1] == '=') {
cut_i += 2;
}
if (cut_i == 2) {
puts("NA");
} else if (hebi[cut_i] != '~' || hebi[cut_i + 1] != '~' ||
hebi[cut_i + 2] != 0) {
puts("NA");
} else {
puts("B");
}
} else {
puts("NA");
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | n = gets.to_i
n.times do
str = gets.chomp!
size = (str.size - 4) / 2
stra = ">'"
strb = ">^"
size.times do
stra += '='
strb += 'Q='
end
stra += '#'
size.times do
stra += '='
end
stra += "~"
strb += '~~'
if (str == stra)
puts "A"
elsif (str == strb)
puts "B"
else
puts "NA"
end
end |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int n;
scanf("%d", &n);
while (n-- > 0) {
char snake[256];
int i;
int equal = 0;
scanf("%s", snake);
if (snake[0] == '>' && snake[1] == '\'') {
for (i = 2; snake[i] == '='; i++, equal++)
;
if (snake[i] == '#') {
for (i++; snake[i] == '='; i++, equal--)
;
if (snake[i] == '~' && !snake[i + 1] && !equal) {
puts("A");
} else {
puts("NA");
}
} else {
puts("NA");
}
} else if (snake[0] == '>' && snake[1] == '^') {
for (i = 2; snake[i] == 'Q' && snake[i + 1] == '='; i += 2)
;
if (snake[i] == '~' && snake[i + 1] == '~' && !snake[i + 2]) {
puts("B");
} else {
puts("NA");
}
} else {
puts("NA");
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
String snake = sc.next();
if (snake.indexOf('#') > 0 && snake.charAt(0) == '>' && snake.charAt(1) == '\'' && snake.charAt(snake.length() - 1) == '~') {
String[] l = snake.split("[>'#~]");
if ( l[2].length() == l[3].length() && l[2].length() + l[3].length() + 4 == snake.length()) {
System.out.println("A");
}else {
System.out.println("NA");
}
} else if (snake.charAt(0) == '>' && snake.charAt(1) == '^' && snake.charAt(snake.length() - 2) == '~' && snake.charAt(snake.length() - 1) == '~'&&snake.replaceAll("Q=","").equals(">^~~")) {
System.out.println("B");
}else {
System.out.println("NA");
}
}
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string solve(string s) {
int i = 0, j;
string tmp;
for ((i) = 0; (i) < (100); ++(i)) {
tmp += "=";
if (s == ">'" + tmp + "#" + tmp + "~~") return "A";
}
tmp.clear();
for ((i) = 0; (i) < (100); ++(i)) {
tmp += "Q=";
if (s == ">^" + tmp + "~~") return "B";
}
return "NA";
}
int main(void) {
int i, j, n;
string s;
scanf("%d", &n);
for (; n--;) {
cin >> s;
cout << solve(s) << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
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++) {
if (scanf("%c", &data[j]) == EOF) {
data[j] = '\n';
}
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 predA(const char* s) {
int n = 0;
if (*(s++) != '>') return (0);
if (*(s++) != '\'') return (0);
for (; *s == '='; ++s) ++n;
if (*(s++) != '#') return (0);
for (; *s == '='; ++s) --n;
if (n) return (0);
if (*(s++) != '~') return (0);
if (*(s++) != '\0') return (0);
return (1);
}
int predB(const char* s) {
if (*(s++) != '>') return (0);
if (*(s++) != '^') return (0);
for (;;) {
if (*s != 'Q') break;
++s;
if (*(s++) != '=') return (0);
}
if (*(s++) != '~') return (0);
if (*(s++) != '~') return (0);
if (*(s++) != '\0') return (0);
return (1);
}
int main(int argc, char* argv[]) {
int n;
scanf("%d", &n);
while (n--) {
char s[128] = {0};
scanf(" %s", s);
puts(predA(s) ? "A" : predB(s) ? "B" : "NA");
}
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
int num;
int i, j, k, l;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
break;
}
}
if (snake[0] == '>') {
if (snake[1] == '\'') {
for (j = 2; j < i; j++) {
if (snake[j] == '=') {
bodyacnt++;
} else if (snake[j] == '#') {
break;
}
}
for (k = j; k < i; k++) {
if (snake[k] == '=') {
midcnt++;
} else if (snake[k] == '~') {
endacnt++;
if (endacnt == 1) {
break;
}
}
}
} 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) {
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) {
int n, len, flag = 0, flag2 = 0, cnt1 = 0, cnt2 = 0;
char snake[10000][200];
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%s", snake[i]);
len = strlen(snake[i]);
if (snake[i][0] == '>' && snake[i][1] == '\'') {
for (int j = 2; j < len - 1; j++) {
if (snake[i][j] == '=' && flag == 0) {
cnt1++;
flag2 = 1;
}
if (snake[i][j] == '=' && flag == 1) {
cnt2++;
flag2 = 1;
}
if (snake[i][j] == '#') flag = 1;
cout << cnt1 << ' ' << cnt2 << endl;
}
if (snake[i][len - 1] == '~' && cnt1 == cnt2 && flag2 == 1)
cout << 'A' << endl;
else
cout << "NA" << endl;
flag = 0;
flag2 = 0;
cnt1 = 0;
cnt2 = 0;
} else if (snake[i][0] == '>' && snake[i][1] == '^') {
for (int j = 2; j < len - 2; j++) {
if (snake[i][j] == 'Q' && snake[i][j + 1] == '=') flag = 1;
}
if (snake[i][len - 2] == '~' && snake[i][len - 1] == '~' && flag == 1)
cout << 'B' << endl;
else
cout << "NA" << endl;
} else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
int main(void) {
int n;
cin >> n;
while (n--) {
string snake;
cin >> snake;
if (snake[0] == '>' && snake[1] == '\'' && snake[snake.size() - 1] == '~') {
int count = 0;
int end;
for (int i = 2; i < snake.size() && snake[i] == '='; i++) {
count++;
end = i;
}
end++;
if (count && snake[end] == '#' && end + count + 2 == snake.size()) {
bool yes = true;
for (int i = end + 1; i < snake.size() - 1; i++) {
if (snake[i] != '=') yes = false;
}
if (yes) {
cout << "A" << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
} else if (snake[0] == '>' && snake[1] == '^' &&
snake[snake.size() - 1] == '~' &&
snake[snake.size() - 2] == '~') {
bool yes = true;
for (int i = 2; i < snake.size() - 2; i++) {
if (i % 2 == 0 && snake[i] != 'Q') yes = false;
if (i % 2 == 1 && snake[i] != '=') yes = false;
}
if (yes) {
cout << "B" << endl;
} else {
cout << "NA" << endl;
}
} 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 argc, char **argv) {
int n, f, m;
char a[101], w;
cin >> m;
while (m--) {
f = 0;
scanf("%s", a);
w = (a[1] == '^') ? 'B' : 'A';
n = strlen(a);
if (w == 'A') {
if (a[n - 1] == '~') {
for (int i = 2; i < n - i; i++) {
if (a[i] != a[n - i]) {
f = 1;
break;
}
}
} else {
f = 1;
}
} else {
if (a[n - 1] == '~' && a[n - 2] == '~') {
for (int i = 2; i < n - 2; i += 2) {
if (a[i] != 'Q' && a[i + 1] != '=') {
f = 1;
break;
}
}
} else {
f = 1;
}
}
if (f == 1) {
cout << "NA" << endl;
} else {
cout << w << 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, a, c, f;
string str = "\0";
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> str;
c = f = 0;
a = 2;
if (str[0] == '>') {
if (str[1] == '\'') {
while (str[a] == '=') {
++a;
++c;
}
if (str[a] != '#' || c == 0) goto end;
++a;
while (str[a] == '=') {
++a;
++f;
}
if (str[a] == '~' && c == f && c != 0)
cout << "A" << endl;
else
goto end;
} else if (str[1] == '^') {
while (str[a] == 'Q' && str[a + 1] == '=') {
a += 2;
}
if (str[a] == '~' && str[a + 1] == '~')
cout << "B" << endl;
else
goto end;
} else
goto end;
} else {
end:
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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"
| 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"
| 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 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;
scanf("%s", data);
len = strlen(data);
if (len == '0') p = 1;
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;
bool isA(string s) {
int cnt1 = 0;
for (int i = 2; i < s.size(); ++i) {
if (s[i] == '=') {
++cnt1;
} else if (s[i] == '#') {
if (cnt1 == 0) return false;
break;
} else {
return false;
}
if (i == s.size() - 1) return false;
}
int cnt2 = 0;
for (int i = cnt1 + 3; i < s.size(); ++i) {
if (s[i] == '=') {
++cnt2;
} else if (s[i] == '~') {
return (cnt1 == cnt2 && i == s.size() - 1);
} else {
return false;
}
}
return false;
}
bool isB(string s) {
if (s.size() % 2) return false;
for (int i = 2; i < s.size(); i += 2) {
if (s[i] == 'Q' && s[i + 1] == '=') {
continue;
} else if (s[i] == '~' && s[i + 1] == '~') {
return i + 1 == s.size() - 1;
} else {
return false;
}
}
return false;
}
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
for (int i = 0; i < n; ++i) {
if (s[i][0] != '>' || s[i].size() == 3) {
cout << "NA" << endl;
continue;
}
if (s[i][1] == '\'') {
cout << ((isA(s[i])) ? "A" : "NA") << endl;
} else if (s[i][1] == '^') {
cout << ((isB(s[i])) ? "B" : "NA") << endl;
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | for _ in [0]*int(input()):
s=input()
if s[:2]=='>\'' and s[-1]=='~':
a=s[2:-1].split('#')
print(['NA','A'][set(a[0])==set(a[1])=={'='} and len(set(a))==1])
elif s[:2]=='>^' and s[-2:]=='~~':
s=s[2:-2]
print(['NA','B'][len(s)==2*s.count('Q=')]) |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int n, m, s, t;
string str, p;
cin >> m;
while (m--) {
cin >> str;
n = str.size();
p = (str[1] == '^') ? "B" : "A";
if (str[n - 1] != '~') {
cout << "NA" << endl;
continue;
}
if (p == "A") {
s = (n + 1) / 2;
if (str.substr(2, s - 1) != str.substr(s + 1, s - 1) && str[s] != '#') {
cout << "NA" << endl;
continue;
}
} else {
if (str[n - 2] != '~') {
cout << "NA" << endl;
continue;
}
for (int i = 2; i < n - 2; i += 2) {
if (str.substr(i, 2) != "Q=") {
n = -1;
cout << "NA" << endl;
break;
}
}
if (n == -1) {
continue;
}
}
cout << p << 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) {
char snake[200];
int n, cnt1 = 0, cnt2 = 0, j = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", snake);
while (1) {
if (snake[j] == '>') {
j++;
if (snake[j] == '\'') {
j++;
while (1) {
if (snake[j] == '=') {
j++;
cnt1++;
} else if (snake[j] == '#') {
j++;
while (1) {
if (snake[j] == '=') {
j++;
cnt2++;
} else if (snake[j] == '~') {
if (cnt1 == cnt2) {
puts("A");
break;
} else {
puts("NA");
break;
}
break;
} else {
puts("NA");
break;
}
}
break;
} else {
puts("NA");
break;
}
}
break;
} else if (snake[j] == '^') {
j++;
while (1) {
if (snake[j] == 'Q' && snake[j + 1] == '=') {
j += 2;
} else {
break;
}
}
if (snake[j] == '~' && snake[j + 1] == '~') {
puts("B");
}
break;
} else {
puts("NA");
break;
}
} else {
puts("NA");
break;
}
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
void a() {
cout << "NA" << endl;
return;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string snake;
cin >> snake;
string::size_type aruyon;
if ((aruyon = snake.find(">'")) == 0) {
int equal = 0;
int j;
for (j = 2; snake.at(j) == '='; j++) equal++;
if (equal > 0)
if (snake.at(j) == '#') {
j++;
for (; snake.at(j) == '='; j++) equal--;
if (equal == 0) {
if (snake.at(j) == '~' && j + 1 == snake.size())
cout << 'A' << endl;
else
a();
} else
a();
} else
a();
else
a();
} else if ((aruyon = snake.find(">^")) == 0) {
int j;
if ((aruyon = snake.find("~~")) == snake.size() - 2) {
if (aruyon % 2 == 0) {
for (j = 2; j < aruyon; j++) {
if (snake.at(j) == 'Q')
j++;
else {
j = 0;
break;
}
if (snake.at(j) != '=') {
a();
break;
}
}
if (j == aruyon)
cout << 'B' << endl;
else
a();
} else
a();
} else
a();
} else
a();
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
void a() {
cout << "NA" << endl;
return;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string snake;
cin >> snake;
string::size_type aruyon;
if ((aruyon = snake.find(">'")) == 0) {
int equal = 0;
int j;
for (j = 2; snake.at(j) == '='; j++) equal++;
if (equal > 0)
if (snake.at(j) == '#') {
j++;
for (; snake.at(j) == '='; j++) equal--;
if (equal == 0) {
if (snake.at(j) == '~' && j + 1 == snake.size())
cout << 'A' << endl;
else
a();
} else
a();
} else
a();
else
a();
} else if ((aruyon = snake.find(">^")) == 0) {
int j;
bool dou = false;
if ((aruyon = snake.find("~~")) == snake.size() - 2) {
if (aruyon % 2 == 0) {
for (j = 2; j < aruyon; j++) {
if (snake.at(j) == 'Q')
j++;
else {
j = 0;
dou = false;
break;
}
if (snake.at(j) != '=') {
a();
dou = false;
break;
} else
dou == true;
}
if (j == aruyon && dou == true)
cout << 'B' << endl;
else
a();
} else
a();
} else
a();
} else
a();
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int A_snake(char snake[]);
int B_snake(char snake[]);
int main(void) {
int quantity, i;
char snake[201] = {0};
scanf("%d", &quantity);
for (i = 0; i < quantity; i++) {
scanf("%s", snake);
if (snake[0] != '>') {
puts("NA");
} else if (snake[1] == '\'') {
if (A_snake(snake)) {
puts("A");
} else {
puts("NA");
}
} else if (snake[1] == '^') {
if (B_snake(snake)) {
puts("B");
} else {
puts("NA");
}
} else {
puts("NA");
}
}
return (0);
}
int A_snake(char snake[]) {
int j, idx = 0, count = 0;
for (j = 2; j < 201; j++) {
if (snake[j] != '=' && snake[j] != '#')
if (snake[j] != '~') return (0);
if (snake[j] == '=') {
count++;
} else if (snake[j] == '#') {
idx = j;
break;
}
}
for (j = idx + 1; j < 201; j++) {
if (snake[j] == '=') {
count--;
} else if (snake[j] == '~') {
idx = j;
break;
} else {
return (0);
}
}
if (count == 0) {
if (snake[idx] == '~' && snake[idx + 1] == '\0')
return (1);
else
return (0);
} else {
return (0);
}
}
int B_snake(char snake[]) {
int j, idx, count = 0;
char *str;
str = &snake[2];
for (j = 2; j < 201; j += 2) {
if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++;
if (!(strncmp(str, "~~", 2)) && j > 3) {
idx = j;
break;
}
str += 2;
}
if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) {
if (snake[idx + 2] == '\0') {
return (1);
} else {
return (0);
}
} else
return (0);
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string input;
cin >> input;
string check = input.substr(0, 2) + input.substr(input.size() - 2, 2);
bool isCorrect = true;
if (check == ">'=~") {
int count = 0;
for (int j = 2; input.substr(j, 1) == "="; j++) count++;
if (input.substr(count + 2, 1) != "#") isCorrect = false;
for (int j = 2 + count + 1; j < 2 + count * 2 + 1; j++)
if (input.substr(j, 1) != "=") isCorrect = false;
if (input.size() != count * 2 + 2 + 1 * 2) isCorrect = false;
if (isCorrect) cout << "A" << endl;
} else if (check == ">^~~") {
for (int j = 2; j < input.size() - 2; j += 2)
if (input.substr(j, 2) != "Q=") isCorrect = false;
if (isCorrect) cout << "B" << endl;
} else {
cout << "NA" << endl;
}
if (!isCorrect) 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 ;
#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};
inline bool value(int x,int y,int w,int h){
return (x >= 0 && x < w && y >= 0 && y < h);
}
template<typename T>
void Unique(vector<T> &v){
sort(all(v));
v.erase(unique(all(v)),v.end());
}
template<typename T>
T ston(string& str, T n){
istringstream sin(str) ;
T num ;
sin >> num ;
return num ;
}
void Ans(bool f){
if(f) cout << "YES"<<endl;
else cout << "NO"<<endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n;
rep(i,n){
cin >> s;
if(s[0] != '>'|| s.size() < 6|| (s[1] != '\'' && s[1] != '^') ){
cout << "NA"<<endl;
}
else if(s[1] == '\''){
int cnt = find(all(s),'#') - s.begin()-2;
if(s[2*cnt+3] == '~' && 2*cnt+3 == s.size()-1){
cout << "A"<<endl;
}
else{
cout <<"NA"<<endl;
}
}
else{
bool f = false;
for(int i = 2; i < s.size(); i+=2){
if(!(s[i] == 'Q' && s[i+1] == '=')){
if(s[i] == '~' && s[i+1] == '~' && i == s.size()-2){
cout << "B"<<endl;
f = true;
}
else{
break;
}
}
}
if(!f) cout << "NA"<<endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | using System;
namespace AOJ.Volume1
{
public class Snakes
{
public static bool CheckA(string input)
{
// 先頭は「>'」
if (input.Substring(0, 2) != ">'") { return false; }
// 末尾は「~」
if (input.Substring(input.Length - 1, 1) != "~") { return false; }
// 真ん中のチェック
var tmp = input.Substring(2, input.Length - 3).Split('#');
// 「#」が無いか複数存在
if (tmp.Length != 2) { return false; }
string bef = tmp[0], aft = tmp[1];
// 「=」以外の文字を含む
if (bef.Replace("=", "").Length > 0) { return false; }
if (aft.Replace("=", "").Length > 0) { return false; }
// 「#」の前と後が同じ長さではない
if (bef.Length != aft.Length) { return false; }
return true;
}
public static bool CheckB(string input)
{
// 先頭は「>^」
if (input.Substring(0, 2) != ">^") { return false; }
// 末尾は「~~」
if (input.Substring(input.Length - 2, 2) != "~~") { return false; }
// 「Q=」以外の文字列が存在する
if (input.Replace("Q=", "").Length > 0) { return false; }
return true;
}
public static int Main()
{
int s = int.Parse(Console.ReadLine());
for (int i = 0; i < s; i++)
{
string input = Console.ReadLine();
if (CheckA(input)) { Console.WriteLine("A"); }
else if(CheckB(input)){Console.WriteLine("B");}
else { Console.WriteLine("NA"); }
}
return 0;
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main(void) {
int quantity, i, j, idx, count = 0;
char snake[200] = {0};
scanf("%d", &quantity);
for (i = 0; i < quantity; i++) {
scanf("%s", snake);
if (snake[0] != '>') {
puts("NA");
break;
} else if (snake[1] == '\'') {
for (j = 2; j < 199; j++) {
if (snake[j] == '=') {
count++;
} else if (snake[j] == '#') {
idx = j;
break;
}
}
for (j = idx + 1; j < 199; j++) {
if (snake[j] != '=') {
idx = j;
break;
}
count--;
}
if (count == 0) {
if (snake[idx] == '~')
puts("A");
else
puts("NA");
} else {
puts("NA");
}
} else if (snake[1] == '^') {
for (j = 2; j < 198; j += 2) {
if (snake[j] == 'Q') count++;
if (snake[j + 1] == '=') count--;
if (snake[j] == '~' && snake[j + 1] == '~') break;
printf("count = %d\n", count);
}
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 | java | import java.util.*;
import java.lang.*;
import java.io.*;
class Main{
private static boolean snake_A(String snake)
{
if(snake.charAt(snake.length()-1) != '~')
return false;
if(!snake.substring(0,2).equals(">'"))
return false;
if(snake.indexOf("#") == -1)
return false;
if(snake.indexOf("#") > snake.indexOf("~"))
return false;
if(snake.indexOf("#")-snake.indexOf("'") != snake.indexOf("~")-snake.indexOf("#"))
return false;
int left,right;
left = right = 0;
for(int i=2;i<snake.indexOf("#");i++)
{
if(snake.charAt(i) == '=')
left++;
else
{
return false;
}
}
for(int i=snake.indexOf("#")+1;i<snake.indexOf("~");i++)
{
if(snake.charAt(i) == '=')
right++;
else
return false;
}
if(left != right)
return false;
return true;
}
private static boolean snake_B(String snake)
{
if(!snake.substring(snake.length()-2,snake.length()).equals("~~"))
return false;
if(!snake.substring(0,2).equals(">^"))
return false;
int cnt = 0;
for(int i=2;i<snake.indexOf("~");i+=2)
{
if(snake.substring(i,i+2).equals("Q="))
cnt++;
else
return false;
}
if(cnt < 1)
return false;
return true;
}
public static void main(String args[])throws IOException{
//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Scanner in = new Scanner(System.in);
int n;
// n = Integer.parseInt(in.readLine());
n = in.nextInt();
while(n-- > 0)
{
//String snake = in.readLine();
String snake = in.next();
if(snake_A(snake))
{
System.out.println("A");
}
else if(snake_B(snake))
{
System.out.println("B");
}
else
{
System.out.println("NA");
}
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | require 'pp'
$stdin.gets.chomp.to_i.times do
line = $stdin.gets.chomp
ans = false
if (m = line.match(/^>'(=+)#(=+)~$/)) then
if m[1].length == m[2].length then
puts 'A'
ans = true
end
end
if (m = line.match(/^>\^(.*?)~~$/)) then
if ((m[1].unpack("a2"*(m[1].length/2))).all? {|x| x == "Q="}) then
puts 'B'
ans = true
end
end
puts 'NA' if !ans
end |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string ans;
string s;
cin >> s;
if (s[0] != '>') {
cout << "NA" << endl;
continue;
}
if (s[1] == '^') {
ans = 'B';
int h = 2;
if (s[h] == 'Q' && s[h + 1] == '=')
while (s[h++] == 'Q' && s[h++] == '=')
;
h--;
if (s[h++] != '~' || s[h++] != '~') ans = "NA";
if (h != s.size()) ans = "NA";
} else if (s[1] == '\'') {
ans = 'A';
int h1 = 0, h2 = 0;
int j = 1;
while (s[++j] == '=') h1++;
if (s[j] != '#') ans = "NA";
while (s[++j] == '=') h2++;
if (s[j] != '~') ans = "NA";
if (++j != s.size()) ans = "NA";
if (h1 != h2) ans = "NA";
}
cout << ans << endl;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | char s[101],a[50],b[50],t,t2;
Q(){
int i;
for(i=0;a[i];i+=2)
if(a[i]!='Q'||a[i+1]!='=')
return 0;
return i>=2;
}
main(){
scanf("%*d");
for(;~scanf("%s",s);){
if(sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&t2)==3&&t=='~'&&strlen(a)==strlen(b))
puts("A");
else if(sscanf(s,">^%[Q=]~%c%c",a,&t,&t2)==2&&t=='~'&&Q())
puts("B");
else
puts("NA");
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | s.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;
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;
for (int i = 2; i < str.size(); i++) {
if (str[i] == '=')
t++;
else if (str[i] == '#')
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 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++) {
if (scanf("%s", snake) == '\n') {
puts("NA");
return (0);
}
if (snake[0] != '>') {
puts("NA");
} else if (snake[1] == '\'') {
if (A_snake(snake)) {
puts("A");
} else {
puts("NA");
}
} else if (snake[1] == '^') {
if (B_snake(snake)) {
puts("B");
} else {
puts("NA");
}
} else {
puts("NA");
}
}
return (0);
}
int A_snake(char snake[]) {
int j, idx = 0, count = 0;
for (j = 2; j < 200; j++) {
if (snake[j] != '=' && snake[j] != '#')
if (snake[j] != '~') return (0);
if (snake[j] == '=') {
count++;
} else if (snake[j] == '#') {
idx = j;
break;
}
}
for (j = idx + 1; j < 200; j++) {
if (snake[j] == '=') {
count--;
} else if (snake[j] != '=') {
idx = j;
break;
}
}
if (count == 0) {
if (snake[idx] == '~' && snake[idx + 1] == '\0')
return (1);
else
return (0);
} else {
return (0);
}
}
int B_snake(char snake[]) {
int j, idx, count = 0;
char *str;
str = &snake[2];
for (j = 2; j < 200; j += 2) {
if (strncmp(str, "Q=", 2) != 0 && strncmp(str, "~~", 2) != 0) count++;
if (!(strncmp(str, "~~", 2))) {
idx = j;
break;
}
str += 2;
}
if (count == 0 && (snake[idx] == '~' && snake[idx + 1] == '~')) {
if (snake[idx + 2] == '\0') {
return (1);
} else {
return (0);
}
} else
return (0);
return (0);
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
bool checkA(char st[1001]) {
int len = strlen(st);
if (st[len - 1] != '~') return false;
if (len % 2 == 1) return false;
for (int i = 0; i < len / 2 - 1; i++) {
if (!(st[i] == st[len - 2 - i] && st[i] == '=')) return false;
}
return true;
}
bool checkB(char st[1001]) {
if (st[strlen(st) - 1] != '~' || st[strlen(st) - 2] != '~') return false;
for (int i = 0; i < strlen(st) - 2; i += 2) {
if (!(st[i] == 'Q' && st[i + 1] == '=')) return false;
}
return true;
}
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char str[1001];
scanf("%s", str);
bool Af = false;
bool Bf = false;
if (str[1] == '\'') {
Af = checkA(str + 2);
} else {
Bf = checkB(str + 2);
}
if (Af == Bf) {
puts("NA");
} else if (Af == true) {
puts("A");
} else {
puts("B");
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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));
try {
int num = Integer.parseInt(bfr.readLine());
String res;
for (int i = 0; i < num; i++) {
res = me.judge(bfr.readLine());
System.out.println(res);
}
} catch (NumberFormatException e) {
}
}
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> str;
string x = " ";
for (int j = 0; j < 2; j++) x[j] = str[j];
if (str[0] == '>') {
if (str[1] == '\'' && str[str.size() - 1] == '~') {
bool f = true;
int C = 0;
int mid = (2 + str.size() - 2) / 2;
for (int j = 2; j <= str.size() - 2; j++) {
if (j != mid && str[j] != '=') {
f = false;
} else if (j == mid && str[j] != '#')
f = false;
if (str[j] == '=') C++;
}
if (C % 2 != 0 || C == 0) f = false;
if (f == true)
cout << "A" << endl;
else
cout << "NA" << endl;
} else if (str[1] == '^' && str[str.size() - 1] == '~' &&
str[str.size() - 2] == '~') {
bool f = true;
int C = 0;
for (int j = 2; j < str.size() - 2; j++) {
C++;
if (C % 2 == 0 && str[j] != '=') f = false;
if (C % 2 == 1 && str[j] != 'Q') f = false;
}
if (C % 2 != 0 || C == 0) f = false;
if (f == true)
cout << "B" << endl;
else
cout << "NA" << endl;
}
} else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
bool isOutOfStr(int ind, string str) { return ind >= str.length(); }
int main(void) {
int n;
cin >> n;
while (n--) {
string str;
cin >> str;
if (!isOutOfStr(1, str) && str[0] == '>' && str[1] == '\'') {
int sharp_cnt = 0;
int ind;
ind = 2;
if (!isOutOfStr(ind, str) && str[ind] != '=') {
cout << "NA" << endl;
continue;
}
for (;; ind++) {
if (isOutOfStr(ind, str) || str[ind] != '=') {
break;
}
sharp_cnt++;
}
if (isOutOfStr(ind, str) || str[ind] != '#') {
cout << "NA" << endl;
continue;
}
ind++;
bool flg = true;
for (int i = 0; i < sharp_cnt; i++, ind++) {
if (isOutOfStr(ind, str) || str[ind] != '=') {
cout << "NA" << endl;
flg = false;
break;
}
}
if (!flg) continue;
if (!isOutOfStr(ind, str) && str[ind] == '~' && ind == str.length() - 1)
cout << "A" << endl;
else {
cout << "NA" << endl;
}
} else if (str[0] == '>' && str[1] == '^') {
int ind;
ind += 2;
int flg = true;
for (;; ind += 2) {
if (isOutOfStr(ind, str) || !(str[ind] == 'Q' && str[ind + 1] == '=')) {
break;
}
}
if (!isOutOfStr(ind, str) && !isOutOfStr(ind + 1, str) &&
str[ind] == '~' && str[ind + 1] == '~' &&
ind + 1 == str.length() - 1) {
cout << "B" << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
int num;
int i, j, k, l;
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
bodyacnt = 0;
bodybcnt = 0;
midcnt = 0;
endacnt = 0;
endbcnt = 0;
nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
break;
}
}
if (snake[0] == '>') {
if (snake[1] == '\'' && i % 2 == 0) {
for (j = 2; j < i / 2 + 1; j++) {
if (snake[j] == '=') {
bodyacnt++;
} else if (snake[j] == '#') {
break;
}
}
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 / 2; j += 2) {
if (snake[j] == 'Q' && snake[j + 1] == '=') {
bodybcnt++;
} else
nacnt++;
}
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;
bool isA(string s) {
int cnt1 = 0;
for (int i = 2; i < s.size(); ++i) {
if (s[i] == '=') {
++cnt1;
} else if (s[i] == '#') {
break;
} else {
return false;
}
if (i == s.size() - 1) return false;
}
int cnt2 = 0;
for (int i = cnt1 + 3; i < s.size(); ++i) {
if (s[i] == '=') {
++cnt2;
} else if (s[i] == '~') {
return (cnt1 == cnt2 && i == s.size() - 1);
} else {
return false;
}
}
return false;
}
bool isB(string s) {
if (s.size() % 2) return false;
for (int i = 2; i < s.size(); i += 2) {
if (s[i] == 'Q' && s[i + 1] == '=') {
continue;
} else if (s[i] == '~' && s[i + 1] == '~') {
return i + 1 == s.size() - 1;
} else {
return false;
}
}
return false;
}
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
for (int i = 0; i < n; ++i) {
if (s[i][0] != '>' || s[i].size() == 2) {
cout << "NA" << endl;
continue;
}
if (s[i][1] == '\'') {
cout << ((isA(s[i])) ? "A" : "NA") << endl;
} else if (s[i][1] == '^') {
cout << ((isB(s[i])) ? "B" : "NA") << endl;
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
string str;
bool check_A(string t) {
int cnt = 0, i = 0, cnt2 = 0;
while (t[i] == '=') {
cnt++;
i++;
}
if (t[i] != '#') return false;
if (cnt == 0) return false;
if ((int)t.size() == i) return false;
i++;
while (t[i] == '=') {
cnt2++;
i++;
}
if (cnt != cnt2) return false;
if ((int)t.size() != i + 1) return false;
if (t[i] != '~') return false;
return true;
}
bool check_B(string t) {
int i = 0;
while (i + 1 < (int)t.size() && t[i] == 'Q' && t[i + 1] == '=') {
i += 2;
}
if (i + 2 != (int)t.size()) return false;
if (t[i] == '~' && t[i + 1] == '~') return true;
return false;
}
int main() {
cin >> n;
while (n--) {
cin >> str;
if (str[0] == '>' && str[1] == '\'') {
if (check_A(str.substr(2))) {
cout << 'A' << endl;
} else {
cout << "NA" << endl;
}
} else if (str[0] == '>' && str[1] == '^') {
if (check_B(str.substr(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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, len, flag = 0, flag2 = 0, cnt1 = 0, cnt2 = 0;
char snake[10000][200];
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%s", snake[i]);
len = strlen(snake[i]);
if (snake[i][0] == '>' && snake[i][1] == '\'') {
for (int j = 2; j < len - 1; j++) {
if (snake[i][j] == '=' && flag == 0) {
cnt1++;
flag2 = 1;
}
if (snake[i][j] == '=' && flag == 1) {
cnt2++;
flag2 = 1;
}
if (snake[i][j] == '#') flag = 1;
}
if (snake[i][len - 1] == '~' && cnt1 == cnt2 && flag2 == 1)
cout << 'A' << endl;
else
cout << "NA" << endl;
flag = 0;
cnt1 = 0;
cnt2 = 0;
} else if (snake[i][0] == '>' && snake[i][1] == '^') {
for (int j = 2; j < len - 3; j++) {
if (snake[i][j] == 'Q' && snake[i][j + 1] == '=') flag = 1;
}
if (snake[i][len - 2] == '~' && snake[i][len - 1] == '~' && flag == 1)
cout << 'B' << endl;
else
cout << "NA" << endl;
} else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string str;
string kp;
string set;
int flag = 0;
int count = 0;
int i = 0;
cin >> str;
for (i = 0; i < 2; i++) kp += str[i]++;
if (kp == ">'") {
while (str[i] != '#') {
if (str[i] == '=')
count++;
else
flag = -1;
if (flag == -1) break;
i++;
}
i++;
while (str[i] != '~') {
if (str[i] == '=')
count--;
else
flag = -1;
if (flag == -1) break;
i++;
}
if (flag != -1 && !count) flag = 1;
count = 0;
for (int j = i; j < str.length(); j++) {
if (str[i] != '~')
flag = -1;
else
count++;
if (flag == -1) break;
}
if (count != 1) flag = -1;
} else if (kp == ">^") {
while (i < str.length() - 2) {
count = 2;
while (count--) {
set += str[i];
i++;
}
if (set == "Q=")
flag = 2;
else
flag = -1;
set.erase(set.begin(), set.end());
if (flag == -1) break;
}
for (i = str.length() - 2; i < str.length(); i++) set += str[i];
if (set == "~~" && flag == 2)
flag = 2;
else
flag = -1;
}
if (flag == 1)
cout << "A" << endl;
else if (flag == 2)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, size;
string s, a, b;
for (cin >> n, getline(cin, s, '\n'); n > 0; n--) {
getline(cin, s, '\n');
size = s.size();
if (size % 2) {
cout << "NA" << endl;
continue;
}
a = ">'";
b = ">^";
for (int i = 0; i < size / 2 - 2; i++) {
a = a + "=";
b = b + "Q=";
}
a += "#";
for (int i = 0; i < size / 2 - 2; i++) {
a = a + "=";
}
a += "~";
b += "~~";
if (s == a)
cout << "A" << endl;
else if (s == b)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
if (a.substr(0, 2) == ">'") {
int counter = 0;
bool hantei = false;
int i;
for (i = 2; i < a.size(); i++) {
if (a[i] == '=') {
counter++;
} else if (a[i] == '#') {
hantei = true;
break;
} else {
hantei = false;
break;
}
}
if (hantei) {
int j;
for (j = i + 1; j < a.size(); j++) {
if (a[j] == '=') {
counter--;
} else if (a[j] == '~') {
hantei = true;
break;
} else {
hantei = false;
break;
}
}
if (hantei) {
if (counter == 0 && j == a.size() - 1) {
cout << 'A' << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
} else if (a.substr(0, 2) == ">^") {
int i;
bool hantei = false;
for (i = 2; i < a.size() - 1; i += 2) {
if (a.substr(i, 2) == "Q=") {
} else if (a.substr(i, 2) == "~~" && i == a.size() - 2) {
hantei = true;
break;
} else {
hantei = false;
break;
}
}
if (hantei) {
cout << 'B' << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | class Ex(Exception):
pass
n=int(input())
for i in range(n):
try:
snk=input()
l=len(snk)
head=snk[:2]
body=snk[2:l-1]
tail=snk[l-1]
if tail!='~' or snk[0]!='>':
print("NA")
continue
spl_a=body.split('#')
if len(spl_a)==2 and spl_a[0]==spl_a[1]:
for char in spl_a[0]:
if char!='=':
print("NA")
raise Ex()
if head[1]=='\'':
print('A')
raise Ex()
else:
print("NA")
raise Ex()
bars=body.split('=')
for j in range(len(bars)-1):
if bars[j]!='Q':
print("NA")
raise Ex()
if head[1]=='^'and bars[len(bars)-1]=='~':print('B')
else:print("NA")
except Ex:pass |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
string s;
cin >> n;
while (n--) {
cin >> s;
if (s[0] == '>' && s[1] == '\'' && s.size() % 2 == 0) {
for (i = 2; i < s.size(); i++) {
if (i == s.size() / 2 && s[i] != '#') break;
if (i == s.size() / 2) {
i++;
continue;
}
if (i == s.size() - 1 && s[i] == '~') {
cout << "A" << endl;
goto L;
}
if (s[i] != '=') {
cout << i;
break;
}
}
} else if (s[0] == '>' && s[1] == '^' && s[2] == 'Q') {
for (i = 2; i < s.size(); i++) {
if (i == s.size() - 2 && s[i] == '~' && s[i + 1] == '~') {
cout << "B" << endl;
goto L;
}
if (s[i] != 'Q' || s[i + 1] != '=')
break;
else
i++;
}
}
cout << "NA" << endl;
L:;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int z = 0; z < n; z++) {
string a;
cin >> a;
string b = a.substr(0, 2), c = a.substr(a.length() - 2, 2);
if (b == ">'") {
if (c[1] == '~') {
int d[2] = {0, 0}, e = 0;
bool f = false;
for (int i = 2; i < a.length() - 1; i++) {
if (a[i] == '=') {
while (a[i] == '=') {
i++;
d[e]++;
if (i == a.length()) break;
}
e++;
}
if (a[i] == '#' && e == 1) {
f = true;
}
}
if (f == true && d[0] == d[1]) {
cout << "A" << endl;
goto stop;
}
}
}
if (b == ">^") {
if (c == "~~") {
for (int i = 2; i < a.length() - 2; i++) {
string d = a.substr(i, 2);
if (d == "Q=") {
cout << "B" << endl;
goto stop;
}
}
}
}
cout << "NA" << endl;
stop:;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main(int argc, const char* argv[]) {
int num;
int i, j, k, l;
char snake[200];
int bodyacnt = 0;
int bodybcnt = 0;
int midcnt = 0;
int endacnt = 0;
int endbcnt = 0;
int nacnt = 0;
scanf("%d", &num);
for (l = 0; l < num + 1; l++) {
bodyacnt = 0;
bodybcnt = 0;
midcnt = 0;
endacnt = 0;
endbcnt = 0;
nacnt = 0;
for (i = 0; i < 200; i++) {
scanf("%c", &snake[i]);
if (snake[i] == '\n') {
break;
}
}
if (snake[0] == '>') {
if (snake[1] == '\'' && i % 2 == 0) {
for (j = 2; j < i / 2 + 1; j++) {
if (snake[j] == '=') {
bodyacnt++;
} else if (snake[j] == '#') {
break;
} else
break;
}
for (k = j; k < i - 1; k++) {
if (snake[k] == '=') {
midcnt++;
}
}
if (snake[i - 1] == '~' && snake[i - 2] != '~') {
endacnt++;
}
} else if (snake[1] == '^' && i % 2 == 0) {
for (j = 2; j < i - 3; j += 2) {
if (snake[j] == 'Q' && snake[j + 1] == '=') {
bodybcnt++;
} else
nacnt = 1;
}
if (snake[i - 2] == '~' && snake[i - 1] == '~' && snake[i - 3] != '~') {
endbcnt++;
}
}
}
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 | UNKNOWN | char s[102],a[101],b[101],t,u,*p=s,l;B(){short*q;if(*(q=p++)=='^>'){for(;*(q=++p)=='=Q';p++)l++;if(l>0&&*(q=p++)=='~~'&&*++p==0)return 1;}return 0;}main(){scanf("%*d\n");for(;~scanf("%[^\n]\n",s);)puts(sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,&u)-3||t-'~'||strlen(a)-strlen(b)?B()?"B":"NA":"A");} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include<stdio.h>
int main(void){
char w[201];
int a,i,j,k;
a=getchar();
for(j=0;j<a;j++){
gets(w);
if(w[0]!='>'){printf("NA\n");goto la;}
if(w[1]=='\''){
int c;
for(i=2;w[i]!='#';i++){
if(w[i]!='='){printf("NA\n");goto la;}
c++;
}
i++;
for(k=0;k<c;k++){
if(w[i++]!='='){printf("NA\n");goto la;}
}
if(w[i++]!='~'){printf("NA\n");goto la;}
if(w[i]!='\0'){printf("NA\n");goto la;}
printf("A\n");
}
if(w[1]=='^'){
for(i=2;w[i]=='~';i+=2){
if(w[i]!='Q'){printf("NA\n");goto la;}
if(w[i+1]!='='){printf("NA\n");goto la;}
}
if(w[i]!='~'){printf("NA\n");goto la;}
if(w[i+1]!='~'){printf("NA\n");goto la;}
if(w[i+2]!='\0'){printf("NA\n");goto la;}
printf("B\n");
}
la:
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
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 || s.size() < 5) {
printf("NA\n");
continue;
}
if (s[k + 1] == '^') {
f = false;
for (int i = k; i + 1 < s.size(); i++)
if (s[i] == 'Q' && s[i + 1] == '=') f = true;
if (f && s[s.size() - 1] == '~' && s[s.size() - 2] == '~') {
printf("B\n");
continue;
}
}
int cnt = 0;
for (int i = k; i < s.size(); i++) {
if (s[i] == '=') {
while (s[i] == '=' && i < s.size()) {
cnt++;
i++;
}
k = i;
break;
}
}
f = false;
for (int i = k; i < s.size(); i++) {
if (s[i] == '#') {
k = i;
f = true;
}
}
if (f) {
for (int i = k; i < s.size(); i++) {
if (s[i] == '=') {
while (s[i] == '=' && i < s.size()) {
cnt--;
i++;
}
break;
}
}
if (cnt == 0 && s[s.size() - 1] == '~') {
printf("A\n");
continue;
}
}
printf("NA\n");
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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] > 0 && 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);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.