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 | java |
import java.util.*;
import java.util.regex.Pattern;
public class Main {
public void doIt(){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=0; i < n; i++){
String str = sc.next();
boolean result = Pattern.matches(">'(=+)#(=)+\\~", str);
if(result){
String str1 = str.replaceAll(">'(=+)#=+\\~", "$1");
String str2 = str.replaceAll(">'=+#(=+)\\~", "$1");
if(str1.length() == str2.length()){
System.out.println("A");
}
else{
System.out.println("NA");
}
}
else{
result = Pattern.matches(">\\^(Q=)+\\~\\~", str);
if(result)
System.out.println("B");
else
System.out.println("NA");
}
}
}
public static void main(String[] args) {
Main obj = new Main();
obj.doIt();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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--){
int i,eq1,eq2;
string ret = "NA";
string s; cin >> s;
if(s.substr(0,3) == ">'="){
i = 2;
eq1 = 0;
while(s[i] == '=' && i < s.length() )i++,eq1++;
if(s[i] != '#')goto label;
i++; eq2 = 0;
while(s[i] == '=' && i < s.length() )i++,eq2++;
if(i == s.length()-1 && s[i] == '~' && eq1 == eq2)
ret = "A";
}else if(s.substr(0,4) == ">^Q="){
for(i=2;i+1<s.length()-2;i+=2){
if(s[i] == 'Q' && s[i+1] == '='){}
else goto label;
}
if(s[s.length()-1] == '~' && s[s.length()-2] == '~' && s[s.length()-3] == '=' && s[s.length()-4] == 'Q')
ret = "B";
}
label:;
cout << ret << endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
//#include <fstream>
#define NA cout << "NA" << endl; goto LABEL
using namespace std;
int main() {
//ifstream fin("in.txt");
int snakeCount;
cin >> snakeCount;
for(int loopCount = 0; loopCount < snakeCount; loopCount++) {
char arr[202];
cin >> arr;
int i = 0;
if(arr[i]!='>') {
NA;
}
i++;
if(arr[i]=='\'') {
int equalCount = 0;
bool mode = false;
for(int j = i+1; j < 202; j++) {
if(arr[j]=='=') {
if(!mode) {
equalCount++;
}else {
equalCount--;
}
}else if(arr[j]=='#') {
if(!mode && equalCount>0) {
mode = !mode;
}else {
NA;
}
}else if(arr[j]=='~') {
if(arr[j+1]=='\0'&&equalCount==0&&mode) {
cout << "A" << endl;
goto LABEL;
}else {
NA;
}
}else {
NA;
}
}
}else if(arr[i]=='^') {
int count = 0;
for(int j = i+1; j < 202; j++) {
if(arr[j]=='Q'&&arr[j+1]=='=') {
j++;
count++;
continue;
}else if(arr[j]=='~'&&arr[j+1]=='~'&&arr[j+2]=='\0'&&count>0) {
cout<< "B" << endl;
goto LABEL;
}else {
NA;
}
}
}else {
NA;
}
LABEL:;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
bool isA( string& s )
{
int ptr = 0;
if( s.size() < 6 || s[ 0 ] != '>' || s[ 1 ] != '\'' || s[ s.size() - 1 ] != '~' ){
return false;
}
ptr = 2;
while( ptr < s.size() - 1 && s[ ptr ] == '=' ){
++ptr;
}
if( s[ ptr ] != '#' ){
return false;
}
int halfLength = ptr - 2;
if( s.size() != 4 + halfLength * 2 ){
return false;
}
++ptr;
for( int i = 0; i < halfLength; ++i, ++ptr ){
if( s[ ptr ] != '=' ){
return false;
}
}
return true;
}
bool isB( string& s )
{
int ptr = 0;
if( s.size() < 6 || s[ 0 ] != '>' || s[ 1 ] != '^' || s[ s.size() - 1 ] != '~' || s[ s.size() - 2 ] != '~' ){
return false;
}
int restLength = s.size() - 4;
if( restLength % 2 > 0 ){
return false;
}
ptr = 2;
while( ptr < restLength + 2 ){
if( s[ ptr ] != 'Q' || s[ ptr + 1 ] != '=' ){
return false;
}
ptr += 2;
}
return true;
}
int main()
{
int n;
while( cin >> n ){
for( int i = 0; i < n; ++i ){
string snake;
cin >> snake;
string result;
if( isA( snake ) ) result = "A";
else if( isB( snake ) ) result = "B";
else result = "NA";
cout << result << 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 <bits/stdc++.h>
using namespace std;
int main() {
int Tc; cin >> Tc;
while(Tc--) {
string S; cin >> S;
LA:
{
string s = S;
if(s.size() < 6) goto BAD;
if(s.substr(0, 3) != ">'=") goto LB;
if(s[s.size()-1] != '~') goto BAD;
s = s.substr(2);
s = s.substr(0,s.size()-1);
int pos = -1;
int const size = s.size();
int cnt = 0;
for(int i=0; i<size; i++) {
if(s[i] == '=') cnt++;
else if(s[i] == '#') { pos = i; break; }
else goto BAD;
}
if(pos == -1) goto BAD;
if(2*cnt+1 != s.size()) goto BAD;
for(int i=cnt+1; i<2*cnt+1; i++) {
if(s[i] != '=') goto BAD;
}
cout << "A" << endl; goto EXIT;
}
LB:
{
string s = S;
if(s.substr(0, 2) != ">^") goto BAD;
if(s.substr(s.size()-2) != "~~") goto BAD;
s = s.substr(2);
s = s.substr(0, s.size()-2);
if(s.size() % 2 || s.empty()) goto BAD;
int const size = s.size();
for(int i=0; i<size; i+=2) {
if(!(s[i] == 'Q' && s[i+1] == '=')) goto BAD;
}
cout << "B" << endl; goto EXIT;
}
BAD:;
cout << "NA" << endl;
EXIT:;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 | def snakeA(s):
if s.startswith(">'") and s.endswith("~"):
if s.count("#")==1:
t=s[2:-1].split("#")
if len(t)==2 and t[0]==t[1]:
if set(list(t[0]))==set(list(t[1]))==set(["="]):
return True
return False
def snakeB(s):
if s.startswith(">^") and s.endswith("~~"):
t=s[2:-2].split("Q=")
if len(t)>1 and set(t)==set([""]):
return True
return False
for i in range(input()):
s=raw_input()
if snakeA(s):
print "A"
elif snakeB(s):
print "B"
else:
print "NA" |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void){
int n;
cin>>n;
for (int i=0;i<n;i++) {
string s;
cin>>s;
if (s.size()<6||s.size()%2!=0){
cout<<"NA"<<endl;
} else {
if (s.at(0)=='>'&&s.at(1)=='\''&&s.at(s.size()-1)=='~') {
string tmp=s.substr(2,s.size()-3);
string front=tmp.substr(0,(tmp.size()-1)/2);
string back=tmp.substr((tmp.size()+2)/2,(tmp.size()-1)/2);
if (front==back) {
cout<<"A"<<endl;
} else {
cout<<"NA"<<endl;
}
} else if (s.at(0)=='>'&&s.at(1)=='^'&&s.at(s.size()-1)=='~'&&s.at(s.size()-2)=='~') {
string center=s.substr(2,s.size()-4);
for (int j=0;j<center.size();j+=2) {
if (center.at(j)!='Q'||center.at(j+1)!='=') {
cout<<"NA"<<endl;
break;
}
if (j==center.size()-2) {
cout<<"B"<<endl;
}
}
} else {
cout<<"NA"<<endl;
}
}
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#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 <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
int main(){
string hebi;
int n;
cin>>n;
while(n--){
cin>>hebi;
bool a=true,b=true;
if(hebi.size()<6 || hebi.size()%2){
a=false;
b=false;
}
rep(i,hebi.size()){
if(i==0 && hebi[i]=='>')continue;
if(i==1 && hebi[i]=='\'')continue;
if(i==hebi.size()-1 && hebi[i]=='~')continue;
else if(i>=2 && i<hebi.size()-1 && i!=hebi.size()/2 && hebi[i]=='=')continue;
else if(i==hebi.size()/2 && hebi[i]=='#')continue;
a=false;
}
rep(i,hebi.size()){
if(i==0 && hebi[i]=='>')continue;
if(i==1 && hebi[i]=='^')continue;
if(i==hebi.size()-1 && hebi[i]=='~')continue;
if(i==hebi.size()-2 && hebi[i]=='~')continue;
else if(i%2==0 && hebi[i]=='Q')continue;
else if(i%2==1 && hebi[i]=='=')continue;
b=false;
}
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": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
bool check(string s,int n) {
if (s.size() <= n)return true;
return false;
}
void solve() {
string s; cin >> s;
int n = 0;
if (s[n] == '>') {
n++;
if (check(s, n));
else if (s[n] == '\'') {
n++;
int cnt = 0;
while (s[n] == '=' && !check(s, n)) { cnt++; n++; }
if (s[n] == '#') {
n++;
if (check(s, n))goto exit;
else if (s[n] != '=')goto exit;
while (s[n] == '=' && !check(s, n)) { cnt--; n++; }
if (cnt == 0) {
if (s[n] == '~') {
n++;
if (n == s.size()) {
cout << "A\n";
return;
}
}
}
}
}
else if (s[n] == '^') {
n++;
if (check(s, n))goto exit;
bool b = false;
while (true) {
if (check(s, n + 1))goto exit;
else {
if (s[n] == 'Q'&&s[n + 1] == '=') { n += 2; b = true; }
else if (s[n] == '~'&&s[n + 1] == '~') {
if (b) {
cout << "B\n";
return;
}
else goto exit;
}
else goto exit;
}
}
n++;
if (check(s, n))goto exit;
if (s[n] == '~') {
n++;
if (check(s, n))goto exit;
if (s[n] == '~') {
n++;
if (n == s.size()) {
cout << "B\n";
return;
}
}
}
}
}
exit:;
cout << "NA\n";
return;
}
int main() {
int n; cin >> n;
for (int i = 0; i < n; i++)solve();
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;
typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;
template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
os << *it_i << ", ";
}
return os;
}
typedef set <string> SS;
SS SA;
SS SB;
bool checkA( string s ) {
return SA.count( s ) > 0;
}
bool checkB( string s ) {
return SB.count( s ) > 0;
}
string solve( string s ) {
if ( checkA( s ) ) return "A";
if ( checkB( s ) ) return "B";
return "NA";
}
int main() {
for ( int i = 1; i <= 100; ++ i ) {
SA.insert( ">'" + string( i, '=' ) + "#" + string( i, '=' ) + "~" );
}
for ( int i = 1; i <= 100; ++ i ) {
VS con( i, "Q=" );
SB.insert( ">^" + accumulate( con.begin(), con.end(), string() ) + "~~" );
}
int n;
cin >> n;
for ( int i = 0; i < n; ++ i ) {
string s;
cin >> s;
cout << solve( s ) << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
bool kind_a(string str){
if(str[0] != '>' || str[1] != '\'' || str[str.size()-1] != '~'){
return false;
}
string su = str.substr(2, str.size()-3);
if(su.size()<3)
return false;
for(int i=0; i<su.size(); ++i){
int j = su.size()-1-i;
if(i>=j)
break;
if(su[i]!='=' || su[i]!=su[j]){
return false;
}
}
return su[(su.size()-1)/2]=='#';
}
bool kind_b(string str){
if(str[0] != '>' || str[1] != '^' ||
str[str.size()-2] != '~' || str[str.size()-1] != '~'){
return false;
}
string su = str.substr(2, str.size()-4);
if(su.size()<2)
return false;
for(int i=0; i<su.size(); ++i){
int j = su.size()-1-i;
if(i>=j)
break;
if( !(su[i]=='Q' && su[j]=='=' || su[j]=='Q' && su[i]=='=') ){
return false;
}
}
return true;
}
string solve(string str){
if(kind_a(str)){
return "A";
}
else if(kind_b(str)){
return "B";
}
else{
return "NA";
}
}
int main(){
int n;
cin>>n;
while(n--){
string str;
cin>>str;
cout << solve(str) << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | // 2011/10/02 Tazoe
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
for(int i=0; i<n; i++){
string str;
cin >> str;
if(str[0]!='>'){
cout << "NA" << endl;
continue;
}
if(str[1]=='\''){
int N = 0;
int I = 2;
while(str[I]=='='){
N++;
I++;
}
if(N==0){
cout << "NA" << endl;
continue;
}
if(str[I]!='#'){
cout << "NA" << endl;
continue;
}
I++;
int M = 0;
while(str[I]=='='){
M++;
I++;
}
if(N!=M){
cout << "NA" << endl;
continue;
}
if(!(str[I]=='~'&&I+1==str.size())){
cout << "NA" << endl;
continue;
}
cout << "A" << endl;
}
else if(str[1]=='^'){
int N = 0;
int I = 2;
while(str[I]=='Q'&&str[I+1]=='='){
N++;
I += 2;
}
if(N==0){
cout << "NA" << endl;
continue;
}
if(!(str[I]=='~'&&str[I+1]=='~'&&I+2==str.size())){
cout << "NA" << endl;
continue;
}
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": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int main()
{
int n,f,i,m;
string s;
cin>>n;
while(n-->0){
cin>>s;
f=0;
if(s[0]=='>' && s[1]=='\''){
m=s.find('#');
if(m!=string::npos){
for(i=1;s[m-i]==s[m+i];)i++;
if(i>1 && m-i==1 && m+i==s.size()-1 && s[m+i]=='~')f=1;
}
}else if(s[0]=='>' && s[1]=='^'){
for(i=2;s[i]=='Q'&&s[i+1]=='=';)i+=2;
if(i>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": []
} | CORRECT | cpp |
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#define int long long
#define rep(i, n) for (int i=0; i<n; i++)
#define REP(n) rep(i, n)
using namespace std;
int n;
string snake, head, tail, body;
signed main()
{
cin >> n;
REP(n)
{
cin >> snake;
if (snake.length() < 6)
{
cout << "NA" << endl;
continue;
}
head = snake.substr(0, 2);
if (head == ">'")
{
tail = snake.substr(snake.length() - 1, 1);
if (tail != "~")
{
cout << "NA" << endl;
continue;
}
body = string((snake.length() - 4) / 2, '=') + "#" + string((snake.length() - 4) / 2, '=');
if (snake.substr(2, snake.length() - 3) == body)
{
cout << "A" << endl;
continue;
} else {
cout << "NA" << endl;
continue;
}
} else if (head == ">^") {
tail = snake.substr(snake.length() - 2, 2);
if (tail != "~~")
{
cout << "NA" << endl;
continue;
}
body = "";
int cnt = (snake.length() - 4) / 2;
while (cnt--) body += "Q=";
if (snake.substr(2, snake.length() - 4) == body)
{
cout << "B" << endl;
continue;
} else {
cout << "NA" << endl;
continue;
}
} else {
cout << "NA" << endl;
continue;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#include <cstdio>
using namespace std;
enum { A, B, NA };
int f(string s){
if(s.size() < 6) return NA;
if(s.substr(0,2)==">'"){
size_t i=2;
while(i<s.size() && s[i]=='=') i++;
if(i==2 || i==s.size() || s[i]!='#') return NA;
size_t j=i+1;
while(j<s.size() && s[j]=='=') j++;
if(i-2 != j-i-1 || j==s.size() || s[j]!='~') return NA;
return (j+1==s.size() && s[j]=='~') ? A : NA;
} else if(s.substr(0,2)==">^"){
size_t i=2;
while(i<s.size() && s[i]=="Q="[i&1]) i++;
if((i&1)==1 || i==2 || i==s.size() || s[i]!='~') return NA;
return (i+2==s.size() && s.substr(i)=="~~") ? B : NA;
} else {
return NA;
}
}
int main(){
int n;
cin >> n;
for(int i=0;i<n;i++){
string s;
cin >> s;
char res[3][3] = {"A","B","NA"};
puts(res[f(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 | cpp | #include <iostream>
#include <string>
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 && str.size() >= 6){a = true;}
if(str[0] == '>' && str[1] == '^' && str.size()%2==0 && str.size() >= 6){b = true;}
if(a){
for(unsigned j=2;j<str.size()-1;j++){
if(j != (str.size()/2) && str[j] != '='){
a = false;
break;
}
}
if(str[str.size()/2] != '#' || str[str.size()-1] != '~')
a=false;
}
if(b){
for(unsigned j=2;j<str.size()-3;j+=2){
if(str[j] != 'Q' || str[j+1] != '='){
b = false;
break;
}
}
if(str[str.size()-2] != '~' || str[str.size()-1] != '~')
b=false;
}
if(a)
cout << "A" << endl;
else if(b)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int checkA(string);
int checkB(string);
int main(){
int i, n;
string snake;
cin >> n;
for(i=0; i<n; ++i){
cin >> snake;
if(checkA(snake) == 1)
cout << "A" << endl;
else if(checkB(snake) == 1)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
int checkA(string snake){
int i, j, count1=0, count2=0;
if(snake[0] != '>' || snake[1] != '\'' || snake[2] != '=') return 0;
for(i=2; snake[i] == '='; ++i) ++count1;
if(snake[count1 + 2] != '#') return 0;
for(j=count1+3; snake[j] == '='; ++j) ++count2;
if(count1 != count2 || j != snake.size()-1 || snake[snake.size()-1] != '~') return 0;
return 1;
}
int checkB(string snake){
int i;
if(snake[0] != '>' || snake[1] != '^' || snake[2] != 'Q' || snake[3] != '=') return 0;
for(i=2; i < snake.size()-2; i+=2){
if(snake[i] != 'Q' || snake[i+1] != '=') return 0;
}
if(snake[snake.size()-2] != '~' || snake[snake.size()-1] != '~') return 0;
return 1;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main(){
int n;
cin>>n;
REP(t,n){
string s;
cin>>s;
if(s[0]!='>')goto na;
if(s[1]=='\''){
int state=0;
int cnt1=0;
int cnt2=0;
FOR(i,2,s.size()){
if(s[i]=='='&&state==0){
cnt1++;
}else if(s[i]=='#'&&state==0){
state=1;
}else if(s[i]=='='&&state==1){
state=2;
cnt2++;
}else if(s[i]=='='&&state==2){
cnt2++;
}else if(s[i]=='~'&&state==2){
state=3;
}else{
state=-1;
break;
}
}
if(state==3&&cnt1==cnt2){
goto a;
}else{
goto na;
}
}else if(s[1]=='^'){
int state=0;
int flag=0;
FOR(i,2,s.size()){
if(s[i]=='Q'&&state==0){
state=1;
}else if(s[i]=='='&&state==1){
state=0;
flag=1;
}else if(s[i]=='~'&&state==0){
state=2;
}else if(s[i]=='~'&&state==2){
state=3;
}else{
state=-1;
break;
}
}
if(state==3&&flag){
goto b;
}else{
goto na;
}
}else{
goto na;
}
a:
cout<<"A"<<endl;
continue;
b:
cout<<"B"<<endl;
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": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
string str;
int n; cin >> n;
while(n--){
cin >> str;
int idx = 2;
int cnt = 0;
bool flg = true;
if(str[0] == '>' && str[1] == 39){
bool used = false;
while(idx < str.size() && str[idx] == '=') {
used = true;
cnt++;
idx++;
}
if(str[idx] == '#'){
idx++;
while(idx < str.size() && str[idx] == '=') {
cnt--;
idx++;
}
}
if(str[idx] == '~' && cnt == 0 && used) {
cout << "A" << endl;
flg = false;
}
} else if(str[0] == '>' && str[1] == '^'){
while(idx+1 < str.size() && str[idx] == 'Q' && str[idx+1] == '='){
idx += 2;
cnt++;
}
if(cnt > 0 && str[idx] == '~' && str[idx+1] == '~') {
cout << "B" << endl;
flg = false;
}
}
if(flg) cout << "NA" << endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main(void) {
cin >> n;
for (int k = 0; k < n; k++) {
cin >> s;
bool f = true;
if (s[0] == '>' && s[1] == '\'') {
int c = 0;
int i;
for (i = 2; s[i] == '='; i++)
c++;
if (c && s[i] == '#') {
for (i += 1; s[i] == '='; i++)
c--;
if (!c && (int) s.size() == i + 1 && s[i] == '~') {
cout << 'A' << endl;
f = false;
}
}
} else if (s[0] == '>' && s[1] == '^' && s[2] == 'Q' && s[3] == '=') {
int i;
for (i = 4; s[i] == 'Q' && s[i + 1] == '='; i += 2)
;
if ((int) s.size() == i + 2 && s[i] == '~' && s[i + 1] == '~') {
cout << 'B' << endl;
f = false;
}
}
if (f) {
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 | cpp | #include<stdio.h>
#include<string.h>
int n,len;
char t[300];
int checkA(){
if(t[len-1]!='~')return 0;
int i=2,j=len-2;
while(i<j){
if(t[i]!='=')return 0;
if(t[j]!='=')return 0;
i++;
j--;
}
if(t[i]=='#')return 1;
else return 0;
}
int checkB(){
if(t[len-2]!='~')return 0;
if(t[len-1]!='~')return 0;
int i;
for(i=2;i<len-2;i+=2){
if(t[i]!='Q')return 0;
if(t[i+1]!='=')return 0;
}
return 2;
}
int solve(){
if(len<6 || len%2==1)return 0;
if(t[0]=='>'&&t[1]=='\'')return checkA();
if(t[0]=='>'&&t[1]=='^')return checkB();
return 0;
}
int main(){
scanf("%d",&n);
while(n>0){
n--;
scanf("%s",t);
len=strlen(t);
int ans=solve();
if(ans==0)printf("NA\n");
if(ans==1)printf("A\n");
if(ans==2)printf("B\n");
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java |
import java.io.*;
import java.util.*;
// 2011/10/23
// 0139 Snakes
public class Main {
// C return falseŨµÜ¢
boolean main() throws IOException {
String s = reader.readLine();
String type = "NA";
String regA = ">'(=+)#(=+)\\~";
if (s.matches(regA)) {
if (s.replaceAll(regA, "$1").equals(s.replaceAll(regA, "$2")))
type = "A";
}
else if (s.matches(">\\^(Q=)+\\~\\~")) {
type = "B";
}
System.out.printf("%s\n", type);
return true; // ³íI¹ Ö
}
// private final static boolean DEBUG = true; // debug
private final static boolean DEBUG = false; // release
public static void main(String[] args) throws IOException {
if (DEBUG) {
log = System.out;
String inputStr = "1:>'======#======~:";
inputStr = inputStr.replace(":", "\n");
reader = new BufferedReader(new StringReader(inputStr));
}
else {
log = new PrintStream(new OutputStream() { public void write(int b) {} } ); // «ÌÄ
reader = new BufferedReader(new InputStreamReader(System.in)); // R\[©ç
}
int N = readIntArray()[0];
for(int i = 0; i < N; i++) {
boolean b = new Main().main();
if (!b)
break;
}
reader.close();
}
static PrintStream log;
static BufferedReader reader;
// WüÍæè1sªÌæØè¶æØèÅÌ®lðÇÞ
// EOFÌêÍnullðÔ·
private static int[] readIntArray() throws IOException {
String s = null;
for(;;) {
s = reader.readLine();
// log.printf("%s\n", s);
if (s == null)
return null;
s = s.trim();
if (s.length() != 0) // ¦¦¦@ǤàËRósðÇޱƪ éBÇÝòηƤܢ絢BBBB
break;
}
String[] sp = s.split("[ ,]"); // æØè¶ÍXy[X©J}
int[] a = new int[sp.length];
for(int i = 0; i < sp.length; i++) {
a[i] = Integer.parseInt(sp[i]);
}
return 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 | java | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws java.io.IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String snake;
bf.readLine();
while ((snake = bf.readLine()) != null) {
String ans = isSnakeA(snake) ? "A" : isSnakeB(snake) ? "B" : "NA";
System.out.println(ans);
}
}
private static boolean isSnakeA(String snake) {
String sa = "^>'(=+)#\\1~$";
Pattern pa = Pattern.compile(sa);
Matcher ma = pa.matcher(snake);
return ma.matches();
}
private static boolean isSnakeB(String snake) {
String sb = "^>\\^(Q=)+~~$";
Pattern pb = Pattern.compile(sb);
Matcher mb = pb.matcher(snake);
return mb.matches();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 <string>
#include <iostream>
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;
int r = check();
if(r == 0) cout << "NA" << endl;
if(r == 1) cout << "A" << endl;
if(r == 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": []
} | CORRECT | cpp | #include <stdio.h>
bool checkA(char *p){
int eqCnt=0;
if (*p++!='>') return false;
if (*p++!='\'') return false;
if (*p!='=') return false;
while (*p++=='=') eqCnt++;
p--;
if (*p++!='#') return false;
while (*p++=='=') eqCnt--;
p--;
if (eqCnt!=0) return false;
if (*p++!='~') return false;
if (*p!='\0') return false;
return true;
}
bool checkB(char *p){
if (*p++!='>') return false;
if (*p++!='^') return false;
if (*p!='Q') return false;
while (*p++=='Q'){
if (*p++!='=') return false;
}
p--;
if (*p++!='~' || *p++!='~') return false;
if (*p!='\0') return false;
return true;
}
int main(void){
int n;
char str[256];
scanf("%d", &n);
for (int i=0; i<n; i++){
scanf("%s", str);
if (checkA(str)){
puts("A");
} else if (checkB(str)){
puts("B");
} else {
puts("NA");
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
int main(){
int n;
string s;
cin >> n;
for(int i = 0;i < n;i++){
cin >> s;
if(s.substr(0,2) == ">\'"){
if(s[s.length() - 1] != '~') cout << "NA" << endl;
else {
int cnt = 0,pos = 2;
bool flag = true;
for(;;pos++){
if(s[pos] == '#') break;
if(s[pos] == '=') cnt++;
else {
flag = false;
break;
}
}
if(!flag || !cnt) cout << "NA" << endl;
else{
pos++;
for(int j = 0;j < cnt;j++){
if(s[pos + j] != '='){
flag = false;
break;
}
}
if(s[pos + cnt] != '~') flag = false;
if(!flag) cout << "NA" << endl;
else cout << "A" << endl;
}
}
}else if(s.substr(0,2) == ">^"){
if(s.length() % 2 || s.length() <= 4) cout << "NA" << endl;
else {
bool flag = true;
for(int i = 1;i < s.length() / 2;i++){
if(i != s.length() / 2 - 1 && s.substr(i * 2,2) != "Q=") flag = false;
if(i == s.length() / 2 - 1 && s.substr(i * 2,2) != "~~") flag = false;
}
if(flag) cout << "B" << endl;
else cout << "NA" << endl;
}
}else cout << "NA" << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | 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;
int cnt = 0;
for (int i = 2; i < s.size(); i += 2) {
if (s[i] == 'Q' && s[i + 1] == '=') {
++cnt;
} else if (s[i] == '~' && s[i + 1] == '~') {
return (i + 1 == s.size() - 1) && cnt;
} 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": []
} | CORRECT | python2 | for i in range(input()):
s = raw_input()
l = (len(s) - 4) / 2
if l > 0 and s == ">'%s#%s~" % (('=' * l,) * 2):
print('A')
elif l > 0 and s == '>^%s~~' % ('Q=' * l):
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 | java | import java.util.Scanner;
public class Main
{
public static void main(String arg[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
while(n-->0)
{
char ch[] = in.next().toCharArray();
int counta =0;
int countb =0;
boolean flag=false;
if(ch[0]=='>'&&ch[1]=='\'' &&ch[ch.length-1]=='~'&&ch[ch.length-2]=='=')
{
int co=2;
while(ch[co]!='#')
{
if(ch[co]=='=')
counta++;
else
{
counta=0;
break;
}
co++;
if(co==ch.length-1)
break;
}
co++;
while(ch[co]!='~')
{
if(ch[co]=='=')
countb++;
else
{
counta=0;
break;
}
co++;
}
if(counta==countb&&counta>0)
System.out.println("A");
else
System.out.println("NA");
continue;
}
else
if(ch[0]=='>'&&ch[1]=='^' &&ch[ch.length-1]=='~'&&ch[ch.length-2]=='~')
{
for(int co=2;co<ch.length-2;co+=2)
{
if(ch[co]=='Q'&&ch[co+1]=='=')
flag = true;
else
{
flag = false;
break;
}
}
}
System.out.println(flag==true ? "B":"NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java |
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeMap;
public class Main {
static PrintWriter out = new PrintWriter(System.out);
static FastScanner sc = new FastScanner();
static Scanner stdIn = new Scanner(System.in);
static TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
public static void main(String[] args) {
int n = sc.nextInt();
for(int i = 0; i < n; i++) {
char[] in = sc.next().toCharArray();
int res = solv(in);
if(res == 0) {
out.println("A");
}
else if(res == 1) {
out.println("B");
}
else {
out.println("NA");
}
}
out.flush();
}
static int solv(char[] a) {
if(a.length < 6) return -1;
boolean isA = false;
boolean isB = false;
if(a[0] == '>' && a[1] == '\'') {
isA = true;
}
if(a[0] == '>' && a[1] == '^') {
isB = true;
}
if(!isA && !isB) return -1;
if(isA) {
int ac = 0;
int bc = 0;
boolean nowb = true;
for(int i = 2; i < a.length-1; i++) {
if(a[i] == '=' && nowb) {
ac++;
}
else if(a[i] == '=' && !nowb) {
bc++;
}
else if(a[i] == '#' && nowb) {
nowb = false;
}
else {
return -1;
}
}
if(ac != bc || nowb) return -1;
if(a[a.length-1] == '~') return 0;
}
if(isB) {
for(int i = 2; i < a.length-2; i+=2) {
if(a[i] != 'Q' || a[i+1] != '=' ) return -1;
}
if(a[a.length-1] == '~' && a[a.length-2] == '~') return 1;
}
return -1;
}
}
//------------------------------//
//-----------//
class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
public boolean hasNext() { skipUnprintable(); return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b)){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
if (!hasNext()) throw new NoSuchElementException();
int n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b)){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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;
import java.util.Scanner;
public class Main {
enum State{
START, MOUTH, EYE_A, EYE_B, BODY_A1, BODY_A2, BODY_B1, BODY_B2, MID_A, TAIL_A, TAIL_B1, TAIL_B2, NA;
}
String snake(String s){
State state=State.START;
int length=0;
LOOP:
for(int i=0;i<s.length();++i){
char next=s.charAt(i);
switch(state){
case START:
if(next=='>') state=State.MOUTH;
else state=State.NA;
break;
case MOUTH:
if(next=='\'') state=State.EYE_A;
else if(next=='^') state=State.EYE_B;
else state=State.NA;
break;
case EYE_A:
if(next=='='){
state=State.BODY_A1;
length=0;
}
else state=State.NA;
break;
case BODY_A1:
++length;
if(next=='=') state=State.BODY_A1;
else if(next=='#') state=State.MID_A;
else state=State.NA;
break;
case MID_A:
if(next=='=') state=State.BODY_A2;
else state=State.NA;
break;
case BODY_A2:
--length;
if(next=='=') state=State.BODY_A2;
else if(next=='~'&&length==0) state=State.TAIL_A;
else state=State.NA;
break;
case EYE_B:
if(next=='Q') state=State.BODY_B1;
else state=State.NA;
break;
case BODY_B1:
if(next=='=') state=State.BODY_B2;
else state=State.NA;
break;
case BODY_B2:
if(next=='Q') state=State.BODY_B1;
else if(next=='~') state=State.TAIL_B1;
else state=State.NA;
break;
case TAIL_B1:
if(next=='~') state=State.TAIL_B2;
else state=State.NA;
break;
default:
break LOOP;
}
}
switch(state){
case TAIL_A:
return "A";
case TAIL_B2:
return "B";
default:
return "NA";
}
}
BufferedReader input;
int ni() throws NumberFormatException, IOException{
return Integer.parseInt(input.readLine());
}
String ns() throws IOException{
return input.readLine();
}
void io(){
input=new BufferedReader(new InputStreamReader(System.in));
try {
int n=ni();
for(int i=0;i<n;++i){
System.out.println(snake(ns()));
}
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main().io();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
bool check_A( string &S )
{
auto sz = S.size();
//size ??? 6 ??\?????????????????? false
if( sz < 6 )
{
return 0;
}
//?????????[>'=], ????°????[~]?????????????????´?????? false
if( S[ 0 ] != '>' || S[ 1 ] != '\'' || S[ 2 ] != '=' || S[ sz - 1 ] != '~' )
{
return 0;
}
//??????[>']??¨????°?[~]???????????????
string R = S.substr( 2, sz - 3 );
sz = R.size();
//R ???[#,=]??\???????????????????????????????????? false
if( R.find_first_not_of( "#=", 0 ) != string::npos )
{
return 0;
}
if( sz % 2 == 0 )
{
return 0;
}
//R ?????????????????????????????£???[#]???????????\??????[#]????????£?????? false
auto pos = R.find( "#" );
if( R.find( "#", pos + 1 ) != string::npos )
{
return 0;
}
// S ???????????????[#]???????????£?????? false
if( R[ sz / 2 ] != '#' )
{
return 0;
}
return 1;
}
bool check_B( string &S )
{
auto sz = S.size();
//size ??? 6 ??\?????????????????? false
if( sz < 6 )
{
return 0;
}
//?????????[>^], ????°????[~~]?????????????????´?????? false
if( S[ 0 ] != '>' || S[ 1 ] != '^' || S[ sz - 1 ] != '~' || S[ sz - 2 ] != '~' )
{
return 0;
}
string R = S.substr( 2, sz - 4 );
sz = R.size();
// S ???size????\???°?????£?????? false
if( sz % 2 != 0 )
{
return 0;
}
for( int i = 0; i < sz; i += 2 )
{
//[Q=]?????£?¶???§????????£?????? false
if( R[ i ] != 'Q' || R[ i + 1 ] != '=' )
{
return 0;
}
}
return 1;
}
int main()
{
int N;
cin >> N;
REP( i, N )
{
string S;
cin >> S;
string res{ "NA" };
if( check_A( S ) )
{
res = "A";
}
else if( check_B( S ) )
{
res = "B";
}
cout << res << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
using namespace std;
/*s[i]ツつゥツづァツ督ッツつカツ閉カツ篠堋つェツ連ツ堕アツつオツづつ「ツづゥツ青板づーツ陛板つキ*/
int seqlen(string &s,int i){
char c = s[i];
int ret=0;
while(s[i++]==c)ret++;
return ret;
}
int main(){
int n;
int flag = 0;
string s;
cin >> n;
while(n--){
flag = 0;
cin >> s;
/*A*/
if(s[0]=='>' && s[1]==39){
int x=2;
x += seqlen(s,x);
if(s[x]!='#')flag = 1;
x ++ ;
if(seqlen(s,2) != seqlen(s,x))flag = 1;
x += seqlen(s,x);
if(s[x]!='~')flag = 1;
if(!flag)flag='A';
}
else if(s[0]=='>' && s[1]=='^'){
int pointa = 0;
for(int i=2;i<s.length()-2;i++){
if(i%2){
if(s[i] != '=')flag = 1;
else pointa++;
}else{
if(s[i] != 'Q')flag = 1;
else pointa++;
}
}
if(s[s.length()-2] != '~' || s[s.length()-1] != '~')flag = 1;
if(!flag && pointa>=2)flag='B';
else flag = 1;
}
else {flag = 1;}
if(flag != 1)cout << (char)flag << 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 | python3 | import re
n=int(input())
def A(snake):
r=re.match("^>\'(\=+)\#(\=+)\~$",snake)
if r:
if len(r.group(1))==len(r.group(2)):
return True
return False
def B(snake):
r=re.match("^\>\^(Q=)+\~\~$",snake)
if r:
return True
return False
for i in range(n):
S=input()
if A(S):
print("A")
elif B(S):
print("B")
else:
print("NA")
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
const int INF = 10000000;
using namespace std;
typedef long long ll;
/** Problem0139 : Snakes **/
int main()
{
int n;
string s;
cin >> n;
rep(k, n) {
cin >> s;
REP(i, 1, 100) {
string a=">'", b=">^";
rep(j, i) {
a+='=';
b+="Q=";
}
a+='#';
rep(j, i)
a+='=';
a+='~';
b+="~~";
if (s == a) {
cout << "A" << endl;
goto end;
} else if (s == b) {
cout << "B" << endl;
goto end;
}
}
cout << "NA" << endl;
end:;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
string s;
for (int i=0; i<n; ++i) {
cin >> s;
int m = s.size();
string res = "NA";
if (s.size() < 6 || s.size() % 2 == 1) {
// pass
} else if (s.substr(0,2) == ">'" && s[m-1] == '~') {
res = "A";
if (s[m/2] != '#') {
res = "NA";
}
for (int j=2; j<=m-2; ++j) {
if (j == m/2) continue;
if (s[j] != '=') {
res = "NA";
break;
}
}
} else if (s.substr(0,2) == ">^" && s.substr(m-2,2) == "~~") {
res = "B";
for (int j=2; j<=m-4; j+=2) {
if (s[j] != 'Q' || s[j+1] != '=') {
res = "NA";
break;
}
}
}
cout << res << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;
bool isA(const string &str){
int n = str.size();
int m = 0;
int pos = 2;
if(n == 0 || n==1) return false;
if(str[0] != '>') return false;
if(str[1] != '\'') return false;
while(pos < n && str[pos] == '=') {m++; pos++;}
if(pos == n || m == 0) return false;
if(str[pos++] != '#') return false;
while(pos < n && str[pos] == '=') {m--; pos++;}
if(pos == n) return false;
if(str[pos++] != '~') return false;
if(m == 0 && pos == n) return true;
return false;
}
bool isB(const string &str){
int n = str.size();
int pos = 2;
int m = 0;
if(n == 0 || n == 1) return false;
if(str[0] != '>') return false;
if(str[1] != '^') return false;
while(pos+1 < n && str[pos] == 'Q' && str[pos+1] == '=') {m++; pos+=2;}
if(m == 0) return false;
if(pos+2 != n) return false;
if(str[pos] == '~' && str[pos+1] == '~') return true;
return false;
}
int main(){
int n;
string str;
getline(cin,str); sscanf(str.c_str(),"%d",&n);
while(n --> 0){
getline(cin,str);
if(isA(str)) puts("A");
else if(isB(str)) puts("B");
else puts("NA");
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | 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 and len(t[0])>0:
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)>0 and 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": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n, len;
string s;
int checkA() {
int i=2, j=len-2;
while(i<j) {
if(s[i] != '=' || s[j] != '=') return 0;
i++; j--;
}
if(s[i] == '#' && s[len-1] == '~') return 1;
return 0;
}
int checkB() {
if(s[len-1]!='~' || s[len-2]!='~') return 0;
for(int i=2; i<len-2; i+=2) {
if(s[i] != 'Q' || s[i+1] != '=') return 0;
}
return 2;
}
int solve() {
if(len<6 || len%2 == 1) return 0;
if(s[0] == '>' && s[1] == '\'') return checkA();
if(s[0] == '>' && s[1] == '^') return checkB();
return 0;
}
int main() {
cin>> n;
while(n--) {
cin>> s;
len = s.size();
int ans = solve();
if(ans == 0) cout<< "NA";
if(ans == 1) cout<< 'A';
if(ans == 2) cout<< 'B';
cout<< endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
void jagdeA( const string& str )
{
int count = 0;
int i;
for( i = 2;i < str.size();i++ ){
if( str[i] == '=' ) count++;
else if( count && str[i] == '#' ) break;
else{
cout << "NA" << endl;
return;
}
}
if( i == str.size() ){
cout << "NA" << endl;
return;
}
i++;
for(; i < str.size(); i++ ){
if( str[i] == '=' ) count--;
else if( str[i] == '~' ) break;
else{
cout << "NA" << endl;
return;
}
}
if( count || i == str.size() ) {
cout << "NA" << endl;
return;
}
cout << "A" << endl;
return;
}
void jagdeB( const string& str )
{
int count = 0;
int i;
for( i = 2;i < str.size();i += 2 ){
if( i + 1 >= str.size() ){
cout << "NA" << endl;
return;
}
if( str[i] == 'Q' && str[i + 1] == '=' ){
count++;
} else if( str[i] == '~' && str[i + 1] == '~' && count ){
cout << "B" << endl;
return;
} else {
cout << "NA" << endl;
return;
}
}
cout << "NA" << endl;
return;
}
int main(int argc, char const* argv[])
{
int n;
string str;
cin >> n;
for( int i = 0;i < n;i++ ){
cin >> str;
if( str.size() < 6 || str[0] != '>' ){
cout << "NA" << endl;
continue;
}
switch( str[1] ){
case '\'':
jagdeA( str );
break;
case '^':
jagdeB( str );
break;
default:
cout << "NA" << endl;
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": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std ;
string S ;
int funcA(){
int cnt = 0 , i ;
for( i=2 ; i<S.size() ; i++ ){
if( S[i] == '=' ) cnt++ ;
else if( S[i] == '#' ) break ;
else return -1 ;
}
if( cnt == 0 ) return -1 ;
for( i++ ; i<S.size() ; i++ ){
if( S[i] == '=' ) cnt-- ;
else if( S[i] == '~' ) break ;
else return -1 ;
}
if( cnt == 0 ) return 1 ;
return -1 ;
}
int funcB(){
int cnt = 0 ;
for( int i=2 ; i<S.size() ; i+=2 ){
if( S[i] == 'Q' && S[i+1] == '=' ) cnt++ ;
else if( S[i] == '~' && S[i+1] == '~' && cnt ) return 2 ;
else return -1 ;
}
return -1 ;
}
int main(){
int N ;
cin >> N ;
while( N-- ){
cin >> S ;
int ans = -1 ;
if( S.size() < 6 || S.size()%2 == 1 ){}
else if( S[0] == '>' && S[1] == '\'' ){ ans = funcA() ; }
else if( S[0] == '>' && S[1] == '^' ){ ans = funcB() ; }
if( ans == -1 ) cout << "NA" << endl ;
if( ans == 1 ) cout << "A" << endl ;
if( ans == 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": []
} | CORRECT | java | import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args){
try{
new Main();
}catch(IOException e){
e.printStackTrace();
}
}
public Main() throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
List<String> Ans = new ArrayList<String>();
String line = in.readLine();
int size = Integer.parseInt(line);
for(int n=0; n<size; n++){
line = in.readLine();
int type = 0;
String c = line.substring(0, 2);
if(c.equals(">'")){
int count = 0;
int sharp = 0;
for(int i=2; i<line.length(); i++){
c = line.substring(i, i+1);
if(c.equals("=")){
count++;
}
else if(c.equals("#")){
if(count > 0){
count = -count;
sharp = 1;
}
else{
type = -1;
break;
}
}
else if(c.equals("~")){
if(i != line.length()-1){
type = -1;
break;
}
if(count==0 && sharp==1){
type = 1;
break;
}
else{
type = -1;
break;
}
}
else{
type = -1;
break;
}
}
}
else if(c.equals(">^")){
int count = 0;
for(int i=2; i<line.length(); i++){
c = line.substring(i, i+1);
if(count%2==0 && count>=2 && c.equals("~")){
if(i==line.length()-1){
type = -1;
break;
}
c = line.substring(i+1, i+2);
if(c.equals("~")){
type = 2;
break;
}
else{
type = -1;
break;
}
}
if(i%2==0){
if(!c.equals("Q")){
type = -1;
break;
}
count++;
}
if(i%2==1){
if(!c.equals("=")){
type = -1;
break;
}
count++;
}
if(!c.equals("Q") && !c.equals("=") && !c.equals("~")){
type = -1;
break;
}
}
}
else{
type = -1;
}
switch(type){
case 1:
Ans.add("A");
break;
case 2:
Ans.add("B");
break;
default:
Ans.add("NA");
}
}
for(int n=0; n<Ans.size(); n++){
System.out.println(Ans.get(n));
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
bool isA(const string& s){
if( s.size() >= 1 && s[0] != '>' ) return false;
if( s.size() >= 2 && s[1] != '\'' ) return false;
int cnt1 = 0, cnt2 = 0;
for(int i=2, j=0 ; i < s.size()-1 ; i++ ){
if( s[i] == '=' ){
j? cnt1++ : cnt2++;
}else if( s[i] == '#' ){
j++;
}else{
return false;
}
}
if( cnt1 == 0 || cnt2 == 0 || cnt1 != cnt2 || s[s.size()-1] != '~' ){
return false;
}
return true;
}
bool isB(const string& s){
if( s.size() >= 1 && s[0] != '>' ) return false;
if( s.size() >= 1 && s[1] != '^' ) return false;
if( s.size() < 6 || s.size() % 2 == 1 ) return false;
bool flag = false;
for(int i=3 ; i < s.size() - 2 ; i += 2 ){
if( s[i-1] != 'Q' || s[i] != '=' ){
return false;
}
}
if( s[s.size()-2] != '~' || s[s.size()-1] != '~' ){
return false;
}
return true;
}
int main(){
int n;
cin >> n;
for( ; n-- ; ){
string s;
cin >> s;
if( isA( s ) ){
cout << "A" << endl;
}else if( isB( s ) ){
cout << "B" << endl;
}else{
cout << "NA" << endl;
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <regex.h>
#include <cstring>
int main() {
int n;
regex_t regst[2];
regmatch_t match[3];
const char *pattern[] = {"^>'(=+)#(=+)~$", "^>\\^(Q=)+~~$"};
const char *type_label[] = {"A", "B", "NA"};
int type;
char snake[201];
scanf("%d", &n);
for (int x=0; x<n; x++) {
scanf("%s", snake);
type = 2;
for (int i=0; i<2; i++) {
regcomp(®st[i], pattern[i], REG_EXTENDED);
}
if (!regexec(®st[0], snake, 3, match, 0)) {
if (match[1].rm_eo - match[1].rm_so == match[2].rm_eo - match[2].rm_so) {
type = 0;
}
} else if (!regexec(®st[1], snake, 0, NULL, 0)) {
type = 1;
}
printf("%s\n", type_label[type]);
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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<string.h>
bool checkA(char st[1001]){
int len = strlen(st);
if(len<4)return false;
if(st[len-1]!='~')return false;
if(len%2 == 1)return false;
st[len/2-1] = '=';
for(int i = 0; i < len-1; i++){
if(st[i] !='=')return false;
}
return true;
}
bool checkB(char st[1001]){
if(strlen(st)<4)return false;
if(st[strlen(st)-1] != '~' || st[strlen(st)-2] != '~')return false;
for(int i = 0 ; i < strlen(st)-2; i+=2){
if(!(st[i]=='Q' && st[i+1] =='='))return false;
}
return true;
}
int main(void){
int n;
scanf("%d",&n);
for(int i = 0; i < n ;i++){
char str[1001];
scanf("%s",str);
bool Af = false;
bool Bf = false;
if(str[1] == '\''){
Af = checkA(str+2);
}else {
Bf = checkB(str+2);
}
if(str[0] != '>'){
puts("NA");
}else if(Af == Bf){
puts("NA");
}else if(Af == true){
puts("A");
}else{
puts("B");
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | 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.charAt(snake.length()-2) != '=')
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.charAt(snake.length()-3) != '=')
return false;
if(!snake.substring(0,2).equals(">^"))
return false;
int cnt = 0;
for(int i=2;i<snake.indexOf("~");i+=2)
{
if(snake.substring(i,i+2).equals("Q="))
cnt++;
else
return false;
}
if(cnt < 1)
return false;
return true;
}
public static void main(String args[])throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n;
n = Integer.parseInt(in.readLine());
while(n-- > 0)
{
String snake = in.readLine();
if(snake_A(snake))
{
System.out.println("A");
}
else if(snake_B(snake))
{
System.out.println("B");
}
else
{
System.out.println("NA");
}
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
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 == ">'=~"){
if(input.size() == 4) isCorrect = false;
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 == ">^~~"){
if(input.size() == 4) isCorrect = false;
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": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int main(){
long n,f,i,j,k,m;
string s;
cin>>n;
for(i=0;i<n;i++){
cin>>s;
if(s.substr(0,2)==">'"){
if(s.substr(2,1)!="="){f=2;goto E;}
j=s.find_first_not_of('=',3);
m=j-2;
if(s.substr(j,1)!="#"){f=2;goto E;}
k=s.find_first_not_of('=',j+1);
if(k-j-1!=m){f=2;goto E;}
if(s.substr(k,1)!="~"){f=2;goto E;}
if(k+1!=s.size()){f=2;goto E;}
f=0;
}else if(s.substr(0,2)==">^"){
if(s.substr(2,2)!="Q="){f=2;goto E;}
for(j=4;;j+=2){
if(s.substr(j,2)!="Q=")break;
}
if(s.substr(j,2)!="~~")f=2;else f=1;
}else{
f=2;
}
E:
if(f==0)cout<<"A"<<endl;
else if(f==1)cout<<"B"<<endl;
else cout<<"NA"<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
int n;
string s;
cin >> n;
rep(i, n) {
cin >> s;
string ans;
//cout << s.size() << endl;
if (s.size() % 2 == 1||s.size()==4) {
ans = "NA";
}
else if (s[0] == '>'&&s[s.size() - 1] == '~') {
if (s[1] == '\'') {
ans = "A";
for (int i = 2; i < s.size() - 1; i++) {
if (i == s.size() / 2) {
if (s[i] != '#') {
ans = "NA";
break;
}
}
else {
if (s[i] != '=') {
ans = "NA";
break;
}
}
}
}
else if (s[1] == '^'&&s[s.size()-2]=='~') {
ans = "B";
for (int i = 2; i < s.size() - 2; i += 2) {
if (s[i] != 'Q' || s[i + 1] != '=') {
ans = "NA";
break;
}
}
}
else ans = "NA";
}
else {
ans = "NA";
}
cout << ans << endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | 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 count_b=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_b++;
else flag=-1;
if(flag==-1)break;
i++;
}
if(flag!=-1 && count==count_b && count>=1)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": []
} | CORRECT | cpp |
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,f,i,m;
string s;
cin>>n;
while(n-->0){
cin>>s;
f=0;
if(s[0]+s[1]=='>'+'\''){
m=s.find('#');
if(m!=string::npos){
for(i=1;s[m-i]==s[m+i];)i++;
if(i>1 && m-i==1 && m+i==s.size()-1 && s[m+i]=='~')f=1;
}
}else if(s[0]+s[1]=='>'+'^'){
for(i=2;s[i]=='Q'&&s[i+1]=='=';)i+=2;
if(i>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": []
} | CORRECT | cpp | #ifdef LOCAL
#define _GLIBCXX_DEBUG
#define __clock__
#else
#pragma GCC optimize("Ofast")
#endif
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;
// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair
void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);
// >'======#======~
bool is_pattern_A(string s){
ll L = s.size();
// check tail
if(s.back()!='~') return false;
string body = s.substr(2, L-3);
if(body.size()%2==0) return false;
ll c = body.size()/2;
if(body[c]!='#') return false;
map<char, ll> mp;
for(char c : body){
mp[c]++;
}
if(mp['=']>0 && mp['=']==body.size()-1 && mp['#']==1){
return true;
}else{
return false;
}
}
bool is_pattern_B(string s){
ll L = s.size();
string tail = s.substr(L-2);
if(tail!="~~") return false;
string body = s.substr(2, L-4);
if(body.size()==0) return false;
if(body.size()%2==1) return false;
for(int i=0; i<body.size(); i+=2){
if(body[i]=='Q' && body[i+1]=='='){
// ok
}else{
return false;
}
}
return true;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// input
ll N;
cin >> N;
rep(i, N){
string s;cin>>s;
if(s.size()==1){
p("NA");
continue;
}
string head = s.substr(0, 2);
if(head==">'"){
if(is_pattern_A(s)){
p("A");
}else{
p("NA");
}
}
else if(head==">^"){
if(is_pattern_B(s)){
p("B");
}else{
p("NA");
}
}
else{
p("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": []
} | CORRECT | python3 | #!/usr/bin/env python3
import re
ans = ['A', 'B', 'NA']
for _ in range(int(input())):
s = input()
l = max([1, (len(s) - 4) // 2])
p = [r">'"+("="*l)+"#"+("="*l)+"~", r'>\^(Q=)+~~', r'\S']
for i in range(3):
if re.match(p[i], s):
print(ans[i])
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while(T--) {
string s;
cin >> s;
if(s[0]!='>'||s.size()<=3) cout << "NA" << endl;
else if(s[1]=='\'') {
if(s[s.size()-1]!='~'||s.size()%2) {
cout << "NA" << endl;
goto next;
}
s=s.substr(2,s.size()-3);
for(int i=0; i<s.size()/2; i++) {
if(s[i]!='='||s[i+s.size()/2+1]!='=') {
cout << "NA" << endl;
goto next;
}
}
if(s.size()<3||s[s.size()/2]!='#') cout << "NA" << endl;
else cout << "A" << endl;
} else {
if(s[s.size()-2]!='~'||s[s.size()-1]!='~'||s.size()%2) {
cout << "NA" << endl;
goto next;
}
s=s.substr(2,s.size()-4);
for(int i=0; i<s.size(); i+=2) {
if(s[i]!='Q'||s[i+1]!='=') {
cout << "NA" << endl;
goto next;
}
}
if(s.size()>=2) cout << "B" << endl;
else cout << "NA" << endl;
}
next:;
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int main()
{
string s, r;
int n,i;
bool b;
cin>>n;
while(n--)
{
cin>>s;
r = "NA";
if(s.size() > 5 && (s.size()&1)==0 && s[0]=='>')
{
if(s[1]=='\'')
{
if(s[s.size()-1]=='~' && s[s.size()/2]=='#')
{
b=true;
for(i=2;i<s.size()/2;++i)
if(s[i]!= '=') b=false;
for(i=s.size()/2+1;i<s.size()-1;++i)
if(s[i]!= '=') b=false;
if(b) r = 'A';
}
}
else if(s[1]=='^')
{
if(s[s.size()-1]=='~' && s[s.size()-2]=='~')
{
b=true;
for(i=2;i<s.size()-2;i+=2)
if( !(s[i]=='Q' && s[i+1]=='=') )b=false;
if(b) r='B';
}
}
}
cout << r << 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<sstream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;++i){
string line;
cin>>line;
string sol = "NA";
if(line.find('#')!=string::npos){
bool flag = false;
string a = "";
string b = "";
for(int x=2;x<line.size()-1;++x){
if(line[x] == '#'){
flag = true;
continue;
}
if(!flag){
a += line[x];
}else{
b += line[x];
}
}
if(line.size()> 3 && line[0]=='>' && line[1]=='\'' && line[line.size()-1]=='~' && a==b && a!="")sol = "A";
}else{
bool flag = true;
for(int x=2;line.size()>4 && x<(line.size()-3);x+=2){
if(line[x] !='Q' || line[x+1] != '=')flag = false;
}
if(line.size()>4 && line[0]=='>' && line[1]=='^' && line[line.size()-1]=='~' && line[line.size()-2]=='~' && flag)sol="B"; }
cout<<sol<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | 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] == '\'') {
if(s[2] != '=') NA = 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;
if( !(s[2] == 'Q' && s[3] == '=') ) NA = 1;
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": []
} | CORRECT | cpp | #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
int n;
cin>>n;
rep(i,n){
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": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)
typedef pair<int, int> P;
const int inf = 1LL << 55;
const int mod = 1e9 + 7;
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int n; cin >> n;
while(n--) {
string s; cin >> s;
int kind = 0;
int sz = s.size();
if(s[0] == '>' && s[1] == '\'' && s[sz-1] == '~' && s.size() > 5) kind = 1;
else if(s[0] == '>' && s[1] == '^' && s[sz-1] == '~' && s[sz-2] == '~' && sz%2 == 0 && s.size() > 4) kind = 2;
else kind = 3;
if(kind == 1) {
int cnt = 0, cmp = 0;
for(int 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(int 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": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;
int main(){
int n; cin >> n;
rep(q, n){
string s; cin >> s;
if(s.substr(0, 2) == ">'"){
s = s.substr(2);
int c = 0;
bool p = true;
for(int i=0; i < s.size(); i++) if(s[i] == '='){c++;} else break;
if(s[c] != '#' || c == 0)p = false;
s = s.substr(c+1);
if(c+1 != s.size() || s[s.size()-1] != '~')p = false;
rep(i, c) if(s[i] != '=')p = false;
cout << (p ? "A" : "NA") << endl;
}else if(s.substr(0, 2) == ">^"){
bool p = true;
s = s.substr(2);
if(s.substr(0, 2) != "Q=") p = false;
while(s.substr(0, 2) == "Q=") s = s.substr(2);
cout << (s == "~~" && p ? "B" : "NA") << endl;
}else {
cout << "NA" << endl;
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static final int BIG_NUM = 2000000000;
public static final int MOD = 1000000007;
public static final long HUGE_NUM = 99999999999999999L;
public static final double EPS = 0.000000001;
@SuppressWarnings("unchecked")
public static void main(String[] args) {
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
StringBuilder ans = new StringBuilder();
for(int loop = 0; loop < N; loop++){
String input_str = scanner.next();
if(input_str.matches("\\A>'(=+)#\\1~\\z")){
ans.append("A\n");
}else if(input_str.matches("\\A>\\^(Q=)+~~\\z")){
ans.append("B\n");
}else{
ans.append("NA\n");
}
}
System.out.printf(ans.toString());
}
}
class UTIL{
//最大公約数
public static long gcd(long x,long y){
x = Math.abs(x);
y = Math.abs(y);
if(x < y){
long tmp = y;
y = x;
x = tmp;
}
if(y == 0){
return x;
}else{
return gcd(y,x%y);
}
}
//最小公倍数
public static long lcm(long x,long y){
return (x*y)/gcd(x,y);
}
//String→intへ変換
public static int getNUM(String tmp_str){
return Integer.parseInt(tmp_str);
}
//文字が半角数字か判定する関数
public static boolean isNumber(String tmp_str){
if(tmp_str == null || tmp_str.length() == 0){
return false;
}
Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
Matcher matcher = pattern.matcher(tmp_str);
return matcher.matches();
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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;
int main(){
int n;
cin >> n;
for(int q=0;q<n;q++) {
string str;
cin >> str;
if(str[0] != '>') {
cout <<"NA"<<endl;
continue;
} else if(str[1] != '\''&& str[1] != '^') {
cout << "NA" << endl;
continue;
}
int flg = 0,sum;
if(str[1] == '\'') {
int t = 0;
sum=0;
for(int i=2;i<str.size();i++) {
if(str[i] == '=') t++;
else if(str[i] == '#' && sum==0 && i!=2) sum = t , t = 0;
else break;
if(str[str.size()-1] == '~' && i == str.size() -2 && sum==t ) flg = 1;
}
}
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&& i%2==1 ){
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": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int check(string str)
{
if(str[0] != '>'){ return -1; }
if(str[1] != '\'' && str[1] != '^'){ return -1; }
if(str[2] == '='){
if(str[str.size()-1] != '~' || str[str.size()-2] != '='){ return -1; }
int i=3,cnt1=1,cnt2=0;
while(str[i] != '#'){
if(i >= str.size()){ return -1; }
if(str[i] != '=') { return -1; }
i++;
cnt1++;
}
i++;
while(str[i] == '='){
if(i >= str.size()){ return -1; }
i++;
cnt2++;
}
if(cnt1 == cnt2){ return 0; }
else{ return -1; }
}
else if(str[2] == 'Q'){
if(str[str.size()-1] != '~' ||
str[str.size()-2] != '~' ||
str[str.size()-3] != '='){ return -1; }
int i = 3;
while(1){
if(i >= str.size()-2){ return 1; }
if(i&1){
if(str[i] != '='){ return -1; }
}
else{
if(str[i] != 'Q'){ return -1; }
}
i++;
}
return 1;
}
else{ return -1; }
}
int main(void)
{
int n;
string str;
cin >> n;
while(n-->0){
cin >> str;
int ans = check(str);
if(ans < 0){ cout << "NA" << endl; }
if(ans == 0){ cout << "A" << endl; }
if(ans == 1){ 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": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int isfa(string);
int isfb(string);
int main(){
int n,fa,fb;
string str;
cin >> n;
for(int i = 0;i < n;i++){
cin >> str;
if(str.size()>5){
fa = isfa(str);
fb = isfb(str);
}else fa=fb=0;
if(fa == 1)
cout << "A" << endl;
else if(fb == 1)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
}
int isfa(string n){
int pos,c1,c2;
c1=c2=0;
pos=n.size()-1;
if(n[0]!='>')return 0;
if(n[1]!='\'')return 0;
if(n[pos]!='~')return 0;
pos--;
while(n[pos]=='='){
c1++;
pos--;
}
if(n[pos]!='#')return 0;
pos--;
while(n[pos]=='='){
c2++;
pos--;
}
if(c1!=c2)return 0;
if(pos!=1)return 0;
return 1;
}
int isfb(string n){
int pos;
pos = n.size()-1;
if(n[pos]!='~'||n[pos-1]!='~')
return 0;
if(n[0]!='>'||n[1]!='^')return 0;
pos -= 2;
while(n[pos]=='='&&n[pos-1]=='Q')pos-=2;
if(pos!=1)return 0;
return 1;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
import static java.lang.System.out;
// AOJ
public class Main {
Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
new Main().AOJ0139();
}
void AOJ0145(){
int n=sc.nextInt();
}
void AOJ0141(){
int N=sc.nextInt();
for(int I=1; I<=N; I++){
int n=sc.nextInt();
char[][] c=new char[n+4][n+4];
int[] vx={0, 1, 0, -1};
int[] vy={-1, 0, 1, 0};
c=solve141(2, n+1, n, c, vx, vy);
for(int j=2; j<=n+1; j++){
for(int i=2; i<=n+1; i++) out.print(c[i][j]);
out.println();
}
out.println();
}
}
char[][] solve141(int x, int y, int n, char[][] c, int[] vx, int[] vy){
//範囲を超えていないか
if(x<2&&x>n+1 && y<2&&y>n+1) return c;
//周りが#
//return c;
c[x][y]='#';
// 1周目
if(x==2){
if(y!=2) solve141(x, y-1, n, c, vx, vy);
else solve141(x+1, y, n, c, vx, vy);
}
if(y==2){
if(x!=n+1) solve141(x+1, y, n, c, vx, vy);
else solve141(x, y+1, n, c, vx, vy);
}
if(x==n+1){
if(y!=2) solve141(x, y+1,n,c,vx,vy);
else solve141(x-1, y,n,c,vx,vy);
}
if(y==n+1){
if(x!=3) solve141(x-1,y,n,c,vx,vy);
else solve141(x,y-1,n,c,vx,vy);
}
// それ以降
for(int i=0; i<4; i++){
if(c[x+vx[i]][y+vy[i]]!='#'){
solve141(x+vx[i], y+vy[i],n,c,vx,vy);
}
}
return c;
}
void AOJ0139(){
int N=sc.nextInt();
for(int i=1; i<=N; i++){
String s=sc.next();
Matcher m=Pattern.compile("^>'(=+)#(=+)~$").matcher(s);
if(m.matches()){
if(m.group(1).length()==m.group(2).length()){
out.println("A");
continue;
}
}else if(Pattern.compile("^>\\^(Q=)+~~$").matcher(s).matches()){
out.println("B");
continue;
}
out.println("NA");
}
}
void AOJ0137(){
int N=sc.nextInt();
for(int i=1; i<=N; i++){
long s=sc.nextLong();
out.println("Case "+i+":");
for(int j=0; j<10; j++){
s*=s; s/=100; s%=10000;
out.println(s);
}
}
}
ArrayList<Integer> Sieve2(int N){
ArrayList<Integer> prime = new ArrayList<Integer>();
boolean[] list = new boolean[N+1];
Arrays.fill(list, true);
list[1]=false;
for (int i=2; i<=N; i++) {
if(list[i]) {
prime.add(i);
for (int j=i+i; j<=N; j+=i) list[j] = false;
}
}
return prime;
}
boolean[] Sieve(int N){
boolean[] list = new boolean[N+1];
Arrays.fill(list, true);
list[1]=false;
for(int i=2; i<=N; i++) {
if(list[i]) {
for (int j=i+i; j<=N; j+=i) list[j] = false;
}
}
return list;
}
//素数判定
boolean isPrime(int n){
for(int i=2; i*i<=n; i++){
if(n%i==0) return false;
}
return true;
}
int gcd(int x, int y){
if(y==0) return x;
else return gcd(y, x%y);
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
bool check_A(string str){
if(str.size() < 6 || str.size() % 2 == 1){
return false;
}
if(str.substr(0, 2) != ">'"){
return false;
}
int count = 0;
for(int i = 2; i < (str.size() - 4) / 2 + 2; i++){
if(str[i] != '='){
return false;
}
}
if(str[str.size() / 2] != '#'){
return false;
}
for(int i = str.size() / 2 + 1; i <= str.size() - 2; i++){
if(str[i] != '='){
return false;
}
}
if(str[str.size() - 1] != '~'){
return false;
}
return true;
}
bool check_B(string str){
if(str.size() < 6 || str.size() % 2 == 1){
return false;
}
if(str.substr(0, 2) != ">^"){
return false;
}
for(int i = 2; i < str.size() - 2; i += 2){
if(str.substr(i, 2) != "Q="){
return false;
}
}
if(str.substr(str.size() - 2, 2) != "~~"){
return false;
}
return true;
}
int main(){
int n;
string str;
cin >> n;
for(int loop = 0; loop < n; loop++){
cin >> str;
if(check_A(str)){
printf("A\n");
}else if(check_B(str)){
printf("B\n");
}else{
printf("NA\n");
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | for _ in [0]*int(input()):
s=input()
if s[:2]==">'" and s[-1]=='~' and '#' in s:
s=s[2:-1].split('#')
print(['NA','A'][set(s[0])==set(s[1])=={'='} and len(set(s))==1])
elif s[:2]=='>^' and s[-2:]=='~~':
s=s[2:-2]
print(['NA','B'][len(s)==2*s.count('Q=') and len(s)>0])
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 | java | import java.util.Scanner;
class Main {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Snake s;
for(int i=0;i<n;i++){
s = new Snake(scan.next());
System.out.println(s.getType());
}
}
}
class Snake{
String snake;
Snake(String str){
snake = str;
}
public String getType(){
switch(checkHead()){
case 1:
return "A";
case 2:
return "B";
default:
return "NA";
}
}
public int checkHead(){
if(snake.charAt(0) == 62){
if(snake.charAt(1) == 39){
return checkBodyA();
}else if(snake.charAt(1) == 94){
return checkBodyB();
}
}
return -1;
}
public int checkBodyA(){
int count = 0;
boolean flag = true;
if(snake.charAt(2) == 61){
count++;
}else{
return -1;
}
for(int i=3;i<snake.length()-1;i++){
if(flag){
if(snake.charAt(i) == 61){
count++;
}else if(snake.charAt(i) == 35){
flag = false;
}else{
return -1;
}
}else{
if(snake.charAt(i) == 61){
count--;
}else{
return -1;
}
}
}
if(count == 0){
if(snake.charAt(snake.length()-1) == 126){
return 1;
}
}
return -1;
}
public int checkBodyB(){
boolean flag = false;
for(int i=3;i<snake.length();i+=2){
if(snake.charAt(i-1)==81){
if(snake.charAt(i) == 61){
flag = true;
}else{
return -1;
}
}else if(snake.charAt(i-1) == 126){
if(snake.charAt(i) == 126){
if(flag){
return 2;
}else{
return -1;
}
}else{
return -1;
}
}else{
return -1;
}
}
return -1;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
using namespace std;
typedef string::iterator S;
string ss;
string snakeA(S it){
int count = 0;
for(;it!=ss.end()&&*it=='=';it++,count++);
if(!count) return "NA";
if(it==ss.end()||*it!='#') return "NA";
it++;
for(;it!=ss.end()&&*it=='=';it++,count--);
if(it==ss.end()||*it!='~') return "NA";
it++;
if(*it||count) return "NA";
return "A";
}
string snakeB(S it){
while(true){
if(it==ss.end()||*it++!='Q') return "NA";
if(it==ss.end()||*it++!='=') return "NA";
if(it==ss.end()) return "NA";
if(*it=='~') break;
}
if(*++it=='~'&&!*++it) return "B";
return "NA";
}
string snake(string ss){
S it = ss.begin();
if( *it++ != '>' ) return "NA";
if( *it == '\'' ) return snakeA(++it);
else if( *it == '^' ) return snakeB(++it);
else return "NA";
}
int main(){
int n;
for(cin>>n,cin.ignore();n--;){
getline(cin, ss);
cout<<snake(ss)<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int checksnake(string, int);
int main(void) {
int n, len;
char snake[200];
int type;
cin >> n;
for(int i = 0 ; i < n ; i++) {
scanf("%s", snake);
len = strlen(snake);
type = checksnake(snake, len);
if(type == 1) cout << 'A' << endl;
else if(type == 2) cout << 'B' << endl;
else if(type == 3) cout << "NA" << endl;
for(int a = 0 ; a < 200 ; a++) {
snake[a] = 0;
}
len = 0;
}
return 0;
}
int checksnake(string snake, int len) {
int flag1=0, flag2=0, flag3=0;
int true_flag=0, true_flag2=0, true_flag3=0;
int cnt1=0, cnt2=0;
if(true_flag == 0) {
for(int i = 0 ; i < len - 1 ; i++) {
if(snake[i] != '>' && snake[i] != '#' && snake[i] != '=' && snake[i] != '\'') { true_flag2 = 1; break; }
if(snake[i] == '>' && snake[i+1] == '\'') flag2 = 1;
if(snake[i] == '=' && flag1 == 0 && flag2 == 1) {cnt1++; flag3 = 1; }
if(snake[i] == '=' && flag1 == 1 && flag2 == 1) {cnt2++; flag3 = 1; }
if(snake[i] == '#' && flag2 == 1 && flag3 == 1) flag1 = 1;
//cout << cnt1 << ' ' << cnt2 << endl;
}
if(snake[len-1] == '~' && cnt1 == cnt2 && flag2 == 1 && flag3 == 1 && true_flag2 == 0) {
return 1;
true_flag = 1;
}
}
if(true_flag == 0) {
for(int i = 0 ; i < len - 2 ; i++) {
if(snake[i] != '>' && snake[i] != '^' && snake[i] != '=' && snake[i] != 'Q') { true_flag3 = 1; break; }
if(snake[i] == '>' && snake[i+1] == '^') flag3 = 1;
if(snake[i] == 'Q' && snake[i+1] == '=' && flag3 == 1) flag1 = 1;
}
if(snake[len-2] == '~' && snake[len-1] == '~' && flag1 == 1 && flag3 == 1 && true_flag3 == 0) {
return 2;
true_flag = 1;
}
}
if(true_flag == 0 || true_flag2 == 1 || true_flag3 == 1) {
return 3;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
bool isa(string s) {
int pos = 2,cnt = 0;
if(s[pos] != '=') return false;
while(s[pos] == '=') pos++,cnt++;
if(s[pos] != '#') return false;
pos++;
for(int i=0; i<cnt; ++i) {
if(s[pos+i] != '=') return false;
}
pos += cnt;
if(pos == s.length()-1 && s[pos] == '~') return true;
return false;
}
bool isb(string s) {
int pos = 2;
if(s[2] != 'Q' || s[3] != '=') return false;
for(; pos < s.length()-2; pos += 2)
if(s[pos] != 'Q' || s[pos+1] != '=') return false;
if(s[s.length()-1] == s[s.length()-2] && s[s.length()-1] == '~') return true;
return false;
}
int main() {
int n;
cin>>n;
string s;
for(int i=0; i<n; ++i) {
cin>>s;
if(s.length() <= 2 || s[0] != '>') {
cout<<"NA"<<endl;
} else if(s[1] == '\'') {
if(isa(s)) {
cout<<"A"<<endl;
}else{
cout<<"NA"<<endl;
}
} else {
if(isb(s)) {
cout<<"B"<<endl;
}else{
cout<<"NA"<<endl;
}
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int a=s.nextInt();
for(int i=0;i<a;i++){
String str=s.next();
boolean A=true;
boolean B=true;
if(str.charAt(0)!='>')A=B=false;
if(str.length()<6||str.length()%2==1)A=B=false;
if(str.length()>=6&&str.length()%2==0){
if(str.charAt(1)!='\'')A=false;
if(str.charAt(1)!='^')B=false;
if(str.charAt(str.length()-1)!='~')A=B=false;
if(str.charAt(str.length()-2)!='~')B=false;
if(A){
String [] dat=str.split("#");
if(dat.length!=2)A=false;
if(A){
if(dat[0].length()==dat[1].length()+1||dat[0].length()>2){
for(int j=0;j<dat[1].length()-1;j++){
if(dat[0].charAt(2+j)!='='||dat[1].charAt(j)!='=')A=false;
}
}else A=false;
}
}
if(B){
for(int j=2;j<str.length()-2;j+=2){
if(str.charAt(j)!='Q'||str.charAt(j+1)!='=')B=false;
}
}
}
if(A)System.out.println("A");
else if(B)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<iostream>
using namespace std;
int main()
{
int n;
for(cin>>n;n--;)
{
string s;
cin>>s;
string ans="NA";
if(s.substr(0,2)==">'" &&s[s.size()-1]=='~')
{
string tmp=s.substr(2,s.size()-3);
// cout<<tmp<<endl;
if(tmp.size()%2!=0
&& tmp.size()>1
&& tmp[tmp.size()/2]=='#'
&& tmp.substr(0,tmp.size()/2)==tmp.substr(tmp.size()/2+1,tmp.size()/2)
&& tmp.substr(0,tmp.size()/2)==*(new string(tmp.size()/2,'=')))
ans="A";
}
else if(s.substr(0,2)==">^" && s.substr(s.size()-2,2)=="~~")
{
string tmp=s.substr(2,s.size()-4);
// cout<<tmp<<endl;
bool flag=false;
while(tmp.size()>0)
{
if(tmp.substr(0,2)=="Q=")
{
tmp=tmp.substr(2,tmp.size()-2);
flag=true;
}
else
break;
}
if(tmp.size()==0&&flag)
ans="B";
}
cout<<ans<<endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
bool asnake(string s){
int n=s.size();
if(n%2 || n<6)return false;
string com=">\'";
rep(i,(n-4)/2)com+='=';
com+='#';
rep(i,(n-4)/2)com+='=';
com+='~';
if(s==com)return true;
else return false;
}
bool bsnake(string s){
int n=s.size();
if(n%2 || n<6)return false;
string com=">^";
rep(i,(n-4)/2)com+="Q=";
com+="~~";
if(s==com)return true;
else return false;
}
int main(){
int n;
cin>>n;
rep(p,n){
string s;
cin>>s;
if(asnake(s))cout<<"A"<<endl;
else if(bsnake(s))cout<<"B"<<endl;
else cout<<"NA"<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import static java.util.Arrays.deepToString;
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
new Main().run();
}
void tr(Object... os) {
System.err.println(deepToString(os));
}
Scanner sc = new Scanner(System.in);
void run() {
for (int testcase = sc.nextInt(); testcase-->0;) {
String s = sc.next();
if (isA(s)) System.out.println("A");
else if (isB(s)) System.out.println("B");
else System.out.println("NA");
}
}
boolean isA(String s) {
Pattern p = Pattern.compile(">'(=+)#(=+)~");
Matcher matcher = p.matcher(s);
if (matcher.matches()) {
if (matcher.group(1).equals(matcher.group(2))) return true;
}
return false;
}
boolean isB(String s) {
return s.matches(">\\^(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": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
int main(void){
int i,j,n,a;
string s,ans;
cin >> n;
for(i = 0 ; i < n ; i++ ){
cin >> s;
ans = "NA";
if( s[0] == '>'){
if( s[1] == '\''){
a = 2;
int cnt1 = 0,cnt2 = 0;
if( s[a] == '='){
while( s[a] == '='){
a++;
cnt1++;
}
if( s[a] == '#' ){
a++;
if( s[a] == '='){
while( s[a] == '='){
cnt2++;
a++;
}
if( s[a] == '~' && a + 1 == s.size() && cnt1 == cnt2) ans = "A";
}
}
}
}
else if( s[1] == '^'){
a = 2;
if( s[a] == 'Q' && s[a + 1] == '='){
while( s[a] == 'Q' && s[a + 1] == '=') a += 2;
if( s[a] == '~' && s[a + 1] == '~' && a + 2 == s.size()) ans = "B";
}
}
}
cout << ans << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java |
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
Pattern a = Pattern.compile(">'(=+)#\\1~");
Pattern b = Pattern.compile(">\\^(Q=)+~~");
while (n-- > 0) {
String line = scanner.next();
Matcher ma = a.matcher(line);
Matcher mb = b.matcher(line);
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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T &t = T()){
v.assign(a,vector<T>(b,t));
}
//v.erase(unique(v.begin(),v.end()),v.end());
int main(){
int n;
cin>>n;
rep(i,n){
string s;
cin>>s;
if(s.substr(0,2)==">'"&&s.substr(s.size()-1,1)=="~"){
s=s.substr(2);
s=s.substr(0,s.size()-1);
bool f=true;
if(s.size()==0) f=false;
if(s.size()&&s[0]!='='){
f=false;
}
while(s.size()>1){
if(s[0]==s[s.size()-1]&&s[0]=='='){
s=s.substr(1,s.size()-2);
}
else{
f=false;
break;
}
}
if(f){
if(s[0]=='#'){
cout<<"A\n";
}
else cout<<"NA\n";
}
else{
cout<<"NA\n";
}
}
else if(s.substr(0,2)==">^"&&s.substr(s.size()-2,2)=="~~"){
s=s.substr(2);
s=s.substr(0,s.size()-2);
bool f=true;
if(s.size()<2) f=false;
if(s.size()>=2&&s.substr(0,2)!="Q=") f=false;
while(s.size()>=2){
if(s.substr(0,2)=="Q="){
s=s.substr(2);
}
else{
f=false;
break;
}
}
if(f){
cout<<"B\n";
}
else cout<<"NA\n";
}
else{
cout<<"NA\n";
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair
template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }
int main() {
int n=in();
string snake;
while(n--){
cin>>snake;
int i;
bool a=true,b=true;
if(snake.size()<6||snake.size()%2!=0){
a=false;
b=false;
}
for(i=0;i<snake.size();i++){
if(i==0){
if(snake[i]!='>'){
a=false;
b=false;
}
}
if(i==1){
if(snake[i]!='\'')a=false;
if(snake[i]!='^')b=false;
}
if(i*2==snake.size()){
if(snake[i]!='#')a=false;
}
if(i==snake.size()-1){
if(snake[i]!='~'){
a=false;
b=false;
}
}
if(i==snake.size()-2){
if(snake[i]!='~')b=false;
}
if(i!=0&&i!=1&&i*2!=snake.size()&&i!=snake.size()-1){
if(snake[i]!='=')a=false;
}
if(i%2==0&&i!=0&&i!=snake.size()-2){
if(snake[i]!='Q')b=false;
}
if(i%2==1&&i!=1&&i!=snake.size()-1){
if(snake[i]!='=')b=false;
}
}
if(a){
cout<<"A\n";
}else if(b){
cout<<"B\n";
}else{
cout<<"NA\n";
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | def checkA(s):
if s[:2] == ">'" and s[-1] == "~":
body = s[2:-1]
if len(body) >= 3 and body.count("#") == 1 and body.index("#") == len(body) // 2 and body.count("=") == len(body) - 1:
return True
else:
return False
else:
return False
def checkB(s):
if s[:2] == ">^" and s[-2:] == "~~":
body = s[2:-2]
if len(body) > 0 and len(body) % 2 == 0:
for i in range(0, len(body), 2):
if body[i:i + 2] != "Q=":
return False
else:
return True
else:
return False
else:
return False
n = int(input())
for _ in range(n):
s = input()
if len(s) <= 5:
print("NA")
else:
if checkA(s):
print("A")
elif checkB(s):
print("B")
else:
print("NA")
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.Scanner;
//Snakes
public class Main{
static boolean isA(char[] s){
if(s.length<6)return false;
if(!(s[0]=='>'&&s[1]=='\''))return false;
int con = 0;
while(2+con<s.length && s[2+con]=='=')con++;
if(con==0)return false;
if(2+con==s.length||s[2+con]!='#')return false;
int b = 3+con;
int sec = 0;
while(b+sec<s.length && s[b+sec]=='=')sec++;
if(sec!=con||b+sec==s.length)return false;
return s[b+sec]=='~'&&b+sec==s.length-1;
}
static boolean isB(char[] s){
if(s.length<6)return false;
if(!(s[0]=='>'&&s[1]=='^'))return false;
int i = 2;
int c = 0;
while(i+1<s.length && s[i]=='Q' && s[i+1]=='='){
i+=2;c++;
}
if(i+1>=s.length||c==0)return false;
return i+1==s.length-1 && s[i]=='~' && s[i+1]=='~';
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t--!=0){
char[] s = sc.next().toCharArray();
System.out.println(isA(s)?"A":isB(s)?"B":"NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
using namespace std;
bool chk_a(const string s)
{
bool c = true;
int f, b;
f = b = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] != '=' && s[i] != '#')
return false;
if (c && s[i] == '#')
c = false;
else if (s[i] == '=' && c)
f++;
else
b++;
}
return (f == b) ? true : false;
}
bool chk_b(const string s)
{
for (int i = 0; i < s.size(); i += 2)
if (s[i] != 'Q' || s[i + 1] != '=')
return false;
return true;
}
int main()
{
int n;
cin >> n;
while (n--) {
string inp;
bool flag = false;
cin >> inp;
if (inp.size() >= 5 && inp[0] == '>' && inp[inp.size() - 1] == '~') {
if (inp[1] == '\'') { // Aの判定
if (chk_a(inp.substr(2, inp.size() - 3))) {
cout << "A" << endl;
flag = true;
}
}
else if (inp.size() >= 6 && inp[1] == '^'
&& inp[inp.size() - 2] == '~') { // Bの判定
if (chk_b(inp.substr(2, inp.size() - 4))) {
cout << "B" << endl;
flag = true;
}
}
}
if (!flag)
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>
using namespace std;
int main()
{
const string Type[] = {"A", "B", "NA"};
int n;
while (cin >> n) {
for (int i = 0; i < n; ++i) {
string snake;
cin >> snake;
int ans = 2;
int length = static_cast<int>(snake.size());
if (snake[0] == '>' && snake[length-1] == '~') {
if (length >= 5 && snake[1] == '\'' && snake.find_first_of("#") != string::npos) {
int sharp = snake.find_first_of("#");
bool valid = true;
for (int j = 2; j < sharp && valid; ++j) {
if (snake[j] != '=')
valid = false;
}
for (int j = sharp+1; j < length-1 && valid; ++j) {
if (snake[j] != '=')
valid = false;
}
if (valid && sharp-2 == length-2-sharp)
ans = 0;
} else if (length >= 6 && snake[1] == '^' && snake[length-2] == '~') {
bool valid = true;
for (int j = 2; j < length-2 && valid; j += 2) {
if (snake[j] != 'Q' || snake[j+1] != '=')
valid = false;
}
if (valid)
ans = 1;
}
}
cout << Type[ans] << endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | //package _0139;
import java.util.*;
import java.lang.*;
import java.math.*;
public class Main {
Scanner sc = new Scanner(System.in);
boolean isA(String snake) throws Exception {
if (snake.startsWith(">'")) {
if (snake.endsWith("~")) {
String mid = snake.substring(2, snake.length() - 1);
if (mid.length() >= 3) {
String[] spl = mid.split("#", 2);
if (spl[0].equals(spl[1])) {
for (int i = 0; i < spl[0].length(); i++) {
if ('=' != spl[0].charAt(i)) {
return false;
}
}
return true;
}
}
}
}
return false;
}
boolean isB(String snake) throws Exception {
if (snake.startsWith(">^")) {
if (snake.endsWith("~~")) {
String mid = snake.substring(2, snake.length() - 2);
if (mid.length() >= 2) {
while (mid.startsWith("Q=")) {
mid = mid.substring(2);
}
if (mid.equals("")) {
return true;
}
}
}
}
return false;
}
/*
* >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
*/
String getAns(String snake) {
String ret = "NA";
if (snake.startsWith(">'")) {
try {
if (isA(snake))
ret = "A";
} catch (Exception e) {
}
} else if (snake.startsWith(">^")) {
try {
if (isB(snake))
ret = "B";
} catch (Exception e) {
}
}
return ret;
}
void run() {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
System.out.println(getAns(sc.next()));
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | n = int(input())
for i in range(n):
s = input()
if s[:2] == ">'" and s[-1] == '~' and len(s) % 2 == 0 and '=#=' in s:
temp = ">'" + '=' * (s.count('=')//2) + '#' + '=' * (s.count('=')//2) + '~'
if s == temp:
print('A')
continue
elif s[:2] == ">^" and s[-2:] == '~~' and len(s) % 2 == 0 and 'Q=' in s:
temp = ">^" + 'Q=' * ((len(s)-4)//2) + '~~'
if s == temp:
print('B')
continue
print('NA')
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
enum State{
START, MOUTH, EYE_A, EYE_B, BODY_A1, BODY_A2, BODY_B1, BODY_B2, MID_A, TAIL_A, TAIL_B1, TAIL_B2, NA;
}
String snake(String s){
State state=State.START;
int length=0;
LOOP:
for(int i=0;i<s.length();++i){
char next=s.charAt(i);
switch(state){
case START:
if(next=='>') state=State.MOUTH;
else state=State.NA;
break;
case MOUTH:
if(next=='\'') state=State.EYE_A;
else if(next=='^') state=State.EYE_B;
else state=State.NA;
break;
case EYE_A:
if(next=='='){
state=State.BODY_A1;
length=0;
}
else state=State.NA;
break;
case BODY_A1:
++length;
if(next=='=') state=State.BODY_A1;
else if(next=='#') state=State.MID_A;
else state=State.NA;
break;
case MID_A:
if(next=='=') state=State.BODY_A2;
else state=State.NA;
break;
case BODY_A2:
--length;
if(next=='=') state=State.BODY_A2;
else if(next=='~'&&length==0) state=State.TAIL_A;
else state=State.NA;
break;
case EYE_B:
if(next=='Q') state=State.BODY_B1;
else state=State.NA;
break;
case BODY_B1:
if(next=='=') state=State.BODY_B2;
else state=State.NA;
break;
case BODY_B2:
if(next=='Q') state=State.BODY_B1;
else if(next=='~') state=State.TAIL_B1;
else state=State.NA;
break;
case TAIL_B1:
if(next=='~') state=State.TAIL_B2;
else state=State.NA;
break;
default:
break LOOP;
}
}
switch(state){
case TAIL_A:
return "A";
case TAIL_B2:
return "B";
default:
return "NA";
}
}
BufferedReader input;
int ni() throws NumberFormatException, IOException{
return Integer.parseInt(input.readLine());
}
String ns() throws IOException{
return input.readLine();
}
void io(){
input=new BufferedReader(new InputStreamReader(System.in));
try {
int n=ni();
for(int i=0;i<n;++i){
System.out.println(snake(ns()));
}
input.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main().io();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | def A():
p = s[2:]
count = 0
index = 0
for i, c in enumerate(p):
if c == '=':
count += 1
elif c == '#':
index = i
break
else:
print 'NA'
return
else:
if not index:
print 'NA'
return
p = p[index+1:-1]
for c in p:
if c == '=':
count -= 1
else:
print 'NA'
return
if count == 0 and s[-1] == '~':
print 'A'
else:
print 'NA'
def B():
p = s[2:-2]
for i in range(0, len(p), 2):
if not (p[i]+p[i+1] == 'Q='):
print 'NA'
return
if s[-2:] == '~~':
print 'B'
else:
print 'NA'
for i in range(input()):
s = raw_input()
if s[:3] == ">'=":
A()
elif s[:4] == ">^Q=":
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 <algorithm>
#include <string>
using namespace std;
string kaga(string s,int num){
string san;
for(int i=0;i<num;i++)san+=s;
return san;
}
void check(string s){
for(int i=1;i<99;i++){
string a,b;
a=">'"+kaga("=",i)+'#'+kaga("=",i)+'~';
b=">^"+kaga("Q=",i)+"~~";
if(a==s){
cout<<"A"<<endl;
goto end;
}
if(b==s){
cout<<"B"<<endl;
goto end;
}
}
cout<<"NA"<<endl;
end:;
}
int main(){
int n;
string s;
for(cin>>n;n>0;n--){
cin>>s;
check(s);
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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>
//CÓ¶ðÁ·Ö
int clear(std::string s, std::string f){
int pos;
while(pos = s.find(f), pos != std::string::npos)
s.replace(pos,f.size(),"");
if(s == "")return 1;
return 0;
}
int main(){
int n;
std::cin >> n;
while(n--){
std::string sn, res = "";
std::cin >> sn;
//Type A
//ªª>'CKöª~C©Â¨ ̪ªïÅ é
if(sn.substr(0,2) == ">'" &&
sn[sn.size()-1] == '~' && (sn.size()-3) % 2 == 1){
std::string st = sn.substr(2,sn.size()-3);
//¨ Ì^ñª#
if(st[st.size()/2] == '#'){
st.replace(st.size()/2,1,"");
//#ÈOª·×Ä=
// int eq = 1;
// for(int i=0;i<st.size();i++){
// if(st[i] != '='){eq = 0;break;}
// }
// if(eq)std::cout << "A" << std::endl;
if(st != "")
if(clear(st,"="))res = "A\n";
}
}
//Type B
if(sn.substr(0,2) == ">^" &&
sn.substr(sn.size()-2,2) == "~~" &&
(sn.size()-4) % 2 == 0){
std::string st = sn.substr(2,sn.size()-4);
if(st != "")
if(clear(st,"Q="))res = "B\n";
}
if(res == "")res = "NA\n";
std::cout << 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 <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int check( string S )
{
//A
if( S[ 0 ] == '>' && S[ 1 ] == '\'' && S[ S.size() - 1 ] == '~' && S.size() >= 6 )
{
S = S.substr( 2, S.size() - 3 );
if( S.find_first_not_of( "#=", 0 ) != string::npos ) return 0;
return S.substr( 0, S.find('#') ).size() == S.substr( S.find( '#' ) + 1, S.size() - 1 ).size() ? 1 : 0;
}
//B
if( S[ 0 ] == '>' && S[ 1 ] == '^' && S[ S.size() - 1 ] == '~' && S[ S.size() - 2 ] == '~' && S.size() >= 6 )
{
S = S.substr( 2, S.size() - 4 );
if( S.find_first_not_of( "Q=", 0 ) != string::npos || S.size() % 2 != 0 ) return 0;
for( int i = 0; i < S.size(); i += 2 )
{
if( S[ i ] != 'Q' && S[ i + 1 ] != '=' ) return 0;
}
return 2;
}
return 0;
}
int main()
{
int N;
cin >> N;
vector<string> res{ "NA", "A", "B" };
string S;
while( cin >> S )
{
cout << res[ check( S ) ] << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int main()
{
int n,i,j;
string str;
cin >> n;
for(i=0;i<n;i++)
{
cin >> str;
if(str[0]=='>')
{
if(str[1]=='\'')
{
int num=0;
for(j=2;j<str.size();j++)
{
if(str[j]=='=')
num++;
else if(num>0 && str[j]=='#')
{
for(j+=1;j<str.size();j++)
{
if(j==str.size()-1 && str[j]=='~' && num==0)
cout << "A" << endl;
else if(j!=str.size()-1 && str[j]=='=')
num--;
else
{
cout << "NA" << endl;
break;
}
}
break;
}
else
{
cout << "NA" << endl;
break;
}
}
}
else if(str[1]=='^')
{
if(str.size()<6)
cout << "NA" << endl;
else
{
for(j=2;j<str.size();j++)
{
if(j==str.size()-2 && str[j]=='~' && str[j+1]=='~')
{
cout << "B" << endl;
break;
}
else if(j==str.size()-2 && (str[j]!='~' || str[j+1]!='~'))
{
cout << "NA" << endl;
break;
}
else if((j%2==0 && str[j]!='Q') || (j%2==1 && str[j]!='='))
{
cout << "NA" << endl;
break;
}
}
}
}
else
cout << "NA" << endl;
}
else
cout << "NA" << endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int main(){
int n,j,fa,fb,acount,acount2,i;
string data;
cin >> n;
getline(cin,data);
for(j = 0; j < n; j++){
fa = 0;
fb = 0;
acount = acount2 = 0;
getline(cin,data);
if(data.length() < 6)
data = "OOHAZURE";
if(data[0] == '>' && data[1] == '\''){
fa = 1;
i = 2;
while(data[i] == '='){
acount++;
i++;
}
if(data[i] != '#')
fa = 0;
i++;
while(data[i] == '='){
acount2++;
i++;
}
if(i != data.length()-1)
fa = 0;
if(acount != acount2)
fa = 0;
if(data[data.length()-1] != '~'){
fa = 0;
}
}
if(data[0] == '>' && data[1] == '^'){
fb = 1;
for(i = 2; i < data.length()-3; i = i+2){
if(data[i] != 'Q' || data[i+1] != '=')
fb = 0;
}
if(i != data.length()-2)
fb = 0;
if(data[data.length()-1] != '~' || data[data.length()-2] != '~')
fb = 0;
}
if(fa == 1)
cout << "A" << endl;
else if(fb == 1)
cout << "B" << endl;
else
cout << "NA" << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | //11
#include<string>
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
string s;
cin>>s;
if(s.size()>=6&&s==">'"+string((s.size()-4)/2,'=')+'#'+string((s.size()-4)/2,'=')+'~'){
cout<<'A'<<endl;
}else{
int r=(s.size()-4)/2;
string b;
while(r--){
b+="Q=";
}
if(s.size()>=6&&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": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
bool isA(string s){
if(s.size() < 6 || s.size() % 2 == 1) return false;
if(s.substr(0,2) != ">\'") return false;
if(s[s.size() - 1] != '~') return false;
int a, b;
for( a = 2, b = s.size() - 2 ; a != b ; a++, b--){
if(s[a] != '=' || s[b] != '=') return false;
}
return s[a] == '#';
}
bool isB(string s){
if(s.size() < 6 || s.size() % 2 == 1) return false;
if(s.substr(0,2) != ">^") return false;
if(s.substr(s.size() - 2) != "~~") return false;
for(int i = 2 ; i < s.size() - 2 ; i += 2){
if(s.substr( i, 2) != "Q=") return false;
}
return true;
}
int main(){
int n;
cin >> n;
while(n--){
string s;
cin >> s;
if(isA(s)) cout << "A\n";
else if(isB(s)) cout << "B\n";
else cout << "NA\n";
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
import java.io.*;
public class Main {
public String species(String snake){
if( snake.length() < 5 || snake.charAt(0) != '>' || snake.charAt(snake.length()-1) != '~' ){
return "NA";
}
if( snake.charAt(1) == '\'' ){
int count = 0;
boolean flag = true;
for(int i = 2; i < snake.length()-1; i++){
if( flag ){
if( snake.charAt(i) == '=' ){
count++;
} else if( snake.charAt(i) == '#' ){
flag = false;
} else {
return "NA";
}
} else {
if( snake.charAt(i) == '=' ){
count--;
} else {
return "NA";
}
}
}
if( count != 0 ){
return "NA";
}
return "A";
} else if( snake.charAt(1) == '^' ){
for(int i = 2; i < snake.length()-2; i += 2){
if( snake.charAt(i) == 'Q' && snake.charAt(i+1) == '=' ){
continue;
}
return "NA";
}
if( snake.charAt(snake.length()-2) != '~' ){
return "NA";
}
return "B";
}
return "NA";
}
public void solve() throws IOException{
int n = nextInt();
for(int i = 0; i < n; i++){
String snake = nextToken();
writer.println(species(snake));
}
writer.flush();
}
public static void main (String args[]) throws IOException{
new Main().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() throws IOException{
try{
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
} catch (Exception e){
e.printStackTrace();
System.exit(1);
}
}
public int nextInt() throws IOException{
return Integer.parseInt(nextToken());
}
public String nextToken() throws IOException{
while( tokenizer == null || !tokenizer.hasMoreTokens() ){
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>
using namespace std;
bool hebi_a(string hebi){
if(!(hebi[0]=='>' && hebi[1]=='\''))return false;
if(hebi[2]!='=')return false;
int now=3;
int count=1;
while(1){
if(hebi[now]=='#'){
now++;
break;
}else if(hebi[now]=='='){
now++;
count++;
}else{
return false;
}
}
while(now!=hebi.length()){
if(hebi[now]=='='){
now++;
count--;
}else if(hebi[now]=='~'){
now++;
break;
}else{
return false;
}
}
if(now==hebi.length()&& count==0)return true;
else return false;
}
bool hebi_b(string hebi){
if(!(hebi[0]=='>' && hebi[1]=='^'))return false;
if(hebi[2]!='Q')return false;
if(hebi[3]!='=')return false;
int now=4;
while(1){
if(hebi[now]!='Q'){
break;
}else{
now++;
}
if(now==hebi.length())return false;
if(hebi[now]!='='){
return false;
}else{
now++;
}
if(now==hebi.length())return false;
}
if(now==hebi.length())return false;
if(hebi[now]!='~')return false;
now++;
if(now==hebi.length())return false;
if(hebi[now]!='~')return false;
now++;
if(now==hebi.length())return true;
else return false;
}
int main(){
int n;
cin>>n;
for(int roop=0; roop<n; roop++){
string hebi;
cin>>hebi;
if(hebi_a(hebi))cout<<"A"<<endl;
else if(hebi_b(hebi))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": []
} | CORRECT | cpp | # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };
int main()
{
vector<string> a, b;
for (int i = 1; i <= 100; i++)
{
string s = ">\'";
for (int j = 0; j < i; j++)s += "=";
s += "#";
for (int j = 0; j < i; j++)s += "=";
s += "~";
a.push_back(s);
}
for (int i = 1; i <= 100; i++)
{
string s = ">^";
for (int j = 0; j < i; j++)s += "Q=";
s += "~~";
b.push_back(s);
}
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
if (find(ALL(a), s)!=a.end())cout << "A" << endl;
else if (find(ALL(b), s) != b.end())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": []
} | CORRECT | cpp | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;
typedef ostringstream OSS;
typedef istringstream ISS;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
#define X first
#define Y second
bool check1(string s) {
int n = s.size();
if (n < 6 || s[0] != '>' || s[1] != '\'' || s[n - 1] != '~') {
return false;
}
string sub = s.substr(2, n - 3);
n = sub.size();
if (!(n % 2) || sub[n / 2] != '#') {
return false;
}
for (int i = 0; i < n / 2; i++) {
if (sub[i] != '=' || sub[n - i - 1] != '=') {
return false;
}
}
return true;
}
bool check2(string s) {
int n = s.size();
if (n < 6 || s[0] != '>' || s[1] != '^' || s[n - 1] != '~' || s[n - 2] != '~') {
return false;
}
string sub = s.substr(2, n - 4);
n = sub.size();
for (int i = 0; i < n / 2; i++) {
if (sub[i * 2] != 'Q' || sub[i * 2 + 1] != '=') {
return false;
}
}
return true;
}
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (check1(s)) {
cout << "A" << endl;
}else if (check2(s)) {
cout << "B" << endl;
}else {
cout << "NA" << endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp |
#include<iostream>
#include<string>
using namespace std;
int main(){
int f,i,m;
string s;
for(cin>>f;cin>>s;f?puts(f-2?"A":"B"):puts("NA")){
f=0;
for(i=1;s[0]+s[1]==101 & (m=s.find(35))!=string::npos & s[m-i]==s[m+i];)
m-++i-1 | m+i-s.size()+1 | s[m+i]-'~'||(f=1);
for(i=2;s[0]+s[1]==156 & s[i]==81 & s[i+1]==61;)
++++i-s.size()+2 | s[i]+s[i+1]-252 || (f=2);
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
int main() {
int n;
cin >> n;
while(n--) {
string s;
cin >> s;
int f=0;
if (s.substr(0,2) == ">'") {
int i=2, j1=0,j2=0;
for (;i<s.length() && s[i]=='='; i++) j1++;
if (i<s.length() && s[i++] == '#') {
for (;i<s.length() && s[i]=='='; i++) j2++;
if (j1>0 && j1==j2 && i<s.length() && s[i] == '~') {
cout << "A";
f++;
}
}
} else if (s.substr(0,2) == ">^") {
int i = 2;
for (;i<s.length()-1 && s.substr(i,2) == "Q="; i+=2) ;
if (i>2 && s.substr(i,2) == "~~") {
cout << "B";
f++;
}
}
if (f==0)
cout << "NA";
cout << endl;
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.