Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <regex>
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
string s;
smatch m;
for(cin>>n,getline(cin,s);n;n--){
getline(cin,s);
if(regex_match(s,m,regex(">'(=+)#(=+)~"))&&m[1].length()==m[2].length())cout<<'A'<<endl;
else if(regex_match(s,regex(">^(Q=)+~~")))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.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
double EPS=1e-9;
void run(){
for(int n=sc.nextInt(); n>0; n--){
String s=sc.next();
// debug(s);
Matcher m=Pattern.compile("^>'(=+)#(=+)~$").matcher(s);
if(m.find()){
// debug(m.group(1), m.group(2));
if(m.group(1).length()==m.group(2).length()){
// debug("A");
println("A");
continue;
}
}
m=Pattern.compile("^>\\^(Q=)+~~$").matcher(s);
if(m.find()){
// debug("B");
println("B");
continue;
}
// debug("NA");
println("NA");
}
}
void debug(Object... os){
System.err.println(Arrays.deepToString(os));
}
void print(String s){
System.out.print(s);
}
void println(String s){
System.out.println(s);
}
public static void main(String[] args){
// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
new Main().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 | cpp |
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>
#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif
#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c) __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n) REPEAT(i, 0, n)
#define RREP(i, n) RREPEAT(i, 0, n)
#define REPEAT(i, k, n) for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n) for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t) for(int i = f; i < t; i++)
#define ALL(c) (c).begin(), (c).end()
#define LLPOW(p1,p2) ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A) (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p) fgets((p), sizeof(p), stdin)
#define CHOMP(p) do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v) memset(m, v, sizeof(m))
#define mp make_pair
#define pb push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;}
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;}
template <class _Tv> inline string join(_Tv &v,string sep=" "){
ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)
#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,_Tv _c,bool _p=false){
ITER(_c) _it=_c.begin();
if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<" "<<*_it<<endl;cout<<"]"<<endl; }
else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif
string solve(string &s){
int i = 2;
if(s[0] == '>' && s[1] == '\''){
int c = 0;
while(s[i] == '=') c++, i++;
if(c == 0 || s[i] != '#') return "NA";
i++;
while(s[i] == '=') c--, i++;
if(c != 0 || s[i] != '~' || s[i+1] != '\0') return "NA";
return "A";
}
else if(s[0] == '>' && s[1] == '^'){
int c = 0;
while(s[i] == 'Q' && s[i+1] == '=') c++, i+=2;
if(c == 0 || s[i] != '~' || s[i+1] != '~' || s[i+2] != '\0') return "NA";
return "B";
} else {
return "NA";
}
}
int main(){
int n;
cin >> n;
REP(j,n){
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<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
int n; scanf("%d", &n);
rep(i, n) {
string s; cin >> s;
if (s.size() < 4 || s.size() % 2 == 1) {
puts("NA");
continue;
}
if (s[0] == '>'&&s[1] == '\''&&s[s.size() - 1] == '~') {
int cnt = 0;
bool flag = false;
bool ok = false;
for (int i = 2; i < s.size() - 1; i++) {
if (s[i] != '='&&s[i] != '#') { puts("NA"); goto g; }
if (flag&&s[i] == '#') { puts("NA"); goto g; }
if (s[i] == '#')flag = true;
else {
ok = true;
if (flag)cnt--;
else cnt++;
}
}
if (!ok) { puts("NA"); goto g; }
puts(cnt ? "NA" : "A");
}
else if (s[0] == '>'&&s[1] == '^'&&s[s.size() - 2] == '~'&&s[s.size() - 1] == '~') {
if (s.size() == 4) { puts("NA"); goto g; }
for (int i = 2; i < s.size() - 2; i += 2) {
if (s[i] != 'Q' || s[i + 1] != '=') {
puts("NA"); goto g;
}
}
puts("B");
}
else puts("NA");
g:;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Integer;
import java.lang.System;
import java.lang.Exception;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
Pattern a = Pattern.compile(">'(=+)#\\1~");
Pattern b = Pattern.compile(">\\^(Q=)+~~");
int n = Integer.parseInt(r.readLine());
for (int i = 0; i < n; i++) {
String s = r.readLine();
Matcher ma = a.matcher(s);
Matcher mb = b.matcher(s);
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 <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--) {
string snake;
cin >> snake;
string s = snake.substr(0, 2);
if (s != ">^" && s != ">\'") {
puts("NA");
continue;
}
if (s == ">\'") {
int a = 0;
int p = 2;
bool flg = true;
int len = (int)snake.size();
for (int i = 2; i < len; i++, p++) {
if (snake[i] == '#') break;
else if (snake[i] == '=') a++;
else {
flg = false;
break;
}
}
if (!flg) {
puts("NA");
continue;
}
int b = 0, q = p + 1;
for (int i = q; i < len; i++, p++) {
if (snake[i] == '~') break;
else if (snake[i] == '=') b++;
else {
flg = false;
break;
}
}
if (!flg || a == 0 || b == 0 || a != b) {
puts("NA");
continue;
}
if (a == b && snake[len-1] == '~') {
puts("A");
} else {
puts("NA");
}
} else {
bool ok = true;
int p = 0;
string ss = "";
int len = (int)snake.size();
if (len < 6 || len % 2) {
puts("NA");
continue;
}
for (int i = 2; i < len-2; i++, p++) {
ss += snake[i];
if (p == 1) {
p = -1;
if (ss != "Q=") {
ok = false;
break;
}
ss = "";
}
}
if (snake[len-2] == '~' && snake[len-1] == '~' && ok) {
puts("B");
} else {
puts("NA");
}
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
import java.util.regex.*;
class Main {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
for (int ii = 0; ii < n; ii++) {
String str = scanner.nextLine();
Pattern pa = Pattern.compile("^>'(=+)#\\1~$");
Pattern pb = Pattern.compile("^>\\^(?:Q=)+~~$");
Matcher ma = pa.matcher(str);
Matcher mb = pb.matcher(str);
if (ma.find()) {
System.out.println("A");
} else if (mb.find()) {
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 <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>
using namespace std;
using namespace placeholders;
using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > struct getv_fmt;
template <> struct getv_fmt< int >{ static constexpr const char *fmt = "%d"; };
template <> struct getv_fmt< long long >{ static constexpr const char *fmt = "%lld"; };
template < typename T > void getv( std::vector< T > &v ){ for_each( begin( v ), end( v ), []( T &a ){ scanf( getv_fmt< T >::fmt, &a ); } ); };
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }
#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )
#define DRANGE( c, p ) begin( c ), begin( c ) + ( p ), end( c )
#define SZ( v ) ( (int)( v ).size() )
#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )
template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter
#define MP make_pair
#define fst first
#define snd second
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
bool is_a( const string &S )
{
const int Ls = SZ( S );
if ( S.find( ">'" ) != 0 || S.find( "~" ) != Ls - 1 )
{
return false;
}
string T = S.substr( 2, Ls - 3 );
const int Lt = SZ( T );
if ( Lt % 2 == 0 || Lt < 3 || T[ Lt / 2 ] != '#' )
{
return false;
}
T[ Lt / 2 ] = '=';
return all_of( ALL( T ), bind( equal_to< char >(), _1, '=' ) );
}
bool is_b( const string &S )
{
const int Ls = SZ( S );
if ( S.find( ">^" ) != 0 || S.find( "~~" ) != Ls - 2 )
{
return false;
}
const string T = S.substr( 2, Ls - 4 );
const int Lt = SZ( T );
if ( Lt == 0 || Lt % 2 )
{
return false;
}
for ( int i = 0; i < Lt; i += 2 )
{
if ( T[i] != 'Q' || T[ i + 1 ] != '=' )
{
return false;
}
}
return true;
}
int main()
{
cin.tie( 0 );
ios::sync_with_stdio( false );
cout << setprecision( 12 ) << fixed;
int N;
cin >> N;
REP( N )
{
string S;
cin >> S;
string res = "NA";
if ( is_a( S ) )
{
res = "A";
}
if ( is_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<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin>>n;
while(n--){
string s;
cin>>s;
bool f=s[0]=='>';
int l=s.size();
f&=l>5;
if(s[1]=='\''){
int x=0;
int i;
for(i=2;i<l;i++){
if(s[i]=='=') x++;
else{
f&=s[i]=='#';
break;
}
}
for(i++;i<l;i++){
if(s[i]=='=') x--;
else{
f&=s[i]=='~';
break;
}
}
f&=i==l-1&&x==0;
}else if(s[1]=='^'){
int i;
for(i=2;i<l;i+=2){
if(!(i+1<l)){
f=0;
break;
}
if(s[i]=='Q'&&s[i+1]=='=') continue;
if(i+2==l&&s[i]=='~'&&s[i+1]=='~') continue;
break;
}
f&=i==l;
}else f=0;
cout<<(f?(s[1]=='^'?"B":"A"):"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>
int main(){int f,i,m;std::string s;for(std::cin>>f;std::cin>>s;f?puts(f-2?"A":"B"):puts("NA")){f=0;for(i=1;s[0]+s[1]==101&(m=s.find(35))!=-1&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<string>
using namespace std;
int main(){
int n;
string s;
cin>>n;
for(int u=0;u<n;u++){
cin>>s;
bool a=true,b=true;
if(s[0]!='>'||s.size()%2!=0||s.size()<6)a=false,b=false;
if(s[1]!='\''||s[s.size()-1]!='~')a=false;
if(s[1]!='^'||s[s.size()-1]!='~'||s[s.size()-2]!='~')b=false;
if(a){
if(s[s.size()/2]!='#')a=false;
int count=0;
for(int i=2;i<s.size()-1;i++)if(s[i]!='=')count++;
if(count!=1)a=false;
if(a)cout<<"A"<<endl;
}
if(b){
for(int i=2;i<s.size()-2;i++){
if(i%2==0&&s[i]!='Q')b=false;
if(i%2==1&&s[i]!='=')b=false;
}
if(b)cout<<"B"<<endl;
}
if(!a&&!b)cout<<"NA"<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | from re import match
A = r"^>'(=+)#\1~$"
B = r"^>\^(Q=)+~~$"
for _ in xrange(input()):
s = raw_input()
if match(A,s) != None:
print "A"
elif match(B,s) != None:
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 <stdio.h>
#include <string.h>
int main(void) {
int max,data;
int num;
int cut_i;
char hebi[201];
scanf("%d",&max);
for(data=0;data<max;data++) {
scanf("%s",hebi);
if(strlen(hebi)<2 || hebi[0]!='>') {
puts("NA");
continue;
}
if(hebi[1]=='\'') {
num=0;
cut_i=2;
while(hebi[cut_i]=='=') {
cut_i++;
num++;
}
if(hebi[cut_i]!='#' || num<=0){
puts("NA");
}
else {
cut_i++;
while(hebi[cut_i]=='=') {
cut_i++;
num--;
}
if(num!=0){
puts("NA");
}
else if(hebi[cut_i]!='~' || hebi[cut_i+1]!=0){
puts("NA");
}
else {
puts("A");
}
}
}
else if(hebi[1]=='^') {
cut_i=2;
while(hebi[cut_i]=='Q' && hebi[cut_i+1]=='='){
cut_i+=2;
}
if(cut_i==2){
puts("NA");
}
else if(hebi[cut_i]!='~' || hebi[cut_i+1]!='~' || hebi[cut_i+2]!=0){
puts("NA");
}
else {
puts("B");
}
} else {
puts("NA");
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | # -*- coding: utf-8 -*-
import sys
import os
N = int(input())
def is_A(s):
if s[0:2] != ">'":
return False
if s[-1] != '~':
return False
body = s[2:-1]
if len(body) % 2 == 0:
return False
# body = '==#=='
center_index = len(body) // 2
if body[center_index] != '#':
return False
if body.count('#') != 1:
return False
lst = body.split('#')
if len(lst) != 2:
return False
if len(lst[0]) > 0 and lst[0] == lst[1] and len(lst[0]) == lst[0].count('='):
return True
else:
return False
def is_B(s):
if s[0:2] != ">^":
return False
if s[-2:] != '~~':
return False
body = s[2:-2]
if len(body) % 2 != 0:
return False
elif body.count('Q=') > 0 and body.count('Q=') == len(body) // 2:
return True
else:
return False
for s in sys.stdin:
s = s.strip()
if is_A(s):
print('A')
elif is_B(s):
print('B')
else:
print('NA') |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | import re
a = ">'(=+)#(=+)~$"
b = ">\^(Q=)+~~$"
n = int(input())
for _ in range(n):
s = input()
r = re.match(a, s)
if r and r.group(1) == r.group(2):
print('A')
elif re.match(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 <bits/stdc++.h>
using namespace std;
bool checkA(char* s){
if(s[0] != '>' || s[1] != '\'' || s[2] != '='){
return false;
}
int slen = 0;
while(s[slen+2] == '='){
slen++;
}
if(s[slen+2] != '#'){
return false;
}
for(int i = slen+3; i < slen*2+3;i++){
if(s[i] != '='){
return false;
}
}
return (s[slen*2+3] == '~' && s[slen*2+4] == '\0');
}
bool checkB(char* s){
if(s[0] != '>' || s[1] != '^' || s[2] != 'Q' || s[3] != '='){
return false;
}
int slen = 0;
while(s[slen*2+2] == 'Q' && s[slen*2+3] == '='){
slen++;
}
return (s[slen*2+2] == '~' && s[slen*2+3] == '~' && s[slen*2+4] == '\0');
}
int main(){
int n;
char S[1024];
scanf("%d",&n);
for(int step = 0; step < n; step++){
scanf("%s",S);
if(checkA(S)){
printf("A\n");
}
else if(checkB(S)){
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 | cpp | #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
int N,j;
cin>>N;
while(N--){
int runcnt=0,j;
char S[128000]={0};
cin>>S;
if(S[0]=='>'&&S[1]==39){
int K=0;
for(j=2;;j++){
if(S[j]=='='){
runcnt++;
K=1;
}
else if(S[j]=='#'){
break;
}
else {
cout<<"NA"<<endl;
goto end;
}
}
for(int i = j + 1;;i++){
if(S[i] == '='){
runcnt--;
}
else if(runcnt == 0 && S[i] == '~' && K == 1){
cout<<"A"<<endl;
goto end;
}
else{
cout<<"NA"<<endl;
goto end;
}
}
}
else if(S[0] == '>' && S[1] == '^'){
int F = 0;
for(j = 2;;){
if(S[j] == 'Q' && S[j + 1] == '='){
j += 2;
F = 1;
}
else if(S[j] == '~' && S[j+1] == '~' && F == 1){
cout<<"B"<<endl;
goto end;
}
else{
cout<<"NA"<<endl;
goto end;
}
}
}
else cout<<"NA"<<endl;
end:;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#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>
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 EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#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)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
int main() {
int n;
cin >> n;
REP(i, n) {
string s;
cin >> s;
string h = s.substr(0, 2);
if(h == ">'") {
s += "!";
if(s.find('#') != string::npos && s.find('=') != string::npos) {
int pos = s.find('#');
int size = pos-2;
REP(i, pos-2) {
if(s[i+2] == s[i+pos+1] && s[i+2] == '=') {
} else {
cout << "NA" << endl;
goto next;
}
}
if(s[pos+size+1] == '~' && s[pos+size+2] == '!') {
cout << "A" << endl;
goto next;
} else {
cout << "NA" << endl;
goto next;
}
} else {
cout << "NA" << endl;
goto next;
}
} else if(h == ">^") {
s += "!!";
int b = 2;
bool flag = false;
while(s.substr(b, 2) == "Q=") {
b += 2;
flag = true;
}
if(s.substr(b, 2) == "~~" && s.substr(b+2, 2) == "!!" && flag) {
cout << "B" << endl;
goto next;
} else {
cout << "NA" << endl;
goto next;
}
} else {
cout << "NA" << endl;
goto next;
}
next:;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
int solve(string &s){
if(s.length() >= 6 && s.substr(0, 2) == ">'" && s[(int)s.length() - 1] == '~'){
int c1 = 0, c2 = 0, t = 0, f = 0;
for(int i = 2; i + 1 < (int)s.length(); ++i){
if(s[i] != '=' && s[i] != '#') f = 1;
if(s[i] == '#' && t >= 1) f = 1;
if(f) break;
if(s[i] == '#') ++t;
else if(t) ++c2;
else ++c1;
}
if(!f && c1 == c2) return 0;
}
if(s.length() >= 6 && s.substr(0, 2) == ">^" && s.substr((int)s.length() - 2) == "~~"){
int f = 0;
for(int i = 2; i + 2 < s.length(); i += 2) if(s.substr(i, 2) != "Q=") f = 1;
if(!f) return 1;
}
return -1;
}
int main() {
int T; cin >>T;
REP(t, T){
string s; cin >>s;
int ans = solve(s);
cout <<(ans == 0 ? "A" : (ans == 1 ? "B" : "NA")) <<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
bool f(string s) {
int l = 0, r = 0, sz = s.size();
while (r < sz && s[r] == '=') r++;
if (r - l == 0) return false;
if (r < sz && s[r] != '#') return false;
if (s.substr(r + 1, r - l) != string(r - l, '=')) return false;
r += 1 + r - l;
if (r + 1 != sz || s[r] != '~') return false;
return true;
}
bool g(string s) {
int sz = s.size();
if (sz % 2 == 1 || sz == 2) return false;
for (int i = 0; i < sz; i += 2) {
if (s.substr(i, 2) == "Q=") continue;
if (s.substr(i, 2) == "~~" && i + 2 == sz) break;
return false;
}
return true;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(10);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string S;
cin >> S;
if (S.substr(0, 2) == ">'") {
cout << (f(S.substr(2)) ? "A" : "NA") << endl;
} else if (S.substr(0, 2) == ">^") {
cout << (g(S.substr(2)) ? "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 | cpp | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
getchar();
for(int i = 0; i < n; i++) {
string snake;
getline(cin, snake);
string ans = "NA";
if(snake[0] == '>' && snake[1] == '\'' && snake.length() >= 6) {
int shape = 0;
for(int i = 2; i < snake.length(); i++) {
if(i+1 >= snake.length()) {
if(snake[i] == '~') ans = "A";
} else {
if(snake[i] != '=' && snake[i] != '#') break;
if(snake[i] == '#') {
if(shape == 1) break;
else {
shape++;
if(i-2 != (double)(snake.length()-4)/2) break;
}
}
}
}
} else if(snake[0] == '>' && snake[1] == '^' && snake.length()%2 == 0 && snake.length() >= 6) {
for(int i = 3; i < snake.length(); i+=2) {
if(i+2 >= snake.length()) {
if(snake[i-1] == '~' && snake[i] == '~') ans = "B";
} else {
if(snake[i-1] != 'Q' || snake[i] != '=') break;
}
}
}
cout << ans << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | //Name: Snakes
//Level: 2
//Category: 文字列,オートマトン
//Note:
/**
* AとBは別々に判定する。
*/
#include <iostream>
#include <string>
using namespace std;
bool snakeA(const string &s) {
auto it = begin(s);
int cnt = 0;
if(*it++ != '>') return false;
if(*it++ != '\'') return false;
while(true) {
const char c = *it++;
if(c == '#') break;
else if(c == '=') ++cnt;
else return false;
}
if(cnt == 0) return false;
while(cnt--) {
if(*it++ != '=') return false;
}
if(*it++ != '~') return false;
return it == end(s);
}
bool snakeB(const string &s) {
auto it = begin(s);
if(*it++ != '>') return false;
if(*it++ != '^') return false;
bool ok = false;
while(true) {
const char c = *it++;
if(c == '~') break;
else if(c != 'Q') return false;
if(*it++ != '=') return false;
ok = true;
}
if(!ok) return false;
if(*it++ != '~') return false;
return it == end(s);
}
bool solve(bool first) {
string s;
cin >> s;
if(snakeA(s)) cout << "A" << endl;
else if(snakeB(s)) cout << "B" << endl;
else cout << "NA" << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(2);
bool first = true;
int N;
cin >> N;
while(N-- && solve(first)) {
first = false;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
for(int D = 0; D < n; ++D){
string s;
cin>>s;
if(s.compare(0,2,">'")== 0){
int bef_eq = 0;
int aft_eq = 0;
int shp = 0;
int pos_shp = 0;
int pos_tld = 0;
for(unsigned int i = 2; i < s.length(); ++i ){
if( s[i] == '=' )
if( shp == 0 )
++bef_eq;
else
++aft_eq;
else if( s[i] == '#' ){
shp++;
}else if( s[i] == '~' ){
pos_tld = i;
break;
}else{
shp = 2;
break;
}
}
if( bef_eq && aft_eq && pos_tld && bef_eq == aft_eq &&
shp == 1 && pos_tld == s.length() - 1 )
cout << "A\n";
else
cout << "NA\n";
}else if(s.compare(0,2,">^")==0){
int cnt_qeq = 0;
int pos_tltl = 0;
bool invalid = false;
if( s.length() <= 2 || s.length() % 2 == 1 )
invalid = true;
for(unsigned int i = 2; i < s.length() && !invalid; i+=2){
if( s.compare(i,2,"Q=") == 0 )
++cnt_qeq;
else if( s.compare(i,2,"~~") == 0 ){
pos_tltl = i;
break;
}else
invalid = true;
}
if( cnt_qeq == 0 || pos_tltl != s.length() - 2 ){
invalid = true;
}
if( invalid )
cout << "NA\n";
else
cout << "B\n";
}else{
cout <<"NA\n";
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
int main()
{
int n; cin >> n;
while (n--) {
string s; cin >> s;
string head = s.substr(0, 2);
bool ok = true;
if (head == ">'") {
int c = 0;
REP(i, 2, s.size()) { if (s[i] != '=') break; c++; }
if (c < 1) ok = false;
else if (s[c+2] != '#') ok = false;
else if (s.substr(c+3, c) != string(c, '=')) ok = false;
else if (s.size() != c*2 + 4) ok = false;
else if (s[s.size()-1] != '~') ok = false;
puts(ok ? "A" : "NA");
}
else if (head == ">^") {
if (s.substr(2, 2) != "Q=") ok = false;
else {
for (int i = 4; i < s.size()-2; i+=2)
if (s.substr(i, 2) != "Q=") { ok = false; break; }
if (ok && s.substr(s.size()-2) != "~~") ok = false;
}
puts(ok ? "B" : "NA");
}
else puts("NA");
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
string afunc(string str)
{
string res = "NA";
if(str[0] == '#'){
return res;
}
for(int i = 0, j = str.size()-1; i <= j; i++, j--){
if(i == j){
if(str[i] == '#'){
res = "A";
}
} else if(str[i] != '=' || str[j] != '='){
break;
}
}
return res;
}
string bfunc(string str)
{
string res = "B";
if(str.size() == 0){
return "NA";
}
for(int i = 0; i < str.size(); i+=2){
if(str[i] != 'Q' || str[i+1] != '='){
res = "NA";
break;
}
}
return res;
}
int main()
{
int n;
string str, res;
while(cin >> n && n){
while(n--){
cin >> str;
res = "NA";
if('>' == str[0]){
str.erase(str.begin());
int l = str.size();
if(str[0] == '\'' && str[l-1] == '~'){
str.erase(str.end()-1);
str.erase(str.begin());
if(str.size()%2 == 1){
res = afunc(str);
}
} else if(str[0] == '^' && str[l-1] == str[l-2] && str[l-1] == '~'){
str.erase(str.end()-1);
str.erase(str.end()-1);
str.erase(str.begin());
if(str.size()%2 == 0){
res = bfunc(str);
}
}
}
cout << res << endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | import re
ptA = re.compile(r"^>'(=+)#\1~$")
ptB = re.compile(r"^>\^(?:Q=)+~~$")
for i in xrange(input()):
s = raw_input()
if ptA.match(s):
print "A"
elif ptB.match(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<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 10000000
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
char snake[256]={0};
int check(int len){
if(len % 2 == 1)return INF;
if(snake[0] == '>'){
if(snake[1] == 39){
if(snake[len-1] != '~')return INF;
int cnt = 0;
int x = 0;
rep(i,len){
if(snake[i] == '#'){
cnt++;
x = i;
}
}
if(cnt != 1)return INF;
if(snake[2] != '=')return INF;
reps(i,3,x){
if(snake[i] != '=')return INF;
}
reps(i,x+1,len-1){
if(snake[i] != '=')return INF;
}
return (x-2 == len-x-2) ? 1 : INF;
}
else if(snake[1] == '^'){
if(snake[len-1] != '~' || snake[len-2] != '~')return INF;
if(snake[2] != 'Q' || snake[3] != '=')return INF;
for(int i = 4; i < len-2; i += 2){
if(snake[i] != 'Q' || snake[i+1] != '=')return INF;
}
return 0;
}
}
return INF;
}
int main(){
int n;
scanf("%d",&n);
rep(q,n){
memset(snake,0,sizeof(snake));
scanf("%s",snake);
int len = strlen(snake);
int res = check(len);
(res == 1) ? puts("A") : (res == 0) ? puts("B") : puts("NA");
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
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 != ""){
int pos;
while(pos = st.find("="), pos != std::string::npos){
st.replace(pos,1,"");
}
if(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 != ""){
int pos;
while(pos = st.find("Q="), pos != std::string::npos){
st.replace(pos,2,"");
}
if(st == "")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 <iostream>
#include <string>
using namespace std;
bool is_A(string s){
int size = s.size();
if(size < 6) return false;
if(s[0] != '>' || s[1] != '\'') return false;
if(s[size - 1] != '~') return false;
if(s[2] != '=') return false;
int count = 0;
int i = 2;
while(s[i] == '='){ count++; i++; }
if(s[i++] != '#') return false;
for(int j = 0; j < count; j++, i++){
if(s[i] != '=') return false;
}
if(i == size - 1) return true;
else return false;
}
bool is_B(string s){
int size = s.size();
if(size < 6) return false;
if(s[0] != '>' || s[1] != '^') return false;
if(s[size - 1] != '~' || s[size - 2] != '~') return false;
int i = 2;
while(i < size - 2){
if(s[i] != 'Q' || s[i+1] != '=') return false;
i += 2;
}
return true;
}
int main(){
string s;
int n;
cin >> n;
getline(cin, s);
for(int i = 0; i < n; i++){
getline(cin, s);
if(is_A(s)) cout << "A";
else if(is_B(s)) cout << "B";
else cout << "NA";
cout << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static BufferedReader br = null;
static {
br = new BufferedReader(new InputStreamReader(System.in));
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int cnt = parseNum();
while (cnt-- > 0) {
parseSnake();
}
}
private static void parseSnake() {
int typ = 0;
String str = null;
if ((str = parseStdin()) != null) {
int len = str.length();
if (len >= 6 && len%2 == 0) {
if (str.charAt(0) == '>') {
if (str.charAt(1) == '\'') {
if (str.charAt(len-1) == '~' && str.charAt(len-2) == '=') {
if (str.charAt(2) == '=') {
char stc = 0;
int mid = 2+(len-4)/2;
for (int i = 2; i < len-1; i++) {
stc = str.charAt(i);
typ = (i == 2) ? 1 : typ;
if ((stc != '=' && stc != '#') || (stc == '#' && i != mid) || (stc != '#' && i == mid)) {
typ = 0;
break;
}
}
}
}
}
else if (str.charAt(1) == '^') {
if (str.charAt(len-1) == '~' && str.charAt(len-2) == '~' && str.charAt(len-3) == '=') {
char sc1 = 0;
char sc2 = 0;
for (int i = 2; i+1 < len-2; i += 2) {
typ = (i == 2) ? 2 : typ;
sc1 = str.charAt(i);
sc2 = str.charAt(i+1);
if (sc1 != 'Q' || sc2 != '=') {
typ = 0;
break;
}
}
}
}
}
}
}
switch (typ) {
case 1:
System.out.println("A");
break;
case 2:
System.out.println("B");
break;
default:
System.out.println("NA");
break;
}
}
private static int parseNum() {
int num = 0;
String str = null;
if ((str = parseStdin()) != null) {
num = Integer.parseInt(str);
}
return num;
}
private static String parseStdin() {
String stdin = null;
try {
String tmp = br.readLine();
if (tmp != null) {
if (!tmp.isEmpty()) stdin = tmp;
}
}
catch (IOException e) {}
return stdin;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define rep(i, n)for((i) = 0;(i) < (n);++(i))
string solve(string s){
int i = 0, j;
string tmp;
rep(i, 100){
tmp += "=";
if(s == ">'" + tmp + "#" + tmp + "~")return "A";
}
tmp.clear();
rep(i, 100){
tmp += "Q=";
if(s == ">^" + tmp + "~~")return "B";
}
return "NA";
}
int main(void){
int i, j, n;
string s;
scanf("%d", &n);
for(;n--;){
cin >> s;
cout << solve(s) << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
int main(){
string snake;
int n,len;
cin >> n;
for(int i=0;i<n;i++){
cin >> snake;
len = snake.size();
int ans = -1;
if(snake[0] == '>' && snake[1] == '\''){
int pos = 2;
int turn = 0;
int flag = 0;
int count = 0;
do{
if(turn && snake[pos] == '=')count--;
else if(snake[pos] == '=') count++;
else if(snake[pos] == '#')turn = 1;
else flag = 0;
if(pos == 2 && count > 0)flag = 1;
pos++;
}while(pos < len-1);
if(count == 0 && flag && snake[pos] == '~')ans = 0;
}else if(snake[0] == '>' && snake[1] == '^'){
int pos = 2;
int flag = 1;
do{
if(snake[pos] != 'Q' || snake[pos+1] != '='){
flag = 0;
break;
}
pos += 2;
}while(pos < len-2);
if(flag && snake[pos] == '~' && snake[pos+1] == '~')ans = 1;
}
if(ans == 0)cout << 'A' << endl;
else if(ans == 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>
using namespace std;
void solve()
{
int n;
cin >> n;
while(n--)
{
string snake;
cin >> snake;
if(snake.size() < 4)
{
cout << "NA" << endl;
}
else if(snake[0] == '>' && snake[1] == '\'' && snake[snake.size() - 1] == '~')
{
bool first = true;
int count1 = 0;
int count2 = 0;
for(int i = 2; i < snake.size() - 1; ++i)
{
if(snake[i] == '=')
{
if(first)
{
++count1;
}
else
{
++count2;
}
}
else if(snake[i] == '#')
{
first = false;
}
else
{
cout << "NA" << endl;
goto END;
}
}
if(count1 == count2 && count1 >= 1)
{
cout << "A" << endl;
}
else
{
cout << "NA" << endl;
}
}
else if(snake[0] == '>' && snake[1] == '^' && snake[snake.size() - 2] == '~' && snake[snake.size() - 1] == '~')
{
bool flag = true;
int count = 0;
for(int i = 2; i < snake.size() - 2; i += 2)
{
if(snake[i] != 'Q' || snake[i + 1] != '=')
{
flag = false;
break;
}
if(snake[i] == 'Q' && snake[i + 1] == '=')
{
++count;
}
}
if(flag && count)
{
cout << "B" << endl;
}
else
{
cout << "NA" << endl;
}
}
else
{
cout << "NA" << endl;
}
END:
;
}
}
int main()
{
solve();
return(0);
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
double EPS=1e-9;
void run(){
for(int n=sc.nextInt(); n>0; n--){
String s=sc.next();
Matcher m=Pattern.compile("^>'(=+)#(=+)~$").matcher(s);
if(m.find()){
if(m.group(1).length()==m.group(2).length()){
println("A");
continue;
}
}
m=Pattern.compile("^>\\^(Q=)+~~$").matcher(s);
if(m.find()){
println("B");
continue;
}
println("NA");
}
}
void debug(Object... os){
System.err.println(Arrays.deepToString(os));
}
void print(String s){
System.out.print(s);
}
void println(String s){
System.out.println(s);
}
public static void main(String[] args){
// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
new Main().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 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0139
"""
import sys
from sys import stdin
import re
input = stdin.readline
def identify_snake(snake):
# ????????????>`???????¶???????1?????\?????????=]??????#??????????????§1?????\?????????=??????????????????~??????????????¨?????????=?????°?????????
patternA = re.compile("^>'(=+)#(=+)~")
resultA = patternA.search(snake)
if resultA:
pre, post = resultA.groups()
if pre == post:
return 'A'
# ????????????>^???????¶???????1?????\?????????Q=]???????????????????????????~~???
patternB = re.compile("^>\^(Q=)+~~")
resultB = patternB.search(snake)
if resultB:
return 'B'
return 'NA'
def main(args):
n = int(input())
for _ in range(n):
snake = input()
result = identify_snake(snake)
print(result)
if __name__ == '__main__':
main(sys.argv[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>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
string s;
int n;
cin >> n;
rep(i,n) {
cin >> s;
int len = s.length();
bool fa = 0, fb = 0;
if(len > 5 && len % 2 == 0) {
fa = 1;
string ns;
ns += s.substr(2,len/2-2);
ns += s.substr(len/2+1,len/2-2);
rep(i,ns.length()) {
if(ns[i] != '=') fa = 0;
}
if(s[0] != '>' || s[1] != '\'' || s[len/2] != '#' || s[len-1] != '~') {
fa = 0;
}
fb = 1;
rep2(i,1,(len-2)/2) {
if(s[2*i] != 'Q' || s[2*i+1] != '=') fb = 0;
}
if(s[0] != '>' || s[1] != '^' || s[len-2] != '~' || s[len-1] != '~') {
fb = 0;
}
}
if(fa) cout << "A" << endl;
else if(fb) 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>
using namespace std;
int n;
string s;
int main()
{
cin>>n;
for(;n--;)
{
cin>>s;
string t="NA";
if(s.substr(0,2)==">'")
{
int cnt=0;
int i=2;
while(i<s.size()&&s[i]=='=')i++,cnt++;
if(cnt>0&&s[i]=='#')
{
int j=i+1;
while(j<s.size()&&s[j]=='=')j++,cnt--;
if(cnt==0&&j+1==s.size()&&s.substr(j,1)=="~")t="A";
}
}
else if(s.substr(0,2)==">^")
{
int i=2;
while(i+2<s.size()&&s.substr(i,2)=="Q=")i+=2;
if(i>2&&i+2==s.size()&&s.substr(i,2)=="~~")
{
t="B";
}
}
cout<<t<<endl;
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.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.find();
}
private static boolean isSnakeB(String snake) {
String sb = "^>\\^(Q=)+~~$";
Pattern pb = Pattern.compile(sb);
Matcher mb = pb.matcher(snake);
return mb.find();
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 printNA() {
cout << "NA" << endl;
}
void judgeB(string s) {
if (s.substr(s.size() - 2, 2) != "~~") {
printNA();
return;
}
if (s.size() <= 4) {
printNA();
return;
}
for (int i = 2; i < s.size() - 2; i += 2) {
if (s.substr(i, 2) != "Q=") {
printNA();
return;
}
}
cout << "B" << endl;
}
void judgeA(string s) {
int len = 0;
int i;
for (i = 2; s[i] == '='; i++) {
len++;
}
if (len == 0 || s.size() < i || s[i] != '#') {
printNA();
return;
}
if (s.size() < 2 + 2 * len) {
printNA();
return;
}
for (i++ ; i <= 2 + 2 * len; i++) {
if (s[i] != '=') {
printNA();
return;
}
}
if (s.size() == i || s[i] != '~') {
printNA();
} else {
cout << "A" << endl;
}
}
int main() {
int n;
cin >> n;
for (int c = 0; c < n; c++) {
string s;
cin >> s;
if (s.substr(0, 2) == ">'") {
judgeA(s);
} else if (s.substr(0, 2) == ">^") {
judgeB(s);
} else {
cout << "NA" << endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(void){
int n;
cin >> n;
for(int i=0;i<n;i++){
string str;
cin >> str;
if(str.size()<2)cout << "NA" << endl;
else if(str[0]=='>' && str[1]=='\''){
int j=2;
int l[2]={0,0};
int ck=0;
bool ch[2]={false,true};
while(j<str.size()){
if(str[j]=='=')l[ck]++;
else if(str[j]=='#' && l[0]>0)ch[0]=true,ck=1;
else if(str[j]=='~')break;
else ch[1]=false;
j++;
}
if(ch[0]==true && ch[1]==true && l[0]==l[1])cout << "A" << endl;
else cout << "NA" << endl;
}else if(str[0]=='>' && str[1]=='^'){
if(str.size()%2==1 || str.size()<6)cout << "NA" << endl;
else{
bool ch=true;
for(int j=2;j<str.size()-2;j+=2){
if(str[j]!='Q' || str[j+1]!='=')ch=false;
}
if(str[str.size()-2]!='~' || str[str.size()-1]!='~')ch=false;
if(ch==true)cout << "B" << endl;
else cout << "NA" << endl;
}
}else cout << "NA" << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.lang.*;
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
String s=sc.next();
if(s.matches("^>'(=+)#\\1~$"))
System.out.println("A");
else if(s.matches("^>\\^(Q=)+~~$"))
System.out.println("B");
else
System.out.println("NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
int n;
string s;
bool checkA(string s) {
if (s.length() < 6) return false;
if (s[0] != '>') return false;
if (s[1] != '\'') return false;
int i;
for (i = 2; i < s.length() && s[i] == '='; i++);
if (i == s.length() || s[i] != '#') return false;
int cnt = i - 2;
for (i = i + 1; i < s.length() && s[i] == '='; i++, cnt--);
if (cnt != 0) return false;
if (s.length() != i + 1) return false;
if (s[i] != '~') return false;
return true;
}
bool checkB(string s) {
if (s.length() < 6) return false;
if (s[0] != '>') return false;
if (s[1] != '^') return false;
int i;
for (i = 2; i < s.length(); i += 2) {
if (i + 1 >= s.length()) return false;
if (s[i] != 'Q') break;
if (s[i + 1] != '=') return false;
}
if (s.length() != i + 2) return false;
if (s[i] != '~' || s[i + 1] != '~') return false;
return true;
}
int main() {
cin >> n;
while (n--) {
cin >> s;
if (checkA(s)) cout << "A" << endl;
else if (checkB(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 <vector>
#include <algorithm>
#include <string>
using namespace std;
void a(){
cout << "NA" << endl;
return;
}
int main(){
int n;
vector<string> sample;
string aaa;
cin >> n;
for(int i=0;i<n;i++){
cin >> aaa;
sample.push_back(aaa);
}
for(unsigned int i=0;i<sample.size();i++){
string snake = sample[i];
string::size_type aruyon;
if((aruyon = snake.find(">'"))==0){
int equal=0;
int j;
for(j=2;snake.at(j)=='=';j++) equal++;
if(equal > 0)
if(snake.at(j) == '#'){
j++;
for(;snake.at(j)=='=';j++) equal--;
if(equal == 0){
if(snake.at(j)=='~' && j+1 == snake.size()) cout << 'A' << endl;
else a();
}
else a();
}
else a();
else a();
}
else if((aruyon = snake.find(">^"))==0){
int j;
bool dou = false;
aruyon = snake.find("~~");
if(aruyon == snake.size() -2){
if(aruyon%2==0){
for(j=2;j<aruyon;j++){
dou = false;
if(snake.at(j) == 'Q') j++;
else break;
if(snake.at(j) == '=') dou = true;
else break;
}
if(dou) cout << 'B' << endl;
else a();
}
else a();
}
else a();
}
else
a();
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
import java.util.regex.*;
class Main {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
for (int ii = 0; ii < n; ii++) {
String str = scanner.nextLine();
Pattern pa = Pattern.compile("^>'(=+)#\\1~$");
Pattern pb = Pattern.compile("^>\\^(?:Q=)+(?:~~)$");
Matcher ma = pa.matcher(str);
Matcher mb = pb.matcher(str);
if (ma.find()) {
System.out.println("A");
} else if (mb.find()) {
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<string>
using namespace std;
int count( string str, string t, int &curr ){
int cnt = 0;
for( ; curr + t.size() - 1 < str.size(); cnt++, curr += t.size() ){
if( str.substr(curr, t.size()) != t ) break;
}
return cnt;
}
bool isA( string str, int curr ){
if ( str.substr(0, curr) != ">'" ) return false;
int cnt = count(str, "=", curr);
if ( cnt < 1 || str[curr++] != '#' ) return false;
if ( cnt != count(str, "=", curr) ) return false;
return ( curr == str.size()-1 && str[curr] == '~');
}
bool isB( string str, int curr ){
if ( str.substr(0, curr) != ">^" ) return false;
int cnt = count(str, "Q=", curr);
return ( cnt && curr == str.size()-2 && str.substr(str.size()-2, 2) == "~~");
}
int main(){
int tcase; cin >> tcase;
for ( int i = 0; i < tcase; i++ ) {
string snake; cin >> snake;
if ( isA(snake, 2) ) cout << "A" << endl;
else if ( isB(snake, 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,size;
string s,a,b;
for(cin>>n,getline(cin,s,'\n');n>0;n--){
getline(cin,s,'\n');
//cin>>s;
size = s.size();
if(size<6||size%2){cout<<"NA"<<endl;continue;}
a=">'"; b=">^";
for(int i=0;i<size/2-2;i++){a=a+"=";b=b+"Q=";}
a+="#";
for(int i=0;i<size/2-2;i++){a=a+"=";}
a+="~"; b+="~~";
if (s==a)cout<<"A"<<endl;
else if (s==b)cout<<"B"<<endl;
else cout<<"NA"<<endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;
//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
signed main() {
int n; cin >> n;
regex b(R"(>\^(Q=)+~~)");
rep(i, 0, n) {
string s; cin >> s;
int m = 0;
rep(j, 0, s.size())if (s[j] == '=')m++;
regex a(">'={" + to_string(m / 2) + "}#={" + to_string(m / 2) + "}~");
if (regex_match(s, a) && m) { cout << "A" << endl; }
else if (regex_match(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>
#include <cstdio>
using namespace std;
string vbString(int Number,string Character){
string res="";
for(int i=0;i<Number;i++) res+=Character;
return res;
}
string checksnake(string s){
string t;
for(int i=1;i<100;i++){
t=">'"+vbString(i,"=")+"#"+vbString(i,"=")+"~";
if(t==s) return "A";
}
for(int i=1;i<100;i++){
t=">^"+vbString(i,"Q=")+"~~";
if(t==s) return "B";
}
return "NA";
}
int main(){
int n;
cin >> n;
while(n--){
string s;
cin >> s;
cout << checksnake(s) << endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.Scanner;
public class Main {
Scanner sc;
private void run () {
sc = new Scanner( System.in );
int n = sc.nextInt();
for( int i = 0; i < n; i++ ) {
String line = sc.next();
if( line.matches( "^\\>\\'(\\=+)\\#\\1~$" ) ) {
System.out.println( "A" );
} else if( line.matches( "^\\>\\^(Q=)+(~~)$" ) ) {
System.out.println( "B" );
} else {
System.out.println( "NA" );
}
}
}
public static void main( String[] args ) {
new Main().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 | python2 | for i in [0]*input():
s=raw_input()
n=(len(s)-4)/2
if s==">'"+"="*n+"#"+"="*n+"~": t="A"
elif s==">^"+"Q="*n+"~~": t="B"
else: t="NA"
if n<1: t="NA"
print t |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 <algorithm>
#include <string>
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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>
typedef long long ll;
const double Eps = 1e-6;
using namespace std;
int main()
{
char buf[256];
int n;
scanf("%d\n", &n);
while (n--)
{
cin.getline(buf, sizeof(buf));
string s(buf);
bool ok = false;
for (int i = 1; i < 100; ++i)
{
string a = ">'";
for (int j = 0; j < i; ++j)
a += "=";
a += "#";
for (int j = 0; j < i; ++j)
a += "=";
a += "~";
if (s == a)
{
puts("A");
ok = true;
break;
}
string b = ">^";
for (int j = 0; j < i; ++j)
b += "Q=";
b += "~~";
if (s == b)
{
puts("B");
ok = true;
break;
}
}
if (!ok)
puts("NA");
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
int N;
cin>>N;
while(N--){
string str;
cin>>str;
int len=str.size();
int ans=-1;
if(str[0]=='>'&&str[1]=='\''){
int pos=2;
int cnt=0;
int turn=0;
int flag=0;
do{
if(str[pos]=='=')
cnt+=(turn)?(-1):(1);
else if(str[pos]=='#')turn=1;
else flag=0;
if(pos==2&&cnt>0)flag=1;
pos++;
}while(pos<len-1);
if(cnt==0&&flag&&str[pos]=='~')ans=0;
}
else if(str[0]=='>'&&str[1]=='^'){
int pos=2;
int flag=1;
do{
if(str[pos]!='Q'||str[pos+1]!='='){
flag=0;
break;
}
pos+=2;
}while(pos<len-2);
if(flag&&str[pos]=='~'&&str[pos+1]=='~')ans=1;
}
if(ans==0)cout<<"A"<<endl;
else if(ans==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 <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>
#define M_PI 3.14159265358979323846
using namespace std;
//conversion
//------------------------------------------
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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
int to, cost, nm;
Edge(int to, int cost, int nm): to(to), cost(cost), nm(nm) {}
};
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 100000000;
ll GCD(ll a, ll b){
if(a < b) swap(a, b);
if(b == 0) return a;
return GCD(b, a%b);
}
bool cmp(const pii& a, const pii& b){
if(a.first == b.first){
return a.second < b.second;
}
return a.first < b.first;
}
int main() {
//cout << fixed << setprecision(2);
int n;
cin >> n;
for(int i=0; i<n; ++i){
string s; cin >> s;
int n = s.size();
if(n>2 && s[0] == '>' && s[1] =='\''){
if(s[n-1] != '~'){
cout << "NA" << endl;
}else{
int l = 2, r = n-2;
bool ok = true;
int stmt = 0;
int cnt1=0, cnt2=0;
for(int j=l; j<=r; ++j){
if(s[j] == '#') stmt++;
else if(s[j]=='='){
if(stmt == 0) cnt1++;
else if(stmt == 1) cnt2++;
else ok = false;
}else ok = false;
}
if(ok){
if(cnt1 >= 1 && (cnt1 == cnt2)){
cout << "A" << endl;
}else{
cout << "NA" << endl;
}
}else{
cout << "NA" << endl;
}
}
}else if(n > 2 && s[0] == '>' && s[1] == '^'){
if(s[n-2] == '~' && s[n-1] == '~'){
if(n%2 == 1){
cout << "NA" << endl;
}else {
bool ok = true;
int cnt = 0;
for (int j = 2; j <= n - 3; j+=2) {
if(s[j] == 'Q' && s[j+1] == '='){
cnt++;
}else{
ok = false;
}
}
if(cnt>=1 && ok){
cout << "B" << endl;
}else{
cout << "NA" << endl;
}
}
}else{
cout << "NA" << endl;
}
}else{
cout << "NA" << endl;
}
}
return 0;
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<string>
#include<iostream>
using namespace std;
bool isA(string s)
{
int len=s.length();
if(len<6) return false;
if(s.substr(0,2)!=">'") return false;
if(s.substr(len-1)!="~") return false;
s=s.substr(2,len-3);
len=s.length();
if(len%2==0) return false;
if(s[len/2]!='#') return false;
if(s.substr(0,len/2)!=string(len/2,'=')) return false;
if(s.substr(len/2+1)!=string(len/2,'=')) return false;
return true;
}
bool isB(string s)
{
int len=s.length();
if(len<6) return false;
if(s.substr(0,2)!=">^") return false;
if(s.substr(len-2)!="~~") return false;
s=s.substr(2,len-4);
len=s.length();
if(len%2==1) return false;
bool b=true;
for(int i=0;i<len;i+=2){
if(s[i+0]!='Q') b=false;
if(s[i+1]!='=') b=false;
}
return b;
}
int main()
{
int n; cin>>n;
string snake;
while(n--){
cin>>snake;
if (isA(snake)) cout<<'A'<<endl;
else if(isB(snake)) 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 <algorithm>
using namespace std;
bool isA(const string &s) {
if(s.size() < 6) return false;
if(s.substr(0,2) != ">'") return false;
if(*(s.rbegin()) != '~') return false;
string t = s.substr(2, (int)s.size()-3);
int m = t.find("#");
if(m == string::npos) return false;
if(t.substr(0,m) != string(m, '=')) return false;
if(t.substr(m+1) != string(m, '=')) return false;
return true;
}
bool isB(const string &s) {
if(s.size() < 6) return false;
if(s.substr(0,2) != ">^") return false;
if(s.substr((int)s.size()-2) != "~~") return false;
string t = s.substr(2, (int)s.size()-4);
if(t.size()&1) return false;
for(int i = 0; i < t.size(); i += 2) {
if(t[i] != 'Q' || t[i+1] != '=') return false;
}
return true;
}
int main() {
int n;
cin >> n;
while(n--) {
string s;
cin >> s;
if(isA(s)) cout << "A" << endl;
else if(isB(s)) cout << "B" << endl;
else cout << "NA" << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
string makeSnakeA( int a )
{
string s = ">\'";
for( int i = 0; i < a; i++ )
s += "=";
s += "#";
for( int i = 0; i < a; i++ )
s += "=";
s += "~";
return s;
}
string makeSnakeB( int a )
{
string s = ">^";
for( int i = 0; i < a; i++ )
s += "Q=";
s += "~~";
return s;
}
int main()
{
int n;
string str, s[200], t[200];
for( int i = 0; i < 200; i++ )
{
s[i] = makeSnakeA( i + 1 );
t[i] = makeSnakeB( i + 1 );
}
cin >> n;
for( int i = 0; i < n; i++ )
{
cin >> str;
int size = str.size();
if( size >= 6 && s[(size-6)/2] == str )
cout << "A" << endl;
else if( size >= 6 && t[(size-6)/2] == str )
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 <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define fr first
#define sc second
#define mp make_pair
#define foreach(c, it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;
int main(){
int N;
cin >> N;
while(N--) {
string s; cin >> s;
if(s[0] != '>') {
cout << "NA" << endl;
continue;
}
int select = 0;
if(s[1] == '\'') {
int cnt = 0;
if(!(s.size() % 2)) {
for(int i = 2; i < s.size() / 2; i++) {
if(s[i] != '=') {
select = -1;
break;
}
cnt++;
}
if(~select && !cnt) {
cout << "NA" << endl;
continue;
}
for(int i = s.size() / 2 + 1; i < s.size() - 1; i++) {
if(s[i] != '=') {
select = -1;
break;
}
cnt--;
}
} else select = -1;
if(!cnt && ~select && s[s.size() / 2] == '#' && s[s.size() - 1] == '~')
cout << "A" << endl;
else cout << "NA" << endl;
} else if(s[1] == '^') {
if(!(s.size() % 2)) {
for(int i = 2; i < s.size() - 2; i++) {
if((!(i % 2) && s[i] != 'Q') || (i % 2 && s[i] != '=')) {
select = -1;
break;
}
}
if(s.size() >= 6 && ~select && s[s.size() - 1] == s[s.size() - 2] && s[s.size() - 1] == '~') cout << "B" << endl;
else cout << "NA" << endl;
} else cout << "NA" << endl;
} else {
cout << "NA" << endl;
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
int main()
{
// cut here before submit
// freopen ("testcase.snack", "r", stdin );
const string species[] = { "A", "B", "NA" };
string str = "";
int n;
while (getline (cin, str ) ){
stringstream ssn(str);
ssn >> n;
// cout << "n: " << n << endl;
if (n == 0 ){
break;
} // end if
int i,j;
for (i = 0; i < n; ++i){
string res = species[2];
getline (cin, str );
if (str.empty() ){
break;
} // end if
int len = str.length();
if (str[0] == '>'){
if (str[1] == '\''){ // A species?
res = species[0];
}else if (str[1] == '^'){ // B species?
res = species[1];
}else{ // new species.
res = species[2];
} // end if
} // end if
if (res == species[0] || res == species[1]){
if (res == species[0]){ // A species?
int prev = 0;
int after = 0;
int mid = 0;
bool flag = false;
for (j = 2; j < len - 1; ++j){
if (str[j] == '='){
if (!flag){
++prev;
}else{
++after;
} // end if
continue;
}else if (str[j] == '#'){
flag = true;
++mid;
continue;
}else{
break;
} // end if
} // end for
if (j == len - 1){
if (str[j] == '~' && flag && mid == 1
&& prev != 0 && after != 0 && prev == after ){
res = species[0];
}else{
res = species[2];
} // end if
}else{
res = species[2];
} // end if
}else{ // if (res == species[1]) // B species?
bool flag = false;
for (j = 2; j < len - 2; j += 2){
if (str[j] == 'Q' && str[j+1] == '='){
if (!flag ){
flag = true;
} // end if
continue;
}else{
break;
} // end if
} // end for
if (j == len - 2 && flag && str[j] == '~' && str[j+1] == '~'){
res = species[1];
}else{
res = species[2];
} // end if
} // end if
} // end if
cout << res << endl;
} // end for
} // end loop
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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>
using namespace std;
string judgeSnakeType(string s){
if(s.find( ">'") == 0 && s.find("~") == s.size()-1)
{
s.erase(s.size()-1,1); s.erase(0,2);
int cnt = 0;
if( s.size() == 0 ) return "NA";
while( s.size() > 0 && s[0] == '=' ){
if(s[0] == '='){
s.erase(0,1);
cnt++;
}
}
if( s[0] != '#' || cnt == 0)return "NA";
s.erase(0,1);
while( s.size() > 0 && s[0] == '=' ){
if(s[0] == '='){
s.erase(0,1);
cnt--;
}
}
if(s.size() == 0 && cnt == 0) return "A";
else return "NA";
}
else if( s.find( ">^") == 0 && s.find("~~") == s.size()-2)
{
s.erase(s.size()-2,2); s.erase(0,2);
if( s.size() == 0 ) return "NA";
while( s.size() > 0 && s.size() % 2 == 0){
if(s[0] == 'Q' && s[1] == '='){
s.erase(0,2);
}
else {
return "NA";
}
}
return s == "" ? "B" : "NA";
}
else
{
return "NA";
}
return "NA";
}
void solve(string snake){
cout << judgeSnakeType( snake ) << endl;
}
int main(){
int d;
cin >> d;
string snake;
for(int i = 0 ; i < d; i++ )
{
cin >> snake;
solve(snake);
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))
typedef long long int ll;
using namespace std;
bool isa(string s){
if(s.substr(0,2) != ">'") return false;
int x = 2;
int c = 0;
while(s[x+c] == '='){
c++;
}
if(s[x+c] != '#') return false;
x = x + c + 1;
for(int i=0;i<c;i++){
if(s[x+i] != '=') return false;
}
x += c;
if(s[x] != '~') return false;
return true;
}
bool isb(string s){
if(s[0] != '>') return false;
if(s[1] != '^') return false;
int x = 2;
int c = 0;
while(s[x+c] == 'Q' && s[x+1+c] == '='){
c += 2;
}
x += c;
if(s[x] != '~') return false;
if(s[x+1] != '~') return false;
return true;
}
int main(){
string s = "";
int n;
cin >> n;
REP(i,n){
cin >> s;
if(s.size() < 6){
cout << "NA" << endl;
continue;
}
if(isa(s)) cout << "A"<<endl;
else if(isb(s)) cout << "B" << endl;
else cout << "NA" << endl;
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
using namespace std;
int main(){
char buf[210];
int bi,n,eqc,ti;
cin >> n;
for (int i=0;i<n;i++){
bi=0;
cin >> buf;
if (buf[bi++]!='>') {
cout << "NA" << endl;
continue;
}
if (buf[bi]=='\''){
bi++;
eqc=0;
if (buf[bi]!='='){
cout << "NA" << endl;
continue;
}
while (buf[bi+eqc]=='=')eqc++;
if (buf[bi+eqc]!='#'){
cout << "NA" << endl;
continue;
}
bi += eqc+1;
for (ti=0;ti<eqc;ti++)
if (buf[bi+ti]!='=')break;
if (ti <eqc){
cout << "NA" << endl;
continue;
}
bi+=ti;
if (buf[bi]=='~'&&buf[bi+1]=='\0')cout << "A" << endl;
else cout << "NA" << endl;
}else if(buf[bi]=='^'){
bi++;
//cout <<"dbg "<< buf[bi] << buf[bi+1] << endl;
if(buf[bi]!='Q'||buf[bi+1]!='='){
cout << "NA" << endl;
continue;
}
bi+=2;
while (buf[bi]=='Q'&&buf[bi+1]=='=')bi +=2;
//cout <<"dbg "<< buf[bi] << buf[bi+1] << endl;
if (buf[bi]=='~'&&buf[bi+1]=='~'){
if (buf[bi+2]=='\0')cout << "B" << endl;
else cout << "NA" << endl;
}else cout << "NA" << endl;
}else{
cout << "NA" << endl;
continue;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
using namespace std;
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second
#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;
int n;
string s;
bool F;
int main(){
cin >> n;
REP(i, n){
F = 0;
cin >> s;
if (s[0] == '>'&&s[s.size() - 1] == '~'){
if (s[1] == '\''){
int icnt = 0;
bool f = 1;
FOR(j, 2, s.size() - 1){
if (s[j] == '='){
if (f){
icnt++;
}
else{
icnt--;
}
}
else if (s[j] == '#'){
if (f)f = 0;
else {
F = 1;
break;
}
}
else{
F = 1;
break;
}
}
if (F == 0 && icnt == 0 && s.size() >= 6){
cout << "A" << endl;
}
else {
cout << "NA" << endl;
}
}
else if (s[1] == '^'&&s.size() % 2 == 0 && s.size() >= 6
&& s[s.size() - 1] == '~'&&s[s.size() - 2] == '~'){
FOR(j, 2, s.size() - 2){
if (j % 2 == 0){
if (s[j] != 'Q'){
F = 1;
break;
}
}
else{
if (s[j] != '='){
F = 1;
break;
}
}
}
if (F){
cout << "NA" << endl;
}
else{
cout << "B" << endl;
}
}
else {
cout << "NA" << endl;
}
}
else{
cout << "NA" << endl;
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
if (a.substr(0, 2) == ">'") {
int counter = 0;
bool hantei = false;
int i;
for (i = 2; i < a.size(); i++) {
if (a[i] == '=') {
counter++;
} else if (a[i] == '#' && counter > 0) {
hantei = true;
break;
} else {
hantei = false;
break;
}
}
if (hantei) {
int j;
for (j = i+1; j < a.size(); j++) {
if (a[j] == '=') {
counter--;
} else if (a[j] == '~') {
hantei = true;
break;
} else {
hantei = false;
break;
}
}
if (hantei) {
if (counter == 0 && j == a.size()-1) {
cout << 'A' << endl;
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
} else {
cout << "NA" << endl;
}
} else if (a.substr(0, 2) == ">^") {
int i;
bool hantei = false;
for (i = 2; i < a.size()-1; i += 2) {
if (a.substr(i, 2) == "Q=") {
hantei = true;
} else if (a.substr(i, 2) == "~~" && i == a.size()-2 && hantei) {
hantei = true;
break;
} else {
hantei = false;
break;
}
}
if (hantei) {
cout << 'B' << endl;
} else {
cout << "NA" << endl;
}
}else {
cout << "NA" << endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | import re
n = int(input())
for i in range(n):
s = input()
if re.match(r">'(=+)#\1~", s):
print('A')
elif re.match(r">\^(Q=)+~~", 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>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
bool b;
int n, i, j, t, c[2];
char s[201];
cin >> n;
for (i = 0; i < n; i++)
{
b = true;
cin >> s;
if (s[0] == '>')
{
if (s[1] == '\'')
{
for (j = 2, t = c[0] = c[1] = 0; j < strlen(s)-1; j++)
{
if (s[j] == '=')
c[t]++;
else if (t == 0 && s[j] == '#')
t++;
else
{
b = false;
break;
}
}
if (b && c[0] > 0 && c[0] == c[1] && s[strlen(s)-1] == '~')
cout << "A" << endl;
else
cout << "NA" << endl;
continue;
}
else if (s[1] == '^')
{
for (j = 2, c[0] = 0; j < strlen(s)-2; j+=2)
{
if (s[j] != 'Q' || s[j+1] != '=')
{
b = false;
break;
}
else
c[0]++;
}
if (b && c[0] > 0 && s[strlen(s)-2] == '~' && s[strlen(s)-1] == '~')
cout << "B" << endl;
else
cout << "NA" << endl;
continue;
}
else
b = false;
}
else
b = false;
if (!b)
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 | python2 | for r in range(input()):
snake=raw_input()
m=(len(snake)-4)/2
if m>0 and snake == ">'" + "="*m + "#" + "="*m + "~":
print "A"
elif m>0 and snake == ">^" + "Q="*m + "~~":
print "B"
else:
print "NA" |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int n,i,j,s;
string c1,c2,c3;
cin >> n;
for (i=0;i<n;i++) {
cin >> c1;
c2=c3=c1;
s=c1.size();
if (s<6 || s % 2==1) { cout << "NA" << endl; continue; }
for (j=0;j<s;j++) c2[j]=c3[j]='=';
c2[0]=c3[0]='>'; c2[s-1]=c3[s-1]=c3[s-2]='~';
c2[1]='\''; c2[s/2]='#'; c3[1]='^';
for (j=2;j<s-2;j+=2) c3[j]='Q';
if (c1==c2) cout << 'A'; else if (c1==c3) cout << 'B'; else cout << "NA";
cout << 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;
char buf[1024];
int M;
bool checkA(){
if( buf[0] != '>' ) return false;
if( buf[1] != '\'') return false;
int cnt1=0,cnt2=0;
bool f = false;
int i;
for(i=2;i<M;i++){
if(!f){
if( buf[i] == '=' ) cnt1++;
else if( buf[i] == '#' ) f = true;
else return false;
} else {
if( buf[i] == '=' ) cnt2++;
else break;
}
}
if( buf[i] != '~' ) return false;
i++;
if( i == M && cnt1 == cnt2 && cnt1>0 && f ) return true;
return false;
}
bool checkB(){
if( buf[0] != '>' ) return false;
if( buf[1] != '^' ) return false;
int i;
bool f = false;
for(i=2;i<M-2;i+=2){
if( buf[i] != 'Q' ) return false;
if( buf[i+1] != '=' ) return false;
f = true;
}
if( f && buf[i] == '~' && buf[i+1] == '~' && i + 2 == M ) return true;
return false;
}
int main(){
int n; cin >> n;
for(int i=0;i<n;i++){
cin >> buf; M = strlen(buf);
if( checkA() ) cout << "A" << endl;
else if( checkB() ) 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<string>
using namespace std;
string S;
int n;
string solve(string T) {
int chain = 0, ok = 0;
if (T.size() >= 3) {
if (T[T.size() - 1] == '~') {
if (T.substr(0, 2) == ">'" && T.size() >= 6) {
for (int i = 2; i < T.size() - 1; i++) {
if (T[i] == '#') {
ok++;
}
else if (T[i] == '=') {
if (ok == 0) { chain++; }
else { chain--; }
}
else {
goto NA;
}
}
if (ok == 1 && chain == 0) { return "A"; }
}
if (T.substr(0, 2) == ">^" && T[T.size() - 2] == '~' && T.size() >= 6) {
for (int i = 2; i < T.size() - 2; i += 2) {
if (T.substr(i, 2) != "Q=") {
goto E;
}
}
return "B";
E:;
}
}
}
NA:;
return "NA";
}
int main() {
cin >> n;
for (int h = 0; h < n; h++) {
cin >> S;
cout << solve(S) << endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | for i in [0]*input():
s=raw_input()
n=(len(s)-4)/2
if n>0 and s==">'"+"="*n+"#"+"="*n+"~": t="A"
elif n>0 and s==">^"+"Q="*n+"~~": t="B"
else: t="NA"
print t |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
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 isOutOfStr(int ind, string str){
return ind >= str.length();
}
int main(void){
int n;
cin >> n;
while(n--){
string str; cin >> str;
if(!isOutOfStr(1, str) &&str[0] == '>' && str[1] == '\''){
int sharp_cnt = 0;
int ind;
ind = 2;
if(isOutOfStr(ind, str) || str[ind] != '='){
cout << "NA" << endl;
continue;
}
for(;;ind++){
if(isOutOfStr(ind, str) || str[ind] != '='){
break;
}
sharp_cnt++;
}
if(isOutOfStr(ind, str) || str[ind] != '#'){
cout << "NA" << endl;
continue;
}
ind++;
bool flg = true;
for(int i=0; i < sharp_cnt; i++, ind++){
if(isOutOfStr(ind, str) || str[ind] != '='){
cout << "NA" << endl;
flg = false;
break;
}
}
if(!flg) continue;
if(!isOutOfStr(ind, str) && str[ind] == '~' && ind == str.length() - 1)
cout << "A" << endl;
else{
cout << "NA" << endl;
}
}else if(str[0] == '>' && str[1] == '^'){
int ind;
ind=2;
if(isOutOfStr(ind, str) || !(str[ind] == 'Q' && str[ind+1] == '=')){
cout << "NA" << endl;
}else{
int flg = true;
for(;;ind+=2){
if(isOutOfStr(ind, str) || !(str[ind] == 'Q' && str[ind+1] == '=')){
break;
}
}
if(!isOutOfStr(ind, str) && !isOutOfStr(ind+1, str) && str[ind] == '~' && str[ind+1] == '~' && ind+1 == str.length() - 1){
cout << "B" << endl;
}else{
cout << "NA" << endl;
}
}
}else{
cout << "NA" << endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | class Ex(Exception):
pass
n=int(input())
for i in range(n):
try:
snk=input()
l=len(snk)
head=snk[:2]
body=snk[2:l-1]
tail=snk[l-1]
if tail!='~' or snk[0]!='>':
print("NA")
continue
spl_a=body.split('#')
if len(spl_a)==2 and spl_a[0]==spl_a[1] and len(spl_a[0])!=0:
for char in spl_a[0]:
if char!='=':
print("NA")
raise Ex()
if head[1]=='\'':
print('A')
raise Ex()
else:
print("NA")
raise Ex()
bars=body.split('=')
if len(bars)==1:
print("NA")
continue
for j in range(len(bars)-1):
if bars[j]!='Q':
print("NA")
raise Ex()
if head[1]=='^'and bars[len(bars)-1]=='~':print('B')
else:print("NA")
except Ex:pass |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | 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;
if(s[0]+s[1]==101){
if((m=s.find(35))!=string::npos)
for(i=1;s[m-i]==s[m+i];)
if(m-++i==1 && m+i==s.size()-1 && s[m+i]=='~')f=1;
}else if(s[0]+s[1]==156){
for(i=2;s[i]=='Q'&&s[i+1]=='=';)
if(++++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 | java | import java.util.Scanner;
public class Main{
public static void main(String[] args){
new Main().run();
}
public void run(){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
int n = scan.nextInt();
for(int i = 0;i < n;i++){
String snake = scan.next();
if(snake.substring(0,2).equals(">'") && snake.indexOf("#") >= 2 && snake.charAt(snake.length()-1) == '~'
&& snake.indexOf('=') >= 2){
int eqC = 0;
int sh = 0;
boolean fl = true;
for(int j = 2;j < snake.length()-1;j++){
if(snake.charAt(j) == '=' && sh == 0){
eqC++;
}else if(snake.charAt(j) == '='){
eqC--;
}else if(snake.charAt(j) == '#' && sh == 0){
sh = 1;
}else{
fl = false;
break;
}
}
if(fl && eqC == 0){
System.out.println("A");
}else{
System.out.println("NA");
}
}else if(snake.substring(0,2).equals(">^") && snake.indexOf("Q=") > 1){
snake = snake.replaceAll("Q=","");
if(snake.equals(">^~~")){
System.out.println("B");
}else{
System.out.println("NA");
}
}else{
System.out.println("NA");
}
}
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
int n;
cin >> n;
for(int i=0;i<n;i++)
{
string s;
cin >> s;
int sz=s.size();
if(s[0]!='>'||sz<6)
{
cout << "NA" << endl;
continue;
}
if(s[1]=='\'')
{
int t=sz-3;
if(t%2==0)
{
cout << "NA" << endl;
continue;
}
for(int j=2;j<2+t;j++)
{
if(j==2+t/2&&s[j]!='#')
{
cout << "NA" << endl;
goto end;
}
else if(j!=2+t/2&&s[j]!='=')
{
cout << "NA" << endl;
goto end;
}
}
if(s[sz-1]!='~')
{
cout << "NA" << endl;
continue;
}
cout << "A" << endl;
end:;
}
else if(s[1]=='^')
{
int t=sz-4;
if(t%2==1)
{
cout << "NA" << endl;
continue;
}
for(int j=0;j<t;j++)
{
if(j%2==0&&s[j+2]!='Q')
{
cout << "NA" << endl;
goto end2;
}
else if(j%2==1&&s[j+2]!='=')
{
cout << "NA" << endl;
goto end2;
}
}
if(s[sz-1]!='~'||s[sz-2]!='~')
{
cout << "NA" << endl;
continue;
}
cout << "B" << endl;
end2:;
}
else
{
cout << "NA" << endl;
continue;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<functional>
#include<map>
using namespace std;
int main() {
int a;
cin >> a;
for (int b = 0; b < a; b++) {
string c; cin >> c;
if ((c.length() & 1)==0&&c.length()>=6) {
if (c[0] == '>'&&c[1] == '^'&&c[c.length() - 1] == '~'&&c[c.length() - 2] == '~') {
bool e = true;
for (int d = 2; d < c.length() - 2; d += 2) {
if (c[d] != 'Q' || c[d + 1] != '=')e = false;
}
if (e) {
puts("B");
continue;
}
}
if (c[0] == '>'&&c[1] == '\''&&c[c.length() - 1] == '~') {
bool k = true;
for (int j = 2; j < c.length() - 1; j++) {
if (j == c.length() / 2) {
if (c[j] != '#')k = false;
}
else {
if (c[j] != '=')k = false;
}
}
if (k) { puts("A"); continue; }
}
}
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 <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
int main() {
int N;
cin >> N;
REP(n, N) {
string str;
int type = 0, pos = 0;
cin >> str;
if (str[pos] == '>') {
pos++;
if (str[pos] == '\'') {
pos++;
int cnt = 0;
while (pos < str.size() && str[pos] == '=') { cnt++; pos++; }
if (cnt != 0 && str[pos] == '#') {
pos++;
while (pos < str.size() && str[pos] == '=') { cnt--; pos++; }
if (cnt == 0 && str[pos] == '~') type = 1;
}
}
else if (str[pos] == '^') {
bool f = false;
pos++;
while (pos + 1 < str.size()) {
if (str[pos] == 'Q' && str[pos + 1] == '=') { pos += 2; f = true; }
else break;
}
if (f && pos + 2 == str.size() && str[pos] == '~' && str[pos + 1] == '~')
type = 2;
}
}
switch (type) {
case 0: cout << "NA" << endl; break;
case 1: cout << "A" << endl; break;
case 2: cout << "B" << 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 <bits/stdc++.h>
#include <regex>
using namespace std;
string Sample;
//const regex REA("^>'(=+)#\1~$"), REB("^>\\^(Q=)+~~$");
const regex REA("^>'(=+)#(=+)~$"), REB("^>\\^(Q=)+~~$");
int main() {
int n;
smatch smStr;
cin >> n;
while (n--) {
cin >> Sample;
//cout << Sample << endl;
if (regex_match(Sample, smStr, REA)) {
if (smStr[1].length() == smStr[2].length()) {
cout << "A" << endl;
}
else {
cout << "NA" << endl;
}
}
else if (regex_match(Sample, REB)) {
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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int main(void){
int n;
cin>>n;
while(n--){
string snake;
cin>>snake;
if(snake[0]=='>'&&snake[1]=='\''&&snake[snake.size()-1]=='~'){
int count=0;
int end;
for(int i=2;i<snake.size()&&snake[i]=='='; i++){
count++;
end = i;
}
end++;
if(count&&snake[end]=='#'&&end+count+2==snake.size()){
bool yes = true;
for(int i=end+1;i<snake.size()-1;i++){
if(snake[i]!='=')yes = false;
}
if(yes){
cout<<"A"<<endl;
}else{
cout<<"NA"<<endl;
}
}else{
cout<<"NA"<<endl;
}
}else if(snake[0]=='>'&&snake[1]=='^'&&snake[snake.size()-1]=='~'&&snake[snake.size()-2]=='~'
&&snake[snake.size()-3]=='='){
bool yes = true;
for(int i=2;i<snake.size()-2;i++){
if(i%2==0&&snake[i]!='Q') yes = false;
if(i%2==1&&snake[i]!='=') yes = false;
}
if(yes){
cout<<"B"<<endl;
}else{
cout<<"NA"<<endl;
}
}else{
cout<<"NA"<<endl;
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int main()
{
int n;
cin >> n;
while(--n >= 0){
string s;
cin >> s;
int n = s.size();
if(n < 6 || n % 2 == 1){
cout << "NA" << endl;
continue;
}
string sa(n, '=');
sa[0] = '>';
sa[1] = '\'';
sa[n/2] = '#';
sa[n-1] = '~';
if(s == sa){
cout << 'A' << endl;
continue;
}
string sb(n, '=');
sb[0] = '>';
sb[1] = '^';
for(int i=2; i<n-2; i+=2)
sb[i] = 'Q';
sb[n-2] = '~';
sb[n-1] = '~';
if(s == sb)
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 | python3 | for _ in [0]*int(input()):
s=input()
a='NA'
if s[:2]==">'" and s[-1]=='~' and '#' in s:
s=s[2:-1].split('#')
a=[a,'A'][set(s[0])==set(s[1])=={'='} and len(set(s))==1]
elif s[:2]=='>^' and s[-2:]=='~~':
s=s[2:-2]
a=['NA','B'][len(s)==2*s.count('Q=') and len(s)>0]
print(a) |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
int main()
{
std::string sn; getline(std::cin, sn);
int n = std::stoi(sn);
for (int i=0; i<n; i++) {
std::string snake;
getline(std::cin, snake);
int state = 0;
int equal_count = 0;
for (int k=0; k<snake.length(); k++) {
char c = snake[k];
switch (state) {
case 0:
if (c == '>') state = 1;
else state = 9;
break;
case 1:
if (c == '\'') state = 10;
else if (c == '^') state = 11;
else state = 9;
break;
case 2:
if (c == '=') equal_count++;
else if (c == '#') state = 3;
else state = 9;
break;
case 3:
if (c == '=') {
equal_count--;
if (equal_count < 0) state = 9;
}
else if (equal_count == 0 && c == '~') state = 4;
else state = 9;
break;
case 4:
state = 9;
break;
case 5:
if (c == 'Q') state = 6;
else if (c == '~') state = 7;
else state = 9;
break;
case 6:
if (c == '=') state = 5;
else state = 9;
break;
case 7:
if (c == '~') state = 8;
else state = 9;
break;
case 8:
state = 9;
break;
case 10:
if (c == '=') {
equal_count++; state = 2;
}
else state = 9;
break;
case 11:
if (c == 'Q') state = 12;
else state = 9;
break;
case 12:
if (c == '=') state = 5;
else state = 9;
break;
}
}
if (state == 4) std::cout << "A" << std::endl;
else if (state == 8) std::cout << "B" << std::endl;
else std::cout << "NA" << std::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 <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n;
string s;
int main(){
cin>>n;
while(cin>>s){
if(s.size()<6||s[0]!='>'){cout<<"NA"<<endl;continue;}
int cur=2,l=0,l2=0,f=0,f2=0;
if(s[1]=='\''){
while(cur<s.size()){
if(f2){f2=0;break;}
else if(s[cur]=='='){
if(!f)l++;
else l2++;
}
else if(s[cur]=='#'){
if(!l||f)break;
else f=1;
}
else if(s[cur]=='~'){
if(l&&l==l2){f2=1;}
else break;
}
else break;
cur++;
}
}
else if(s[1]=='^'){
while(cur<s.size()){
if(f2){f2=0;break;}
if(s[cur]=='Q'){
if(!f)f=1;
else break;
}
else if(s[cur]=='='){
if(f==1)f=0;
else break;
}
else if(s[cur]=='~'){
if(!f)f=2;
else if(f==2)f2=2;
else break;
}
else break;
cur++;
}
}
if(f2==1)cout<<"A"<<endl;
else if(f2==2)cout<<"B"<<endl;
else cout<<"NA"<<endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N;
cin>>N;
for(int i=0;i<N;i++){
string sn;
cin>>sn;
int type=0;
if(sn[0]=='>'&&sn[1]==39)type=1;
if(sn[0]=='>'&&sn[1]=='^')type=2;
int flg=1;
if(type==1){
int cou=0;
int aftercou=0;
int p;
for(int j=2;j<sn.size();j++){
if(sn[j]=='=')cou++;
else if(sn[j]=='#'){
p=j;
break;
}
else{
flg=0;
goto syutu;
}
}
for(int k=p+1;k<sn.size();k++){
if(sn[k]=='=')aftercou++;
else if(sn[k]=='~'&&k==sn.size()-1){
if(cou!=aftercou)flg=0;
goto syutu;
}
else{
flg=0;
goto syutu;
}
}
if(sn[sn.size()-1]!='~')flg=0;
syutu:
if(flg&&cou)puts("A");
else puts("NA");
}
else if(type==2){
for(int j=2;j<sn.size()-1;j+=2){
if(sn[j]=='~'&&sn[j+1]=='~'&&j!=2)break;
if(!(sn[j]=='Q'&&sn[j+1]=='='))flg=0;
}
if(sn[sn.size()-2]!='~'||sn[sn.size()-1]!='~')flg=0;
if(flg)puts("B");
else puts("NA");
}
else puts("NA");
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | import re
A = ">'=+#=+~$"
B = ">\^(Q=)+~~$"
n = int(input())
for i in range(n):
s = input()
if re.match(A,s):
a, b = re.match(A,s).group().split("#")
print("A" if a.count("=") == b.count("=") else "NA")
elif re.match(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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
int n,length,second_length;
char snake[201];
scanf("%d",&n);
for(int i=0; i < n; i++){
scanf("%s",snake);
if(snake[1] == '\0'){
printf("NA\n");
continue;
}
if(snake[0] == '>' && snake[1] == '\''){
if(snake[2] != '='){
printf("NA\n");
}else{
for(length = 0;snake[length+2] != '\0' && snake[length+2] == '='; length++);
if(snake[length+2] != '#'){
printf("NA\n");
}else{
for(second_length = 0; snake[length+3+second_length] != '\0' &&
snake[length+3+second_length] == '=';second_length++);
if(length != second_length || snake[length+3+second_length] != '~'){
printf("NA\n");
}else{
if(snake[length+4+second_length] == '\0'){
printf("A\n");
}else{
printf("NA\n");
}
}
}
}
}else if(snake[0] == '>' && snake[1] == '^'){
if(snake[2] != 'Q' || snake[3] != '='){
printf("NA\n");
}else{
bool breakFLG = false;
for(length=0;snake[length+2] != '\0' && (snake[length+2] == 'Q' || snake[length+2] == '=');length++){
if(length > 1){
if(snake[length+2] == 'Q' && snake[length+2-1] != '='){
breakFLG = true;
break;
}
if(snake[length+2] == '=' && snake[length+2-1] != 'Q'){
breakFLG = true;
break;
}
}
}
if(breakFLG)printf("NA\n");
else{
if(snake[length+2-1] == 'Q'|| snake[length+2] != '~'){
printf("NA\n");
}else{
if(snake[length+3] != '~'){
printf("NA\n");
}else{
if(snake[length+4] == '\0'){
printf("B\n");
}else{
printf("NA\n");
}
}
}
}
}
}else{
printf("NA\n");
}
}
return 0;
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
string s;
cin>>s;
if(s[0]=='>'){
if(s[1]=='\''){
int sum=0;
if(s.size()<6)goto L;
r(i,s.size())if(s[i]=='=')sum++;
if(s.size()%2==0&&s[s.size()/2]=='#'&&sum==s.size()-4&&s[s.size()-1]=='~')
cout<<'A'<<endl;
else goto L;
}
else if(s[1]=='^'){
int c=2;
if(s.size()%2||s.size()<6)goto L;
while(c<s.size()-3){
if(s[c]!='Q')goto L;
c++;
if(s[c]!='=')goto L;
c++;
}
if(s[c]=='~'&&s[c+1]=='~')cout<<'B'<<endl;
else goto L;
}
else goto L;
}
else goto L;
if(0)L:cout<<"NA"<<endl;
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | class Main{
public static void main(String[]z){
Scanner x=new Scanner(System.in);
String s=x.nextLine();
while(x.hasNext()){
s=x.nextLine();
if(s.matches(">'(=+)#\\1~"))System.out.println("A");
else if(s.matches(">\\^(Q=)+~~"))System.out.println("B");
else System.out.println("NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static inline int in(){ int x; scanf("%d", &x); return x; }
int main()
{
int n = in();
int am[12][256] = {};
am[1]['>'] = 2;
am[2]['\''] = 3;
am[3]['='] = 4;
am[4]['='] = 4;
am[4]['#'] = 5;
am[5]['='] = 5;
am[5]['~'] = 6;
am[2]['^'] = 7;
am[7]['Q'] = 8;
am[8]['='] = 9;
am[9]['Q'] = 8;
am[9]['~'] = 10;
am[10]['~'] = 11;
const int typeA = 6;
const int typeB = 11;
for (int i = 0; i < n; i++){
string snake;
cin >> snake;
int aid = 1;
int c4, c5;
c4 = c5 = 0;
for (int j = 0; j < snake.size(); j++){
aid = am[aid][snake[j]];
if (aid == 4) c4++;
if (aid == 5) c5++;
}
if (aid == typeA && c4 == c5 - 1){
puts("A");
}
else if (aid == typeB){
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 | java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
String snake = sc.next();
if (snake.indexOf('#') > 0 && snake.length() > 4 && snake.charAt(0) == '>' && snake.charAt(1) == '\'' && snake.charAt(snake.length() - 1) == '~') {
int count = 0;
for (int i = 2, j = snake.length() / 2 + 1; i < snake.length() / 2; i++, j++) {
if (snake.charAt(i) == '=' && snake.charAt(j) == '=') {
count += 2;
}
}
if (count == snake.length() - 4) {
System.out.println("A");
} else {
System.out.println("NA");
}
} else if (snake.charAt(0) == '>' && snake.length() > 4 && snake.charAt(1) == '^' && snake.charAt(snake.length() - 2) == '~' && snake.charAt(snake.length() - 1) == '~' && snake.replaceAll("Q=", "").equals(">^~~")) {
System.out.println("B");
} else {
System.out.println("NA");
}
}
}
}
|
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(){
int i,j,n,a;
string str,ans;
cin >> n;
for(i=0;i<n;i++){
cin >> str;
ans = "NA";
if(str[0] == '>'){
if(str[1] == '\''){
a = 2;
int c=0,c2=0;
if(str[a] == '='){
while(str[a] == '='){
a++;
c++;
}
if(str[a] == '#'){
a++;
if(str[a] == '='){
while(str[a] == '='){
c2++;
a++;
}
if(str[a] == '~' && a + 1 == str.size() && c == c2) ans = "A";
}
}
}
}
else if(str[1] == '^'){
a = 2;
if(str[a] == 'Q' && str[a+1] == '='){
while(str[a] == 'Q' && str[a+1] == '=') a += 2;
if(str[a] == '~' && str[a+1] == '~' && a + 2 == str.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 | cpp | #include <iostream>
#include <string>
using namespace std;
int n;
int main()
{
cin >> n;
for (int i = 0; i < n; i++) {
string s, t, w;
cin >> s;
t = "NA";
int m = s.size();
if (m > 4 && m % 2 == 0) {
string u(m - 4, '=');
u.insert(u.begin() + m / 2 - 2, '#');
if (s == ">'" + u + '~')
t = "A";
for (int j = 0; j < (m / 2 - 2); j++)
w += "Q=";
if (s == ">^" + w + "~~")
t = "B";
}
cout << t << 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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
using namespace std;
#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
bool isA(const char* str)
{
int n = strlen(str);
if(n<6) return false;
if(str[0]!='>' || str[1]!='\'') return false;
int cnt, i;
for(cnt=0, i=2; i<n && str[i]=='='; ++cnt, ++i);
if(cnt==0 || i>=n || str[i] != '#') return false;
++i;
int s;
for(s=0; i<n && str[i]=='='; ++s, ++i);
if(cnt!=s || i+1!=n) return false;
return str[i] == '~';
}
bool isB(const char* str)
{
int n = strlen(str);
if(n<6) return false;
if(str[0]!='>' || str[1]!='^') return false;
int i;
for(i=2; i+1<n && str[i]=='Q' && str[i+1]=='='; i+=2);
if(i==2 || i+2!=n) return false;
return str[i]=='~' && str[i+1] == '~';
}
int main()
{
int n;
scanf("%d", &n);
rep(i, n){
char str[256];
scanf("%s", 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 | 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 AOJ0139(){
int N=sc.nextInt();
sc.nextLine();
for(int i=1; i<=N; i++){
String s=sc.nextLine();
Matcher m=Pattern.compile("^>'=+#=+~$").matcher(s);
Matcher m2=Pattern.compile("^>\\^[Q=]+~~$").matcher(s);
if(m.matches()){
m=Pattern.compile("=+").matcher(s);
if(m.find()){
String a1=m.group();
if(m.find()){
if(a1.equals(m.group())){
out.println("A");
continue;
}
}
}
}
if(m2.matches()){
if(s.replaceAll("Q=", "").length()==4){
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);
}
}
}
void AOJ0133(){
char[][] a=new char[9][9];
for(int i=1; i<=8; i++){
char[] s=sc.next().toCharArray();
for(int j=1; j<=8; j++) a[j][i]=s[j-1];
}
out.println("90");
for(int j=1; j<=8; j++){
for(int i=1; i<=8; i++) out.print(a[j][9-i]);
out.println();
}
out.println("180");
for(int j=1; j<=8; j++){
for(int i=1; i<=8; i++) out.print(a[9-i][9-j]);
out.println();
}
out.println("270");
for(int j=1; j<=8; j++){
for(int i=1; i<=8; i++) out.print(a[9-j][i]);
out.println();
}
}
// 途中
void AOJ0230(){
while(sc.hasNext()){
int n=sc.nextInt();
int[] a=new int[n+1], b=new int[n+1];
for(int i=1; i<=n; i++) a[i]=sc.nextInt();
for(int i=1; i<=n; i++) b[i]=sc.nextInt();
out.println(min(solve230(n,a,b),solve230(n,b,a)));
}
}
int solve230(int n, int[] a, int[] b){
int ans=0;
ArrayList<Integer> dp=new ArrayList<Integer>();
dp.add(0);
for(int i=1; dp.get(dp.size()-1)<n; i++){
int temp=min(dp.get(i-1),min(dp.get(i-2),dp.get(i-3)));
}
return ans;
}
// TLE -> OK
void AOJ0070(){
while(sc.hasNext()){
int n=sc.nextInt(), s=sc.nextInt(), ans=0;
for(int i=0; i<=9; i++){
boolean[] b=new boolean[10];
b[i]=true;
ans+=solve70(1,0,i,n,s,b);
}
out.println(ans);
}
}
int solve70(int nn, int ss, int x, int n, int s, boolean[] b){ // nn番目 合計ss 次x
int ans=0;
if(ss>s) return 0;
if(nn>n) return 0;
if(nn==n) ans+=ss+nn*x==s?1:0;
else if(nn<n){
for(int i=0; i<=9; i++){
if(!b[i]){
// コピーしない
//boolean[] bb=b.clone();
//bb[i]=true;
b[i]=true;
ans+=solve70(nn+1, ss+nn*x, i, n,s,b);
b[i]=false;
}
}
}
return ans;
}
int p31, q31, a31, n31;
void AOJ1131(){
while(sc.hasNext()){
p31=sc.nextInt(); q31=sc.nextInt(); a31=sc.nextInt(); n31=sc.nextInt();
int ans=0;
if(p31==0) break;
int G=gcd(max(p31,q31),min(p31,q31));
p31/=G; q31/=G;
for(int i=1; i<=a31; i++) ans+=solve1131(1, i, 1, i);
out.println(ans);
}
}
int solve1131(int nn, int aa, int pp, int Q){
if(aa>a31) return 0;
// 2秒近く縮まる
double D=(double)aa/q31;
if((double)pp/p31>D) return 0;
int ans=0;
if(nn<=n31){
if((double)pp/p31==(double)aa/q31) ans++;
else if(nn<n31 && aa<=a31){
for(int i=Q; i*aa<=a31; i++) ans+=solve1131(nn+1, aa*i, pp*i+1*aa, i);
}
}
return ans;
}
void AOJ0089(){ // The Shortest Path on A Rhombic Path
int[][] dp=new int[200][200];
dp[1][1]=sc.nextInt();
int idx=2, lastLen=1;
while(sc.hasNext()){
String[] s=sc.next().split(",");
for(int i=1; i<=s.length; i++){
if(s.length>lastLen) dp[i][idx]=Integer.parseInt(s[i-1])+max(dp[i][idx-1], dp[i-1][idx-1]);
else dp[i][idx]=Integer.parseInt(s[i-1])+max(dp[i][idx-1], dp[i+1][idx-1]);
}
/*
String s=sc.nextLine();
Scanner sc2=new Scanner(s).useDelimiter(","); <-【こいつがRE】
int len=(int)round(s.length()/2.0);
for(int i=1; i<=len; i++){
if(len>lastLen) dp[i][idx]=sc2.nextInt()+max(dp[i][idx-1], dp[i-1][idx-1]);
else dp[i][idx]=sc2.nextInt()+max(dp[i][idx-1], dp[i+1][idx-1]);
}
lastLen=len;
*/
lastLen=s.length;
idx++;
}
//debug
/*
for(int i=0; i<=idx; i++){
for(int j=0; j<=(int)round(idx/2.0); j++) out.printf("%4d",dp[j][i]);
out.println();
}
*/
out.println(dp[1][idx-1]);
}
void AOJ0191(){
while(sc.hasNext()){
int n=sc.nextInt(), m=sc.nextInt(), last=0; // m回
if(n==0) break;
double[][] h=new double[n+1][n+1];
double[][] dp=new double[n+1][m+1];
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++) h[j][i]=sc.nextDouble();
}
for(int i=1; i<=n; i++) dp[i][1]=1;
for(int j=2; j<=m; j++){
for(int i=1; i<=n; i++){
for(int k=1; k<=n; k++){
dp[i][j]=max(dp[i][j], dp[k][j-1]*h[i][k]);
//debug
//out.print(dp[k][j-1]*h[i][k]+" ");
}
}
//out.println();
}
//debug
/*
for(int j=1; j<=m; j++){
for(int i=1; i<=n; i++) out.print(dp[i][j]+" ");
out.println();
}
*/
double ans=0;
for(int i=1; i<=n; i++) ans=max(ans,dp[i][m]);
out.printf("%.2f\n",ans);
}
}
void AOJ0203(){ // A New Plan of Aizu Ski Resort
while(sc.hasNext()){
int x=sc.nextInt(), y=sc.nextInt();
if(x==0) break;
int[][] dp=new int[x+3][y+3],b=new int[x+2][y+2];
for(int j=1; j<=y; j++){
for(int i=1; i<=x; i++) b[i][j]=sc.nextInt();
}
for(int i=1; i<=x; i++) dp[i][1]= b[i][1]==1?0:1;
for(int j=1; j<=y; j++){
for(int i=1; i<=x; i++){
// jump2連続を見落としてた
// if(b[i][j]==2) dp[i][j]= dp[i][j-1];
if(b[i][j]==2) dp[i][j]= b[i][j-1]!=2?dp[i][j-1]:0;
else if(b[i][j]==0){
for(int k=i-1; k<=i+1; k++) dp[i][j]+= b[k][j-1]==0?dp[k][j-1]:0;
}
if(j>2 && b[i][j]!=1) dp[i][j]+= b[i][j-2]==2?dp[i][j-2]:0;
}
}
// debug
/*
for(int j=1; j<=y; j++){
for(int i=1; i<=x; i++) out.print(dp[i][j]+" ");
out.println();
}
*/
int ans=0;
for(int i=1; i<=x; i++) ans+= dp[i][y]+(b[i][y-1]==2?dp[i][y-1]:0);
out.println(ans);
}
}
void AOJ0042(){ // A Thief
int num=1;
while(sc.hasNext()){
int w=sc.nextInt();
if(w==0) break;
int n=sc.nextInt();
int[][] dp=new int[n+1][w+1];
int[] ww=new int[n+1], pp=new int[n+1];
for(int i=1; i<=n; i++){
Scanner sc2=new Scanner(sc.next()).useDelimiter(",");
pp[i]=sc2.nextInt();
ww[i]=sc2.nextInt();
}
int ans=0, wei=Integer.MAX_VALUE;
for(int i=1; i<=n; i++){
for(int j=1; j<=w; j++){
dp[i][j]=max(dp[i-1][j], j>=ww[i]?dp[i-1][j-ww[i]]+pp[i]:dp[i-1][j]);
if(dp[i][j]>ans){
wei=j;
ans=dp[i][j];
}else if(dp[i][j]==ans){
wei=min(wei,j);
}
}
}
//debug
/*
for(int i=0; i<=w; i++){
for(int j=0; j<=n; j++) out.printf("%4d",dp[j][i]);
out.println();
}
*/
out.println("Case "+(num++)+":");
out.println(ans);
out.println(wei);
}
}
void AOJ0003(){
int n=sc.nextInt();
while(n-->0){
int[] a=new int[3];
for(int i=0; i<3; i++) a[i]=sc.nextInt();
Arrays.sort(a);
if(a[2]*a[2]==(a[1]*a[1])+(a[0]*a[0])) out.println("YES");
else out.println("NO");
}
}
void AOJ0002(){
while(sc.hasNext()) out.println(new String(""+(sc.nextInt()+sc.nextInt())).length());
}
void AOJ0516(){
while(sc.hasNext()){
int n=sc.nextInt(), k=sc.nextInt(), ans=0;
if(n==0) break;
int[] sum=new int[n+1];
for(int i=1; i<=n; i++) sum[i]=sum[i-1]+sc.nextInt();
for(int i=k; i<=n; i++) ans=max(ans, sum[i]-sum[i-k]);
out.println(ans);
}
}
c547[][] r;
final int MOD547=100000;
void AOJ0547(){ // Commute routes
while(sc.hasNext()){
int w=sc.nextInt(), h=sc.nextInt();
if(w<2) break;
r=new c547[w+1][h+1];
r[2][1]=new c547(0,0,0,1); r[1][2]=new c547(0,1,0,0);
for(int x=1; x<=w; x++){
for(int y=1; y<=h; y++) r[x][y] = r[x][y]==null?solve547(x,y): r[x][y];
}
//r[w][h].list();
out.println(r[w][h].sum());
}
}
c547 solve547(int x, int y){
int s1=y-1>0? r[x][y-1].w2:0;
int s2=y-1>0? (r[x][y-1].s1+r[x][y-1].s2)%MOD547:0;
int w1=x-1>0? r[x-1][y].s2:0;
int w2=x-1>0? (r[x-1][y].w1+r[x-1][y].w2)%MOD547:0;
return new c547(s1, s2, w1, w2);
}
class c547{
int s1, s2, w1, w2;
c547(int s1, int s2, int w1, int w2){
this.s1=s1; this.s2=s2; this.w1=w1; this.w2=w2;
}
int sum(){
return (this.s1 + this.s2 + this.w1 + this.w2)%MOD547;
}
void list(){
out.println("("+this.s1+" "+this.s2+" "+this.w1+" "+this.w2+")");
}
}
int[][] a1209;
void AOJ1209(){
while(sc.hasNext()){
int n=sc.nextInt();
if(n<=0) break;
a1209=new int[18][n+1];
for(int i=0; i<=n; i++) a1209[1][i]=1;
for(int x=2; x<=17; x++){
for(int y=1; y<=n; y++) a1209[x][y]=solve1209(x,y);
}
int ans=0;
for(int i=1; i<=17; i++) ans+=a1209[i][n];
out.println(ans);
// debug
/*
for(int i=0; i<=n; i++){
for(int j=0; j<=17; j++) out.print(a1209[j][i]+" ");
out.println();
}
*/
}
}
int solve1209(int x, int y){
int ans=0;
for(int i=x;i>0; i--) ans+= y-(x*x)>=0?a1209[i][y-(x*x)]:0;
return ans;
}
int[][] r515;
boolean[][] b515;
void AOJ0515(){ // School Road
while(sc.hasNext()){
int xn=sc.nextInt(), yn=sc.nextInt();
if(xn<=0) break;
int n=sc.nextInt();
b515 = new boolean[xn+1][yn+1];
for(int i=0; i<n; i++) b515[sc.nextInt()][sc.nextInt()]=true;
r515=new int[xn+1][yn+1];
r515[1][1]=1;
for(int x=1; x<=xn; x++){
for(int y=1; y<=yn; y++){
if(x==1&&y==1) continue;
r515[x][y]=solve515(x,y);
}
}
out.println(r515[xn][yn]);
}
}
int solve515(int x, int y){
int ans=0;
if(!b515[x][y]){
ans+= y-1>0? r515[x][y-1]:0;
ans+= x-1>0? r515[x-1][y]:0;
}
return ans;
}
int[] a168;
void AOJ0168(){ // Kannondou
while(sc.hasNext()){
int n=sc.nextInt();
if(n<=0) break;
a168=new int[n+1];
a168[0]=1;
for(int i=1; i<=n; i++) a168[i]=solve168(i);
int day=(a168[n]/10) + (a168[n]%10==0? 0: 1);
// out.println("n"+a168[n]+" day"+day);
out.println(((day/365) + (day%365==0?0 :1)));
}
}
int solve168(int a){
int ans=0;
for(int i=a-1; i>=a-3; i--) ans+= i>=0? a168[i]: 0;
return ans;
}
void AOJ0176(){ // What Color?
int[] R = {0,0,0,0,255,255,255,255};
int[] G = {0,0,255,255,0,0,255,255};
int[] B = {0,255,0,255,0,255,0,255};
HashMap<Integer,String> dic = new HashMap<Integer,String>();
dic.put(0, "black"); dic.put(1, "blue"); dic.put(2, "lime"); dic.put(3, "aqua");
dic.put(4, "red"); dic.put(5, "fuchsia"); dic.put(6, "yellow"); dic.put(7, "white");
while(sc.hasNext()){
String s=sc.next();
if(s.equals("0")) break;
int r=Integer.parseInt(""+s.charAt(1)+s.charAt(2),16), g=Integer.parseInt(""+s.charAt(3)+s.charAt(4),16), b=Integer.parseInt(""+s.charAt(5)+s.charAt(6),16);
int index=0;
double last=Double.MAX_VALUE;
for(int i=0; i<8; i++){
double d=sqrt((abs(r-R[i])<<1)+(abs(g-G[i])<<1)+(abs(b-B[i])<<1));
index = last>d? i : index;
last = last>d? d : last;
}
out.println(dic.get(index));
}
}
void AOJ0175(){ // A King in Hawaii
while(sc.hasNext()){
int n=sc.nextInt();
if(n<0) break;
StringBuilder sb = new StringBuilder();
while(n!=0){
//out.println(n&3);
sb.append(n&3);
n=n>>2;
}
out.println(sb.length()>0? sb.reverse(): 0);
}
}
void AOJ0031(){ // Weight
while(sc.hasNext()){
int n=sc.nextInt();
int temp=Integer.lowestOneBit(n);
out.print(temp);
n=(n^temp);
while(n!=0){
temp=Integer.lowestOneBit(n);
out.print(" "+temp);
n=(n^temp);
}
out.println();
}
}
void AOJ0051(){ // Differential II
int n=sc.nextInt();
for(int i=0; i<n; i++){
char[] c = sc.next().toCharArray();
int[] a = new int[8];
for(int j=0; j<8; j++) a[j]=Character.digit(c[j], 10);
Arrays.sort(a);
StringBuilder sb = new StringBuilder();
for(int j=0; j<8; j++) sb.append(a[j]);
int min=Integer.parseInt(sb.toString());
sb=new StringBuilder();
for(int j=7; j>=0; j--) sb.append(a[j]);
int max=Integer.parseInt(sb.toString());
out.println(max-min);
}
}
void AOJ0196(){ // Baseball Championship
while(sc.hasNext()){
int n=sc.nextInt();
if(n==0) break;
Team196[] teams = new Team196[n];
for(int i=0; i<n; i++){
String s=sc.next();
int win=0, lose=0;
for(int j=0; j<n-1; j++){
int temp=sc.nextInt();
if(temp==0) win++;
if(temp==1) lose++;
}
teams[i] = new Team196(s,win,lose,i);
}
Arrays.sort(teams);
for(int i=0; i<n; i++) out.println(teams[i].name);
}
}
class Team196 implements Comparable<Team196>{
String name;
int win,lose,index;
Team196(String name, int win, int lose, int index){
this.name=name; this.win=win; this.lose=lose; this.index=index;
}
@Override
public int compareTo(Team196 o) {
if(this.win<o.win) return 1;
if(this.win>o.win) return -1;
if(this.lose<o.lose) return -1;
if(this.lose>o.lose) return 1;
if(this.index<o.index) return -1;
if(this.index>o.index) return 1;
return 0;
}
}
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<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
bool isA(string s){
int n = 0;
if(s.at(n)!='>' || s.at(++n)!='\'' ||s.at(++n)!='=') return false;
int cnt = 1;
for(;s.at(++n)=='='; cnt++);
if(s.at(n)!='#') return false;
for(int i=0; i<cnt; i++){
if(s.at(++n)!='=') return false;
}
if(s.at(++n)!='~' || s.size()>n+1) return false;
return true;
}
bool isB(string s){
int n = 0;
if(s.at(n)!='>' || s.at(++n)!='^' || s.at(++n)!='Q' || s.at(++n)!='=') return false;
while(true){
if(s.at(++n)=='Q'){
if(s.at(++n)!='=') return false;
}
else break;
}
if(s.at(n)!='~' || s.at(++n)!='~' || s.size()>n+1) return false;
return true;
}
int main(){
string S;
int N;
cin>>N;
for(int i=0;i<N;i++){
cin>>S;
if(isA(S)) puts("A");
else if(isB(S)) 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 | java | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
for(int i = 0; i < n; i++){
String str = sc.nextLine();
if(str.matches(">\'(=+)#\\1~")){
System.out.println("A");
}else if(str.matches(">\\^(Q=)+~~")){
System.out.println("B");
}else{
System.out.println("NA");
}
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
while(n-- > 0){
String s = scan.nextLine();
if(s.matches("^>'(=+)#\\1~$")) System.out.println("A");
else if(s.matches("^>\\^(Q=)+~~$")) System.out.println("B");
else System.out.println("NA");
}
}
} |
p00139 Snakes | In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well.
For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish.
Class B ends with "~~" after "> ^" followed by one or more "Q =".
Example of type A:>'==== # ==== ~>'== # == ~
Example of B type:> ^ Q = Q = Q = Q = ~~> ^ Q = Q = ~~
Receives a snake as character string data, determines what kind it is, and outputs "A" for type A, "B" for type B, and "NA" for other types. Please create a program to do.
Input
The input is given in the following format:
n
S1
S2
::
Sn
The number of snakes identified on the first line n (1 ≤ n ≤ 10000), and the following n lines contain the i-th snake string Si (200 characters or less, without spaces) on each line. Is given to.
Output
Print the i-th snake type A, B or NA on line i.
Example
Input
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
Output
A
B
NA | {
"input": [
"3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~"
],
"output": [
"A\nB\nNA"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<string>
using namespace std;
bool isA(string &s){
if(s.size()<6)return false;
if(s[0]!='>'||s[1]!='\'')return false;
int i=2;
while(s[i]=='=')i++;
int cnt=i-2;
if(cnt==0||s[i]!='#')return false;
for(i++;i<s.size()&&s[i]=='=';i++)cnt--;
if(cnt||i==s.size()||s[i]!='~')return false;
return i+1==s.size();
}
bool isB(string &s){
if(s.size()<6)return false;
if(s[0]!='>'||s[1]!='^')return false;
int i=2;
for(;i<s.size()&&s[i]=='Q';){
if(i+1<s.size()&&s[i+1]=='=')i+=2;
else break;
}
if(i==2)return false;
if(i+2==s.size()&&s[i]=='~'&&s[i+1]=='~')return true;
return false;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
string s;
cin>>s;
if(isA(s))cout<<"A\n";
else if(isB(s))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 | java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1;i<=n;i++){
String s = sc.next();
StringBuffer t = new StringBuffer();
if(s.length()<=5 || s.length()%2==1){
System.out.println("NA");
}else if(s.substring(0,2).compareTo(">'")==0 && s.substring(s.length()-1,s.length()).compareTo("~")==0){
for(int k=0;k<(s.length()-4)/2;k++) t.append("=");
t.append("#");
for(int k=0;k<(s.length()-4)/2;k++) t.append("=");
if(s.substring(2,s.length()-1).compareTo(t.toString())==0) System.out.println("A");
else System.out.println("NA");
}else if(s.substring(0,2).compareTo(">^")==0 && s.substring(s.length()-2,s.length()).compareTo("~~")==0){
for(int k=0;k<(s.length()-4)/2;k++) t.append("Q=");
if(s.substring(2,s.length()-2).compareTo(t.toString())==0) System.out.println("B");
else System.out.println("NA");
}else{
System.out.println("NA");
}
}
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.