text
stringlengths
49
983k
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <cstring> #include <sstream> #include <cassert> using namespace std; static const double EPS = 1e-5; typedef long long ll; typedef pair<int,int> PI; typedef vector<int> vi; #define rep(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() #define mp make_pair #define pb push_back #define f first #define s second int main(){ string hebi; int n; cin>>n; while(n--){ cin>>hebi; bool a=true,b=true; if(hebi.size()<6 || hebi.size()%2){ a=false; b=false; } rep(i,hebi.size()){ if(i==0 && hebi[i]=='>')continue; if(i==1 && hebi[i]=='\'')continue; if(i==hebi.size()-1 && hebi[i]=='~')continue; else if(i>=2 && i<hebi.size()-1 && i!=hebi.size()/2 && hebi[i]=='=')continue; else if(i==hebi.size()/2 && hebi[i]=='#')continue; a=false; } rep(i,hebi.size()){ if(i==0 && hebi[i]=='>')continue; if(i==1 && hebi[i]=='^')continue; if(i==hebi.size()-1 && hebi[i]=='~')continue; if(i==hebi.size()-2 && hebi[i]=='~')continue; else if(i%2==0 && hebi[i]=='Q')continue; else if(i%2==1 && hebi[i]=='=')continue; b=false; } if(a)puts("A"); else if(b)puts("B"); else puts("NA"); } }
#include<iostream> #include<string> using namespace std; bool check(string s,int n) { if (s.size() <= n)return true; return false; } void solve() { string s; cin >> s; int n = 0; if (s[n] == '>') { n++; if (check(s, n)); else if (s[n] == '\'') { n++; int cnt = 0; while (s[n] == '=' && !check(s, n)) { cnt++; n++; } if (s[n] == '#') { n++; if (check(s, n))goto exit; else if (s[n] != '=')goto exit; while (s[n] == '=' && !check(s, n)) { cnt--; n++; } if (cnt == 0) { if (s[n] == '~') { n++; if (n == s.size()) { cout << "A\n"; return; } } } } } else if (s[n] == '^') { n++; if (check(s, n))goto exit; bool b = false; while (true) { if (check(s, n + 1))goto exit; else { if (s[n] == 'Q'&&s[n + 1] == '=') { n += 2; b = true; } else if (s[n] == '~'&&s[n + 1] == '~') { if (b) { cout << "B\n"; return; } else goto exit; } else goto exit; } } n++; if (check(s, n))goto exit; if (s[n] == '~') { n++; if (check(s, n))goto exit; if (s[n] == '~') { n++; if (n == s.size()) { cout << "B\n"; return; } } } } } exit:; cout << "NA\n"; return; } int main() { int n; cin >> n; for (int i = 0; i < n; i++)solve(); }
#include <iostream> #include <sstream> #include <string> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #include <numeric> #include <functional> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> using namespace std; typedef istringstream ISS; typedef ostringstream OSS; typedef vector<string> VS; typedef int INT; typedef vector<INT> VI; typedef vector<VI> VVI; typedef pair <INT, INT> II; typedef vector <II> VII; template<class T> ostream& operator << ( ostream& os, vector<T> v ) { for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) { os << *it_i << ", "; } return os; } typedef set <string> SS; SS SA; SS SB; bool checkA( string s ) { return SA.count( s ) > 0; } bool checkB( string s ) { return SB.count( s ) > 0; } string solve( string s ) { if ( checkA( s ) ) return "A"; if ( checkB( s ) ) return "B"; return "NA"; } int main() { for ( int i = 1; i <= 100; ++ i ) { SA.insert( ">'" + string( i, '=' ) + "#" + string( i, '=' ) + "~" ); } for ( int i = 1; i <= 100; ++ i ) { VS con( i, "Q=" ); SB.insert( ">^" + accumulate( con.begin(), con.end(), string() ) + "~~" ); } int n; cin >> n; for ( int i = 0; i < n; ++ i ) { string s; cin >> s; cout << solve( s ) << endl; } return 0; }
#include <iostream> #include <string> using namespace std; bool kind_a(string str){ if(str[0] != '>' || str[1] != '\'' || str[str.size()-1] != '~'){ return false; } string su = str.substr(2, str.size()-3); if(su.size()<3) return false; for(int i=0; i<su.size(); ++i){ int j = su.size()-1-i; if(i>=j) break; if(su[i]!='=' || su[i]!=su[j]){ return false; } } return su[(su.size()-1)/2]=='#'; } bool kind_b(string str){ if(str[0] != '>' || str[1] != '^' || str[str.size()-2] != '~' || str[str.size()-1] != '~'){ return false; } string su = str.substr(2, str.size()-4); if(su.size()<2) return false; for(int i=0; i<su.size(); ++i){ int j = su.size()-1-i; if(i>=j) break; if( !(su[i]=='Q' && su[j]=='=' || su[j]=='Q' && su[i]=='=') ){ return false; } } return true; } string solve(string str){ if(kind_a(str)){ return "A"; } else if(kind_b(str)){ return "B"; } else{ return "NA"; } } int main(){ int n; cin>>n; while(n--){ string str; cin>>str; cout << solve(str) << endl; } return 0; }
// 2011/10/02 Tazoe #include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; for(int i=0; i<n; i++){ string str; cin >> str; if(str[0]!='>'){ cout << "NA" << endl; continue; } if(str[1]=='\''){ int N = 0; int I = 2; while(str[I]=='='){ N++; I++; } if(N==0){ cout << "NA" << endl; continue; } if(str[I]!='#'){ cout << "NA" << endl; continue; } I++; int M = 0; while(str[I]=='='){ M++; I++; } if(N!=M){ cout << "NA" << endl; continue; } if(!(str[I]=='~'&&I+1==str.size())){ cout << "NA" << endl; continue; } cout << "A" << endl; } else if(str[1]=='^'){ int N = 0; int I = 2; while(str[I]=='Q'&&str[I+1]=='='){ N++; I += 2; } if(N==0){ cout << "NA" << endl; continue; } if(!(str[I]=='~'&&str[I+1]=='~'&&I+2==str.size())){ cout << "NA" << endl; continue; } cout << "B" << endl; } else cout << "NA" << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main() { int n,f,i,m; string s; cin>>n; while(n-->0){ cin>>s; f=0; if(s[0]=='>' && s[1]=='\''){ m=s.find('#'); if(m!=string::npos){ for(i=1;s[m-i]==s[m+i];)i++; if(i>1 && m-i==1 && m+i==s.size()-1 && s[m+i]=='~')f=1; } }else if(s[0]=='>' && s[1]=='^'){ for(i=2;s[i]=='Q'&&s[i+1]=='=';)i+=2; if(i>2 && i==s.size()-2 && s[i]=='~' && s[i+1]=='~')f=2; } if(f)puts(f==1?"A":"B"); else puts("NA"); } }
#include <cstdio> #include <iostream> #include <string> #include <algorithm> #define int long long #define rep(i, n) for (int i=0; i<n; i++) #define REP(n) rep(i, n) using namespace std; int n; string snake, head, tail, body; signed main() { cin >> n; REP(n) { cin >> snake; if (snake.length() < 6) { cout << "NA" << endl; continue; } head = snake.substr(0, 2); if (head == ">'") { tail = snake.substr(snake.length() - 1, 1); if (tail != "~") { cout << "NA" << endl; continue; } body = string((snake.length() - 4) / 2, '=') + "#" + string((snake.length() - 4) / 2, '='); if (snake.substr(2, snake.length() - 3) == body) { cout << "A" << endl; continue; } else { cout << "NA" << endl; continue; } } else if (head == ">^") { tail = snake.substr(snake.length() - 2, 2); if (tail != "~~") { cout << "NA" << endl; continue; } body = ""; int cnt = (snake.length() - 4) / 2; while (cnt--) body += "Q="; if (snake.substr(2, snake.length() - 4) == body) { cout << "B" << endl; continue; } else { cout << "NA" << endl; continue; } } else { cout << "NA" << endl; continue; } } return 0; }
#include <iostream> #include <string> #include <cstdio> using namespace std; enum { A, B, NA }; int f(string s){ if(s.size() < 6) return NA; if(s.substr(0,2)==">'"){ size_t i=2; while(i<s.size() && s[i]=='=') i++; if(i==2 || i==s.size() || s[i]!='#') return NA; size_t j=i+1; while(j<s.size() && s[j]=='=') j++; if(i-2 != j-i-1 || j==s.size() || s[j]!='~') return NA; return (j+1==s.size() && s[j]=='~') ? A : NA; } else if(s.substr(0,2)==">^"){ size_t i=2; while(i<s.size() && s[i]=="Q="[i&1]) i++; if((i&1)==1 || i==2 || i==s.size() || s[i]!='~') return NA; return (i+2==s.size() && s.substr(i)=="~~") ? B : NA; } else { return NA; } } int main(){ int n; cin >> n; for(int i=0;i<n;i++){ string s; cin >> s; char res[3][3] = {"A","B","NA"}; puts(res[f(s)]); } }
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; for(int i=0;i<n;i++){ bool a=false,b=false; string str; cin >> str; if(str[0] == '>' && str[1] == '\'' && str.size()%2==0 && str.size() >= 6){a = true;} if(str[0] == '>' && str[1] == '^' && str.size()%2==0 && str.size() >= 6){b = true;} if(a){ for(unsigned j=2;j<str.size()-1;j++){ if(j != (str.size()/2) && str[j] != '='){ a = false; break; } } if(str[str.size()/2] != '#' || str[str.size()-1] != '~') a=false; } if(b){ for(unsigned j=2;j<str.size()-3;j+=2){ if(str[j] != 'Q' || str[j+1] != '='){ b = false; break; } } if(str[str.size()-2] != '~' || str[str.size()-1] != '~') b=false; } if(a) cout << "A" << endl; else if(b) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int checkA(string); int checkB(string); int main(){ int i, n; string snake; cin >> n; for(i=0; i<n; ++i){ cin >> snake; if(checkA(snake) == 1) cout << "A" << endl; else if(checkB(snake) == 1) cout << "B" << endl; else cout << "NA" << endl; } return 0; } int checkA(string snake){ int i, j, count1=0, count2=0; if(snake[0] != '>' || snake[1] != '\'' || snake[2] != '=') return 0; for(i=2; snake[i] == '='; ++i) ++count1; if(snake[count1 + 2] != '#') return 0; for(j=count1+3; snake[j] == '='; ++j) ++count2; if(count1 != count2 || j != snake.size()-1 || snake[snake.size()-1] != '~') return 0; return 1; } int checkB(string snake){ int i; if(snake[0] != '>' || snake[1] != '^' || snake[2] != 'Q' || snake[3] != '=') return 0; for(i=2; i < snake.size()-2; i+=2){ if(snake[i] != 'Q' || snake[i+1] != '=') return 0; } if(snake[snake.size()-2] != '~' || snake[snake.size()-1] != '~') return 0; return 1; }
#include <vector> #include <list> #include <map> #include <set> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <utility> #include <functional> #include <sstream> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <climits> #include <cassert> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i) const double EPS = 1e-10; const double PI = acos(-1.0); int main(){ int n; cin>>n; REP(t,n){ string s; cin>>s; if(s[0]!='>')goto na; if(s[1]=='\''){ int state=0; int cnt1=0; int cnt2=0; FOR(i,2,s.size()){ if(s[i]=='='&&state==0){ cnt1++; }else if(s[i]=='#'&&state==0){ state=1; }else if(s[i]=='='&&state==1){ state=2; cnt2++; }else if(s[i]=='='&&state==2){ cnt2++; }else if(s[i]=='~'&&state==2){ state=3; }else{ state=-1; break; } } if(state==3&&cnt1==cnt2){ goto a; }else{ goto na; } }else if(s[1]=='^'){ int state=0; int flag=0; FOR(i,2,s.size()){ if(s[i]=='Q'&&state==0){ state=1; }else if(s[i]=='='&&state==1){ state=0; flag=1; }else if(s[i]=='~'&&state==0){ state=2; }else if(s[i]=='~'&&state==2){ state=3; }else{ state=-1; break; } } if(state==3&&flag){ goto b; }else{ goto na; } }else{ goto na; } a: cout<<"A"<<endl; continue; b: cout<<"B"<<endl; continue; na: cout<<"NA"<<endl; continue; } }
#include<bits/stdc++.h> using namespace std; int main(){ string str; int n; cin >> n; while(n--){ cin >> str; int idx = 2; int cnt = 0; bool flg = true; if(str[0] == '>' && str[1] == 39){ bool used = false; while(idx < str.size() && str[idx] == '=') { used = true; cnt++; idx++; } if(str[idx] == '#'){ idx++; while(idx < str.size() && str[idx] == '=') { cnt--; idx++; } } if(str[idx] == '~' && cnt == 0 && used) { cout << "A" << endl; flg = false; } } else if(str[0] == '>' && str[1] == '^'){ while(idx+1 < str.size() && str[idx] == 'Q' && str[idx+1] == '='){ idx += 2; cnt++; } if(cnt > 0 && str[idx] == '~' && str[idx+1] == '~') { cout << "B" << endl; flg = false; } } if(flg) cout << "NA" << endl; } }
#include <bits/stdc++.h> using namespace std; int n; string s; int main(void) { cin >> n; for (int k = 0; k < n; k++) { cin >> s; bool f = true; if (s[0] == '>' && s[1] == '\'') { int c = 0; int i; for (i = 2; s[i] == '='; i++) c++; if (c && s[i] == '#') { for (i += 1; s[i] == '='; i++) c--; if (!c && (int) s.size() == i + 1 && s[i] == '~') { cout << 'A' << endl; f = false; } } } else if (s[0] == '>' && s[1] == '^' && s[2] == 'Q' && s[3] == '=') { int i; for (i = 4; s[i] == 'Q' && s[i + 1] == '='; i += 2) ; if ((int) s.size() == i + 2 && s[i] == '~' && s[i + 1] == '~') { cout << 'B' << endl; f = false; } } if (f) { cout << "NA" << endl; } } }
#include<stdio.h> #include<string.h> int n,len; char t[300]; int checkA(){ if(t[len-1]!='~')return 0; int i=2,j=len-2; while(i<j){ if(t[i]!='=')return 0; if(t[j]!='=')return 0; i++; j--; } if(t[i]=='#')return 1; else return 0; } int checkB(){ if(t[len-2]!='~')return 0; if(t[len-1]!='~')return 0; int i; for(i=2;i<len-2;i+=2){ if(t[i]!='Q')return 0; if(t[i+1]!='=')return 0; } return 2; } int solve(){ if(len<6 || len%2==1)return 0; if(t[0]=='>'&&t[1]=='\'')return checkA(); if(t[0]=='>'&&t[1]=='^')return checkB(); return 0; } int main(){ scanf("%d",&n); while(n>0){ n--; scanf("%s",t); len=strlen(t); int ans=solve(); if(ans==0)printf("NA\n"); if(ans==1)printf("A\n"); if(ans==2)printf("B\n"); } return 0; }
#include <string> #include <iostream> using namespace std; int n; string s; int check() { if(s.size() < 6) return 0; if(s[0] != '>') return 0; if(s[1] == '\'') { int cnt = 0, cntp = 0; for(int i = 2; i < s.size() - 1; i++) { if(s[i] != '=') break; cnt++; cntp++; } if(s[2 + cnt] != '#') return 0; for(int i = cnt + 3; i < s.size(); i++) { if(s[i] != '=') break; cnt--; cntp++; } if(cnt) return 0; if(2 + cntp + 2 != s.size()) return 0; return (s[2 + cntp + 1] == '~' ? 1 : 0); } if(s[1] == '^') { int cnt = 0; for(int i = 2; i < s.size() - 2; i += 2) { if(s[i] != 'Q' || s[i + 1] != '=') break; cnt += 2; } if(cnt + 4 != s.size()) return 0; return ((s[cnt + 2] == '~' && s[cnt + 3] == '~') ? 2 : 0); } return 0; } int main() { scanf("%d", &n); for(int i = 0; i < n; i++) { cin >> s; int r = check(); if(r == 0) cout << "NA" << endl; if(r == 1) cout << "A" << endl; if(r == 2) cout << "B" << endl; } return 0; }
#include <stdio.h> bool checkA(char *p){ int eqCnt=0; if (*p++!='>') return false; if (*p++!='\'') return false; if (*p!='=') return false; while (*p++=='=') eqCnt++; p--; if (*p++!='#') return false; while (*p++=='=') eqCnt--; p--; if (eqCnt!=0) return false; if (*p++!='~') return false; if (*p!='\0') return false; return true; } bool checkB(char *p){ if (*p++!='>') return false; if (*p++!='^') return false; if (*p!='Q') return false; while (*p++=='Q'){ if (*p++!='=') return false; } p--; if (*p++!='~' || *p++!='~') return false; if (*p!='\0') return false; return true; } int main(void){ int n; char str[256]; scanf("%d", &n); for (int i=0; i<n; i++){ scanf("%s", str); if (checkA(str)){ puts("A"); } else if (checkB(str)){ puts("B"); } else { puts("NA"); } } return 0; }
#include <iostream> #include <string> using namespace std; int main(){ int n; string s; cin >> n; for(int i = 0;i < n;i++){ cin >> s; if(s.substr(0,2) == ">\'"){ if(s[s.length() - 1] != '~') cout << "NA" << endl; else { int cnt = 0,pos = 2; bool flag = true; for(;;pos++){ if(s[pos] == '#') break; if(s[pos] == '=') cnt++; else { flag = false; break; } } if(!flag || !cnt) cout << "NA" << endl; else{ pos++; for(int j = 0;j < cnt;j++){ if(s[pos + j] != '='){ flag = false; break; } } if(s[pos + cnt] != '~') flag = false; if(!flag) cout << "NA" << endl; else cout << "A" << endl; } } }else if(s.substr(0,2) == ">^"){ if(s.length() % 2 || s.length() <= 4) cout << "NA" << endl; else { bool flag = true; for(int i = 1;i < s.length() / 2;i++){ if(i != s.length() / 2 - 1 && s.substr(i * 2,2) != "Q=") flag = false; if(i == s.length() / 2 - 1 && s.substr(i * 2,2) != "~~") flag = false; } if(flag) cout << "B" << endl; else cout << "NA" << endl; } }else cout << "NA" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool isA(string s) { int cnt1 = 0; for (int i = 2; i < s.size(); ++i) { if (s[i] == '=') { ++cnt1; } else if (s[i] == '#') { if (cnt1 == 0) return false; break; } else { return false; } if (i == s.size() - 1) return false; } int cnt2 = 0; for (int i = cnt1 + 3; i < s.size(); ++i) { if (s[i] == '=') { ++cnt2; } else if (s[i] == '~') { return (cnt1 == cnt2 && i == s.size() - 1); } else { return false; } } return false; } bool isB(string s) { if (s.size() % 2) return false; int cnt = 0; for (int i = 2; i < s.size(); i += 2) { if (s[i] == 'Q' && s[i + 1] == '=') { ++cnt; } else if (s[i] == '~' && s[i + 1] == '~') { return (i + 1 == s.size() - 1) && cnt; } else { return false; } } return false; } int main() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i < n; ++i) { if (s[i][0] != '>' || s[i].size() == 3) { cout << "NA" << endl; continue; } if (s[i][1] == '\'') { cout << ( (isA(s[i])) ? "A" : "NA") << endl; } else if (s[i][1] == '^') { cout << ( (isB(s[i])) ? "B" : "NA") << endl; } else { cout << "NA" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(n); i++) struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; bool check_A( string &S ) { auto sz = S.size(); //size ??? 6 ??\?????????????????? false if( sz < 6 ) { return 0; } //?????????[>'=], ????°????[~]?????????????????´?????? false if( S[ 0 ] != '>' || S[ 1 ] != '\'' || S[ 2 ] != '=' || S[ sz - 1 ] != '~' ) { return 0; } //??????[>']??¨????°?[~]??????????????? string R = S.substr( 2, sz - 3 ); sz = R.size(); //R ???[#,=]??\???????????????????????????????????? false if( R.find_first_not_of( "#=", 0 ) != string::npos ) { return 0; } if( sz % 2 == 0 ) { return 0; } //R ?????????????????????????????£???[#]???????????\??????[#]????????£?????? false auto pos = R.find( "#" ); if( R.find( "#", pos + 1 ) != string::npos ) { return 0; } // S ???????????????[#]???????????£?????? false if( R[ sz / 2 ] != '#' ) { return 0; } return 1; } bool check_B( string &S ) { auto sz = S.size(); //size ??? 6 ??\?????????????????? false if( sz < 6 ) { return 0; } //?????????[>^], ????°????[~~]?????????????????´?????? false if( S[ 0 ] != '>' || S[ 1 ] != '^' || S[ sz - 1 ] != '~' || S[ sz - 2 ] != '~' ) { return 0; } string R = S.substr( 2, sz - 4 ); sz = R.size(); // S ???size????\???°?????£?????? false if( sz % 2 != 0 ) { return 0; } for( int i = 0; i < sz; i += 2 ) { //[Q=]?????£?¶???§????????£?????? false if( R[ i ] != 'Q' || R[ i + 1 ] != '=' ) { return 0; } } return 1; } int main() { int N; cin >> N; REP( i, N ) { string S; cin >> S; string res{ "NA" }; if( check_A( S ) ) { res = "A"; } else if( check_B( S ) ) { res = "B"; } cout << res << endl; } return 0; }
#include <iostream> using namespace std; /*s[i]ツつゥツづァツ督ッツつカツ閉カツ篠堋つェツ連ツ堕アツつオツづつ「ツづゥツ青板づーツ陛板つキ*/ int seqlen(string &s,int i){ char c = s[i]; int ret=0; while(s[i++]==c)ret++; return ret; } int main(){ int n; int flag = 0; string s; cin >> n; while(n--){ flag = 0; cin >> s; /*A*/ if(s[0]=='>' && s[1]==39){ int x=2; x += seqlen(s,x); if(s[x]!='#')flag = 1; x ++ ; if(seqlen(s,2) != seqlen(s,x))flag = 1; x += seqlen(s,x); if(s[x]!='~')flag = 1; if(!flag)flag='A'; } else if(s[0]=='>' && s[1]=='^'){ int pointa = 0; for(int i=2;i<s.length()-2;i++){ if(i%2){ if(s[i] != '=')flag = 1; else pointa++; }else{ if(s[i] != 'Q')flag = 1; else pointa++; } } if(s[s.length()-2] != '~' || s[s.length()-1] != '~')flag = 1; if(!flag && pointa>=2)flag='B'; else flag = 1; } else {flag = 1;} if(flag != 1)cout << (char)flag << endl; else cout << "NA" << endl; } }
#include <iostream> #define VARIABLE(x) cerr << #x << "=" << x << endl #define rep(i,n) for(int i=0;i<(int)(n);i++) #define REP(i,m,n) for (int i=m;i<(int)(n);i++) const int INF = 10000000; using namespace std; typedef long long ll; /** Problem0139 : Snakes **/ int main() { int n; string s; cin >> n; rep(k, n) { cin >> s; REP(i, 1, 100) { string a=">'", b=">^"; rep(j, i) { a+='='; b+="Q="; } a+='#'; rep(j, i) a+='='; a+='~'; b+="~~"; if (s == a) { cout << "A" << endl; goto end; } else if (s == b) { cout << "B" << endl; goto end; } } cout << "NA" << endl; end:; } return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; string s; for (int i=0; i<n; ++i) { cin >> s; int m = s.size(); string res = "NA"; if (s.size() < 6 || s.size() % 2 == 1) { // pass } else if (s.substr(0,2) == ">'" && s[m-1] == '~') { res = "A"; if (s[m/2] != '#') { res = "NA"; } for (int j=2; j<=m-2; ++j) { if (j == m/2) continue; if (s[j] != '=') { res = "NA"; break; } } } else if (s.substr(0,2) == ">^" && s.substr(m-2,2) == "~~") { res = "B"; for (int j=2; j<=m-4; j+=2) { if (s[j] != 'Q' || s[j+1] != '=') { res = "NA"; break; } } } cout << res << endl; } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<map> #include<set> #include<queue> #include<cstdio> #include<climits> #include<cmath> #include<cstring> #include<string> #include<sstream> #include<complex> #define f first #define s second #define mp make_pair #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) #define ALL(c) (c).begin(), (c).end() using namespace std; typedef unsigned int uint; typedef long long ll; typedef complex<double> P; bool isA(const string &str){ int n = str.size(); int m = 0; int pos = 2; if(n == 0 || n==1) return false; if(str[0] != '>') return false; if(str[1] != '\'') return false; while(pos < n && str[pos] == '=') {m++; pos++;} if(pos == n || m == 0) return false; if(str[pos++] != '#') return false; while(pos < n && str[pos] == '=') {m--; pos++;} if(pos == n) return false; if(str[pos++] != '~') return false; if(m == 0 && pos == n) return true; return false; } bool isB(const string &str){ int n = str.size(); int pos = 2; int m = 0; if(n == 0 || n == 1) return false; if(str[0] != '>') return false; if(str[1] != '^') return false; while(pos+1 < n && str[pos] == 'Q' && str[pos+1] == '=') {m++; pos+=2;} if(m == 0) return false; if(pos+2 != n) return false; if(str[pos] == '~' && str[pos+1] == '~') return true; return false; } int main(){ int n; string str; getline(cin,str); sscanf(str.c_str(),"%d",&n); while(n --> 0){ getline(cin,str); if(isA(str)) puts("A"); else if(isB(str)) puts("B"); else puts("NA"); } return 0; }
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second typedef vector<int> vi; typedef pair<int,int> pii; typedef pair<int,pii> pip; const int INF = (1<<25); const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; int n, len; string s; int checkA() { int i=2, j=len-2; while(i<j) { if(s[i] != '=' || s[j] != '=') return 0; i++; j--; } if(s[i] == '#' && s[len-1] == '~') return 1; return 0; } int checkB() { if(s[len-1]!='~' || s[len-2]!='~') return 0; for(int i=2; i<len-2; i+=2) { if(s[i] != 'Q' || s[i+1] != '=') return 0; } return 2; } int solve() { if(len<6 || len%2 == 1) return 0; if(s[0] == '>' && s[1] == '\'') return checkA(); if(s[0] == '>' && s[1] == '^') return checkB(); return 0; } int main() { cin>> n; while(n--) { cin>> s; len = s.size(); int ans = solve(); if(ans == 0) cout<< "NA"; if(ans == 1) cout<< 'A'; if(ans == 2) cout<< 'B'; cout<< endl; } }
#include <iostream> #include <string> using namespace std; void jagdeA( const string& str ) { int count = 0; int i; for( i = 2;i < str.size();i++ ){ if( str[i] == '=' ) count++; else if( count && str[i] == '#' ) break; else{ cout << "NA" << endl; return; } } if( i == str.size() ){ cout << "NA" << endl; return; } i++; for(; i < str.size(); i++ ){ if( str[i] == '=' ) count--; else if( str[i] == '~' ) break; else{ cout << "NA" << endl; return; } } if( count || i == str.size() ) { cout << "NA" << endl; return; } cout << "A" << endl; return; } void jagdeB( const string& str ) { int count = 0; int i; for( i = 2;i < str.size();i += 2 ){ if( i + 1 >= str.size() ){ cout << "NA" << endl; return; } if( str[i] == 'Q' && str[i + 1] == '=' ){ count++; } else if( str[i] == '~' && str[i + 1] == '~' && count ){ cout << "B" << endl; return; } else { cout << "NA" << endl; return; } } cout << "NA" << endl; return; } int main(int argc, char const* argv[]) { int n; string str; cin >> n; for( int i = 0;i < n;i++ ){ cin >> str; if( str.size() < 6 || str[0] != '>' ){ cout << "NA" << endl; continue; } switch( str[1] ){ case '\'': jagdeA( str ); break; case '^': jagdeB( str ); break; default: cout << "NA" << endl; break; } } return 0; }
#include<iostream> #include<string> using namespace std ; string S ; int funcA(){ int cnt = 0 , i ; for( i=2 ; i<S.size() ; i++ ){ if( S[i] == '=' ) cnt++ ; else if( S[i] == '#' ) break ; else return -1 ; } if( cnt == 0 ) return -1 ; for( i++ ; i<S.size() ; i++ ){ if( S[i] == '=' ) cnt-- ; else if( S[i] == '~' ) break ; else return -1 ; } if( cnt == 0 ) return 1 ; return -1 ; } int funcB(){ int cnt = 0 ; for( int i=2 ; i<S.size() ; i+=2 ){ if( S[i] == 'Q' && S[i+1] == '=' ) cnt++ ; else if( S[i] == '~' && S[i+1] == '~' && cnt ) return 2 ; else return -1 ; } return -1 ; } int main(){ int N ; cin >> N ; while( N-- ){ cin >> S ; int ans = -1 ; if( S.size() < 6 || S.size()%2 == 1 ){} else if( S[0] == '>' && S[1] == '\'' ){ ans = funcA() ; } else if( S[0] == '>' && S[1] == '^' ){ ans = funcB() ; } if( ans == -1 ) cout << "NA" << endl ; if( ans == 1 ) cout << "A" << endl ; if( ans == 2 ) cout << "B" << endl ; } return 0 ; }
#include <iostream> #include <string> using namespace std; bool isA(const string& s){ if( s.size() >= 1 && s[0] != '>' ) return false; if( s.size() >= 2 && s[1] != '\'' ) return false; int cnt1 = 0, cnt2 = 0; for(int i=2, j=0 ; i < s.size()-1 ; i++ ){ if( s[i] == '=' ){ j? cnt1++ : cnt2++; }else if( s[i] == '#' ){ j++; }else{ return false; } } if( cnt1 == 0 || cnt2 == 0 || cnt1 != cnt2 || s[s.size()-1] != '~' ){ return false; } return true; } bool isB(const string& s){ if( s.size() >= 1 && s[0] != '>' ) return false; if( s.size() >= 1 && s[1] != '^' ) return false; if( s.size() < 6 || s.size() % 2 == 1 ) return false; bool flag = false; for(int i=3 ; i < s.size() - 2 ; i += 2 ){ if( s[i-1] != 'Q' || s[i] != '=' ){ return false; } } if( s[s.size()-2] != '~' || s[s.size()-1] != '~' ){ return false; } return true; } int main(){ int n; cin >> n; for( ; n-- ; ){ string s; cin >> s; if( isA( s ) ){ cout << "A" << endl; }else if( isB( s ) ){ cout << "B" << endl; }else{ cout << "NA" << endl; } } }
#include <cstdio> #include <regex.h> #include <cstring> int main() { int n; regex_t regst[2]; regmatch_t match[3]; const char *pattern[] = {"^>'(=+)#(=+)~$", "^>\\^(Q=)+~~$"}; const char *type_label[] = {"A", "B", "NA"}; int type; char snake[201]; scanf("%d", &n); for (int x=0; x<n; x++) { scanf("%s", snake); type = 2; for (int i=0; i<2; i++) { regcomp(&regst[i], pattern[i], REG_EXTENDED); } if (!regexec(&regst[0], snake, 3, match, 0)) { if (match[1].rm_eo - match[1].rm_so == match[2].rm_eo - match[2].rm_so) { type = 0; } } else if (!regexec(&regst[1], snake, 0, NULL, 0)) { type = 1; } printf("%s\n", type_label[type]); } return 0; }
#include<stdio.h> #include<string.h> bool checkA(char st[1001]){ int len = strlen(st); if(len<4)return false; if(st[len-1]!='~')return false; if(len%2 == 1)return false; st[len/2-1] = '='; for(int i = 0; i < len-1; i++){ if(st[i] !='=')return false; } return true; } bool checkB(char st[1001]){ if(strlen(st)<4)return false; if(st[strlen(st)-1] != '~' || st[strlen(st)-2] != '~')return false; for(int i = 0 ; i < strlen(st)-2; i+=2){ if(!(st[i]=='Q' && st[i+1] =='='))return false; } return true; } int main(void){ int n; scanf("%d",&n); for(int i = 0; i < n ;i++){ char str[1001]; scanf("%s",str); bool Af = false; bool Bf = false; if(str[1] == '\''){ Af = checkA(str+2); }else { Bf = checkB(str+2); } if(str[0] != '>'){ puts("NA"); }else if(Af == Bf){ puts("NA"); }else if(Af == true){ puts("A"); }else{ puts("B"); } } return 0; }
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cstring> #define ll long long #define ull unsigned long long #define pii pair<int,int> #define vi vector<int> #define VS vector<string> #define all(x) x.begin(),x.end() #define mp make_pair #define pb push_back using namespace std; int main(){ int n; cin >> n; for(int i=0; i < n; i++){ string input; cin >> input; string check = input.substr(0, 2) + input.substr(input.size()-2, 2); bool isCorrect = true; if(check == ">'=~"){ if(input.size() == 4) isCorrect = false; int count = 0; for(int j=2; input.substr(j,1) == "="; j++) count++; if(input.substr(count+2, 1) != "#") isCorrect = false; for(int j=2+count+1; j < 2+count*2+1; j++) if(input.substr(j, 1) != "=") isCorrect = false; if(input.size() != count*2+2+1*2) isCorrect = false; if(isCorrect) cout << "A" << endl; }else if(check == ">^~~"){ if(input.size() == 4) isCorrect = false; for(int j=2; j < input.size()-2; j+=2) if(input.substr(j, 2) != "Q=") isCorrect = false; if(isCorrect) cout << "B" << endl; }else { cout << "NA" << endl; } if(!isCorrect) cout << "NA" << endl; } }
#include<iostream> #include<string> using namespace std; int main(){ long n,f,i,j,k,m; string s; cin>>n; for(i=0;i<n;i++){ cin>>s; if(s.substr(0,2)==">'"){ if(s.substr(2,1)!="="){f=2;goto E;} j=s.find_first_not_of('=',3); m=j-2; if(s.substr(j,1)!="#"){f=2;goto E;} k=s.find_first_not_of('=',j+1); if(k-j-1!=m){f=2;goto E;} if(s.substr(k,1)!="~"){f=2;goto E;} if(k+1!=s.size()){f=2;goto E;} f=0; }else if(s.substr(0,2)==">^"){ if(s.substr(2,2)!="Q="){f=2;goto E;} for(j=4;;j+=2){ if(s.substr(j,2)!="Q=")break; } if(s.substr(j,2)!="~~")f=2;else f=1; }else{ f=2; } E: if(f==0)cout<<"A"<<endl; else if(f==1)cout<<"B"<<endl; else cout<<"NA"<<endl; } return 0; }
#include <iostream> #include <string> #include <sstream> #include <algorithm> #include <vector> #include <utility> #include <stack> #include <queue> #include <map> #include <set> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define repc(i,s,e) for(int i=(s); i<(e); i++) #define pb(n) push_back((n)) #define mp(n,m) make_pair((n),(m)) #define all(r) r.begin(),r.end() #define fi first #define se second typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ll> vl; typedef vector<vl> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { int n; string s; cin >> n; rep(i, n) { cin >> s; string ans; //cout << s.size() << endl; if (s.size() % 2 == 1||s.size()==4) { ans = "NA"; } else if (s[0] == '>'&&s[s.size() - 1] == '~') { if (s[1] == '\'') { ans = "A"; for (int i = 2; i < s.size() - 1; i++) { if (i == s.size() / 2) { if (s[i] != '#') { ans = "NA"; break; } } else { if (s[i] != '=') { ans = "NA"; break; } } } } else if (s[1] == '^'&&s[s.size()-2]=='~') { ans = "B"; for (int i = 2; i < s.size() - 2; i += 2) { if (s[i] != 'Q' || s[i + 1] != '=') { ans = "NA"; break; } } } else ans = "NA"; } else { ans = "NA"; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while(n--) { string str; string kp; string set; int flag=0; int count=0; int count_b=0; int i=0; cin >> str; for(i=0;i<2;i++)kp+=str[i]++; if(kp==">'") { while(str[i]!='#') { if(str[i]=='=')count++; else flag=-1; if(flag==-1)break; i++; } i++; while(str[i]!='~') { if(str[i]=='=')count_b++; else flag=-1; if(flag==-1)break; i++; } if(flag!=-1 && count==count_b && count>=1)flag=1; count=0; for(int j=i;j<str.length();j++) { if(str[i]!='~')flag=-1; else count++; if(flag==-1)break; } if(count!=1)flag=-1; } else if(kp==">^") { while(i<str.length()-2) { count=2; while(count--) { set+=str[i]; i++; } if(set=="Q=")flag=2; else flag=-1; set.erase(set.begin(),set.end()); if(flag==-1)break; } for(i=str.length()-2;i<str.length();i++)set+=str[i]; if(set=="~~" && flag==2)flag=2; else flag=-1; } if(flag==1) cout << "A" << endl; else if(flag==2)cout << "B" << endl; else cout << "NA" << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main() { int n,f,i,m; string s; cin>>n; while(n-->0){ cin>>s; f=0; if(s[0]+s[1]=='>'+'\''){ m=s.find('#'); if(m!=string::npos){ for(i=1;s[m-i]==s[m+i];)i++; if(i>1 && m-i==1 && m+i==s.size()-1 && s[m+i]=='~')f=1; } }else if(s[0]+s[1]=='>'+'^'){ for(i=2;s[i]=='Q'&&s[i+1]=='=';)i+=2; if(i>2 && i==s.size()-2 && s[i]=='~' && s[i+1]=='~')f=2; } if(f)puts(f==1?"A":"B"); else puts("NA"); } }
#ifdef LOCAL #define _GLIBCXX_DEBUG #define __clock__ #else #pragma GCC optimize("Ofast") #endif #include<bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<ll>; using VV = vector<VI>; using VS = vector<string>; using PII = pair<ll, ll>; // tourist set template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,b) FOR(i, 0, b) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)<<'\n' #define p2(s, t) cout << (s) << " " << (t) << '\n' #define br() p("") #define pn(s) cout << (#s) << " " << (s) << '\n' #define p_yes() p("YES") #define p_no() p("NO") #define SZ(x) ((int)(x).size()) #define SORT(A) sort(ALL(A)) #define RSORT(A) sort(ALL(A), greater<ll>()) #define MP make_pair void no(){p_no(); exit(0);} void yes(){p_yes(); exit(0);} const ll mod = 1e9 + 7; const ll inf = 1e18; const double PI = acos(-1); // >'======#======~ bool is_pattern_A(string s){ ll L = s.size(); // check tail if(s.back()!='~') return false; string body = s.substr(2, L-3); if(body.size()%2==0) return false; ll c = body.size()/2; if(body[c]!='#') return false; map<char, ll> mp; for(char c : body){ mp[c]++; } if(mp['=']>0 && mp['=']==body.size()-1 && mp['#']==1){ return true; }else{ return false; } } bool is_pattern_B(string s){ ll L = s.size(); string tail = s.substr(L-2); if(tail!="~~") return false; string body = s.substr(2, L-4); if(body.size()==0) return false; if(body.size()%2==1) return false; for(int i=0; i<body.size(); i+=2){ if(body[i]=='Q' && body[i+1]=='='){ // ok }else{ return false; } } return true; } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll N; cin >> N; rep(i, N){ string s;cin>>s; if(s.size()==1){ p("NA"); continue; } string head = s.substr(0, 2); if(head==">'"){ if(is_pattern_A(s)){ p("A"); }else{ p("NA"); } } else if(head==">^"){ if(is_pattern_B(s)){ p("B"); }else{ p("NA"); } } else{ p("NA"); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while(T--) { string s; cin >> s; if(s[0]!='>'||s.size()<=3) cout << "NA" << endl; else if(s[1]=='\'') { if(s[s.size()-1]!='~'||s.size()%2) { cout << "NA" << endl; goto next; } s=s.substr(2,s.size()-3); for(int i=0; i<s.size()/2; i++) { if(s[i]!='='||s[i+s.size()/2+1]!='=') { cout << "NA" << endl; goto next; } } if(s.size()<3||s[s.size()/2]!='#') cout << "NA" << endl; else cout << "A" << endl; } else { if(s[s.size()-2]!='~'||s[s.size()-1]!='~'||s.size()%2) { cout << "NA" << endl; goto next; } s=s.substr(2,s.size()-4); for(int i=0; i<s.size(); i+=2) { if(s[i]!='Q'||s[i+1]!='=') { cout << "NA" << endl; goto next; } } if(s.size()>=2) cout << "B" << endl; else cout << "NA" << endl; } next:; } return 0; }
#include<iostream> #include<string> using namespace std; int main() { string s, r; int n,i; bool b; cin>>n; while(n--) { cin>>s; r = "NA"; if(s.size() > 5 && (s.size()&1)==0 && s[0]=='>') { if(s[1]=='\'') { if(s[s.size()-1]=='~' && s[s.size()/2]=='#') { b=true; for(i=2;i<s.size()/2;++i) if(s[i]!= '=') b=false; for(i=s.size()/2+1;i<s.size()-1;++i) if(s[i]!= '=') b=false; if(b) r = 'A'; } } else if(s[1]=='^') { if(s[s.size()-1]=='~' && s[s.size()-2]=='~') { b=true; for(i=2;i<s.size()-2;i+=2) if( !(s[i]=='Q' && s[i+1]=='=') )b=false; if(b) r='B'; } } } cout << r << endl; } return 0; }
#include<iostream> #include<string> #include<sstream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; int main(){ int n; cin>>n; for(int i=0;i<n;++i){ string line; cin>>line; string sol = "NA"; if(line.find('#')!=string::npos){ bool flag = false; string a = ""; string b = ""; for(int x=2;x<line.size()-1;++x){ if(line[x] == '#'){ flag = true; continue; } if(!flag){ a += line[x]; }else{ b += line[x]; } } if(line.size()> 3 && line[0]=='>' && line[1]=='\'' && line[line.size()-1]=='~' && a==b && a!="")sol = "A"; }else{ bool flag = true; for(int x=2;line.size()>4 && x<(line.size()-3);x+=2){ if(line[x] !='Q' || line[x+1] != '=')flag = false; } if(line.size()>4 && line[0]=='>' && line[1]=='^' && line[line.size()-1]=='~' && line[line.size()-2]=='~' && flag)sol="B"; } cout<<sol<<endl; } return 0; }
#include <iostream> #include <algorithm> #include <string> using namespace std; int main() { int Tc; string s; while(cin>>Tc) { while(Tc--) { cin >> s; int const N = s.size(); bool NA = 0; bool isA; if(s[0] != '>') NA = 1; if(s[1] == '\'') { if(s[2] != '=') NA = 1; for(int i=2; i<(N-3)/2+2; i++) if(s[i]!='=') NA=1; if(s.substr(2, (N-3)/2) + "~" != s.substr(3+(N-3)/2)) NA = 1; if(s[(N-3)/2+2] != '#') NA = 1; isA = 1; } else if(s[1] == '^') { int cnt; if( !(s[2] == 'Q' && s[3] == '=') ) NA = 1; for(cnt=2; cnt<N-2; cnt+=2) { if(!(s[cnt] == 'Q' && s[cnt+1] == '=')) NA = 1; } if(!(s[cnt] == '~' && s[cnt+1] == '~')) NA = 1; if(cnt+2 != N) NA = 1; isA = 0; } else { NA = 1; } if(NA) cout << "NA" << endl; else if(isA) cout << "A" << endl; else cout << "B" << endl; } } return 0; }
#include<iostream> #include<cstring> #include<algorithm> #include<string> #include<vector> #include<cstdio> #include<cmath> #define pb(in,tmp) in.push_back(tmp) #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,b) loop(i,0,b) #define all(in) in.begin(),in.end() const double PI=acos(-1); using namespace std; int main(){ int n; cin>>n; rep(i,n){ string ans; string s; cin>>s; if(s[0]!='>'){cout<<"NA"<<endl;continue;} if(s[1]=='^'){ ans='B'; int j=2; if(s[j]!='Q'||s[j+1]!='=')ans="NA"; while(s[j]=='Q'&&s[j+1]=='=')j+=2; if(s[j]!='~'||s[j+1]!='~')ans="NA"; j+=2; if(j!=s.size())ans="NA"; }else if(s[1]=='\''){ ans='A'; int h1=0,h2=0; int j=1; while(s[++j]=='=')h1++; if(s[j]!='#')ans="NA"; while(s[++j]=='=')h2++; if(s[j]!='~')ans="NA"; if(++j!=s.size())ans="NA"; if(h1!=h2||!h1)ans="NA"; }else ans="NA"; cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; #define int long long #define FR first #define SC second #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++) #define each(a, b) for(auto& a : b) typedef pair<int, int> P; const int inf = 1LL << 55; const int mod = 1e9 + 7; signed main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); int n; cin >> n; while(n--) { string s; cin >> s; int kind = 0; int sz = s.size(); if(s[0] == '>' && s[1] == '\'' && s[sz-1] == '~' && s.size() > 5) kind = 1; else if(s[0] == '>' && s[1] == '^' && s[sz-1] == '~' && s[sz-2] == '~' && sz%2 == 0 && s.size() > 4) kind = 2; else kind = 3; if(kind == 1) { int cnt = 0, cmp = 0; for(int i = 2; i < sz-1 && kind != 3; i++) { if(s[i] != '=' && s[i] != '#') kind = 3; else { if(s[i] == '=') cnt++; else if(s[i] == '#' && !cmp) cmp = cnt, cnt = 0; else kind = 3; } } if(cnt != cmp) kind = 3; } else if(kind == 2) { for(int i = 2; i < sz-2 && kind != 3; i+=2) { if(s.substr(i, 2) != "Q=") kind = 3; } } if(kind == 1) puts("A"); else if(kind == 2) puts("B"); else if(kind == 3) puts("NA"); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; #define loop(i,a,b) for(int i=(a);i<ull(b);++i) #define rep(i,n) loop(i,0,n) #define all(a) (a).begin(), (a).end() const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; int main(){ int n; cin >> n; rep(q, n){ string s; cin >> s; if(s.substr(0, 2) == ">'"){ s = s.substr(2); int c = 0; bool p = true; for(int i=0; i < s.size(); i++) if(s[i] == '='){c++;} else break; if(s[c] != '#' || c == 0)p = false; s = s.substr(c+1); if(c+1 != s.size() || s[s.size()-1] != '~')p = false; rep(i, c) if(s[i] != '=')p = false; cout << (p ? "A" : "NA") << endl; }else if(s.substr(0, 2) == ">^"){ bool p = true; s = s.substr(2); if(s.substr(0, 2) != "Q=") p = false; while(s.substr(0, 2) == "Q=") s = s.substr(2); cout << (s == "~~" && p ? "B" : "NA") << endl; }else { cout << "NA" << endl; } } }
#include <iostream> #include <string> using namespace std; int main(){ int n; cin >> n; for(int q=0;q<n;q++) { string str; cin >> str; if(str[0] != '>') { cout <<"NA"<<endl; continue; } else if(str[1] != '\''&& str[1] != '^') { cout << "NA" << endl; continue; } int flg = 0,sum; if(str[1] == '\'') { int t = 0; sum=0; for(int i=2;i<str.size();i++) { if(str[i] == '=') t++; else if(str[i] == '#' && sum==0 && i!=2) sum = t , t = 0; else break; if(str[str.size()-1] == '~' && i == str.size() -2 && sum==t ) flg = 1; } } if(str[1] == '^' && flg == 0) { flg = 0; for(int i=2;i<str.size() ;i++) { if(i%2 == 0 && str[i] != 'Q') break; if(i%2 == 1 && str[i] !='=') break; if(str[str.size()-2] == '~' && str[str.size()-1] =='~' && i == str.size()-3&& i%2==1 ){ flg = 2; break; } } } if(flg == 0) cout << "NA" << endl; else if(flg == 1)cout <<"A" << endl; else if(flg == 2) cout << "B"<<endl; } return 0; }
#include<iostream> #include<string> using namespace std; int check(string str) { if(str[0] != '>'){ return -1; } if(str[1] != '\'' && str[1] != '^'){ return -1; } if(str[2] == '='){ if(str[str.size()-1] != '~' || str[str.size()-2] != '='){ return -1; } int i=3,cnt1=1,cnt2=0; while(str[i] != '#'){ if(i >= str.size()){ return -1; } if(str[i] != '=') { return -1; } i++; cnt1++; } i++; while(str[i] == '='){ if(i >= str.size()){ return -1; } i++; cnt2++; } if(cnt1 == cnt2){ return 0; } else{ return -1; } } else if(str[2] == 'Q'){ if(str[str.size()-1] != '~' || str[str.size()-2] != '~' || str[str.size()-3] != '='){ return -1; } int i = 3; while(1){ if(i >= str.size()-2){ return 1; } if(i&1){ if(str[i] != '='){ return -1; } } else{ if(str[i] != 'Q'){ return -1; } } i++; } return 1; } else{ return -1; } } int main(void) { int n; string str; cin >> n; while(n-->0){ cin >> str; int ans = check(str); if(ans < 0){ cout << "NA" << endl; } if(ans == 0){ cout << "A" << endl; } if(ans == 1){ cout << "B" << endl; } } return 0; }
#include<iostream> #include<string> using namespace std; int isfa(string); int isfb(string); int main(){ int n,fa,fb; string str; cin >> n; for(int i = 0;i < n;i++){ cin >> str; if(str.size()>5){ fa = isfa(str); fb = isfb(str); }else fa=fb=0; if(fa == 1) cout << "A" << endl; else if(fb == 1) cout << "B" << endl; else cout << "NA" << endl; } return 0; } int isfa(string n){ int pos,c1,c2; c1=c2=0; pos=n.size()-1; if(n[0]!='>')return 0; if(n[1]!='\'')return 0; if(n[pos]!='~')return 0; pos--; while(n[pos]=='='){ c1++; pos--; } if(n[pos]!='#')return 0; pos--; while(n[pos]=='='){ c2++; pos--; } if(c1!=c2)return 0; if(pos!=1)return 0; return 1; } int isfb(string n){ int pos; pos = n.size()-1; if(n[pos]!='~'||n[pos-1]!='~') return 0; if(n[0]!='>'||n[1]!='^')return 0; pos -= 2; while(n[pos]=='='&&n[pos-1]=='Q')pos-=2; if(pos!=1)return 0; return 1; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; bool check_A(string str){ if(str.size() < 6 || str.size() % 2 == 1){ return false; } if(str.substr(0, 2) != ">'"){ return false; } int count = 0; for(int i = 2; i < (str.size() - 4) / 2 + 2; i++){ if(str[i] != '='){ return false; } } if(str[str.size() / 2] != '#'){ return false; } for(int i = str.size() / 2 + 1; i <= str.size() - 2; i++){ if(str[i] != '='){ return false; } } if(str[str.size() - 1] != '~'){ return false; } return true; } bool check_B(string str){ if(str.size() < 6 || str.size() % 2 == 1){ return false; } if(str.substr(0, 2) != ">^"){ return false; } for(int i = 2; i < str.size() - 2; i += 2){ if(str.substr(i, 2) != "Q="){ return false; } } if(str.substr(str.size() - 2, 2) != "~~"){ return false; } return true; } int main(){ int n; string str; cin >> n; for(int loop = 0; loop < n; loop++){ cin >> str; if(check_A(str)){ printf("A\n"); }else if(check_B(str)){ printf("B\n"); }else{ printf("NA\n"); } } return 0; }
#include <iostream> using namespace std; typedef string::iterator S; string ss; string snakeA(S it){ int count = 0; for(;it!=ss.end()&&*it=='=';it++,count++); if(!count) return "NA"; if(it==ss.end()||*it!='#') return "NA"; it++; for(;it!=ss.end()&&*it=='=';it++,count--); if(it==ss.end()||*it!='~') return "NA"; it++; if(*it||count) return "NA"; return "A"; } string snakeB(S it){ while(true){ if(it==ss.end()||*it++!='Q') return "NA"; if(it==ss.end()||*it++!='=') return "NA"; if(it==ss.end()) return "NA"; if(*it=='~') break; } if(*++it=='~'&&!*++it) return "B"; return "NA"; } string snake(string ss){ S it = ss.begin(); if( *it++ != '>' ) return "NA"; if( *it == '\'' ) return snakeA(++it); else if( *it == '^' ) return snakeB(++it); else return "NA"; } int main(){ int n; for(cin>>n,cin.ignore();n--;){ getline(cin, ss); cout<<snake(ss)<<endl; } return 0; }
#include <iostream> #include <cstdio> #include <string.h> using namespace std; int checksnake(string, int); int main(void) { int n, len; char snake[200]; int type; cin >> n; for(int i = 0 ; i < n ; i++) { scanf("%s", snake); len = strlen(snake); type = checksnake(snake, len); if(type == 1) cout << 'A' << endl; else if(type == 2) cout << 'B' << endl; else if(type == 3) cout << "NA" << endl; for(int a = 0 ; a < 200 ; a++) { snake[a] = 0; } len = 0; } return 0; } int checksnake(string snake, int len) { int flag1=0, flag2=0, flag3=0; int true_flag=0, true_flag2=0, true_flag3=0; int cnt1=0, cnt2=0; if(true_flag == 0) { for(int i = 0 ; i < len - 1 ; i++) { if(snake[i] != '>' && snake[i] != '#' && snake[i] != '=' && snake[i] != '\'') { true_flag2 = 1; break; } if(snake[i] == '>' && snake[i+1] == '\'') flag2 = 1; if(snake[i] == '=' && flag1 == 0 && flag2 == 1) {cnt1++; flag3 = 1; } if(snake[i] == '=' && flag1 == 1 && flag2 == 1) {cnt2++; flag3 = 1; } if(snake[i] == '#' && flag2 == 1 && flag3 == 1) flag1 = 1; //cout << cnt1 << ' ' << cnt2 << endl; } if(snake[len-1] == '~' && cnt1 == cnt2 && flag2 == 1 && flag3 == 1 && true_flag2 == 0) { return 1; true_flag = 1; } } if(true_flag == 0) { for(int i = 0 ; i < len - 2 ; i++) { if(snake[i] != '>' && snake[i] != '^' && snake[i] != '=' && snake[i] != 'Q') { true_flag3 = 1; break; } if(snake[i] == '>' && snake[i+1] == '^') flag3 = 1; if(snake[i] == 'Q' && snake[i+1] == '=' && flag3 == 1) flag1 = 1; } if(snake[len-2] == '~' && snake[len-1] == '~' && flag1 == 1 && flag3 == 1 && true_flag3 == 0) { return 2; true_flag = 1; } } if(true_flag == 0 || true_flag2 == 1 || true_flag3 == 1) { return 3; } }
#include <iostream> #include <string> using namespace std; bool isa(string s) { int pos = 2,cnt = 0; if(s[pos] != '=') return false; while(s[pos] == '=') pos++,cnt++; if(s[pos] != '#') return false; pos++; for(int i=0; i<cnt; ++i) { if(s[pos+i] != '=') return false; } pos += cnt; if(pos == s.length()-1 && s[pos] == '~') return true; return false; } bool isb(string s) { int pos = 2; if(s[2] != 'Q' || s[3] != '=') return false; for(; pos < s.length()-2; pos += 2) if(s[pos] != 'Q' || s[pos+1] != '=') return false; if(s[s.length()-1] == s[s.length()-2] && s[s.length()-1] == '~') return true; return false; } int main() { int n; cin>>n; string s; for(int i=0; i<n; ++i) { cin>>s; if(s.length() <= 2 || s[0] != '>') { cout<<"NA"<<endl; } else if(s[1] == '\'') { if(isa(s)) { cout<<"A"<<endl; }else{ cout<<"NA"<<endl; } } else { if(isb(s)) { cout<<"B"<<endl; }else{ cout<<"NA"<<endl; } } } }
#include<iostream> using namespace std; int main() { int n; for(cin>>n;n--;) { string s; cin>>s; string ans="NA"; if(s.substr(0,2)==">'" &&s[s.size()-1]=='~') { string tmp=s.substr(2,s.size()-3); // cout<<tmp<<endl; if(tmp.size()%2!=0 && tmp.size()>1 && tmp[tmp.size()/2]=='#' && tmp.substr(0,tmp.size()/2)==tmp.substr(tmp.size()/2+1,tmp.size()/2) && tmp.substr(0,tmp.size()/2)==*(new string(tmp.size()/2,'='))) ans="A"; } else if(s.substr(0,2)==">^" && s.substr(s.size()-2,2)=="~~") { string tmp=s.substr(2,s.size()-4); // cout<<tmp<<endl; bool flag=false; while(tmp.size()>0) { if(tmp.substr(0,2)=="Q=") { tmp=tmp.substr(2,tmp.size()-2); flag=true; } else break; } if(tmp.size()==0&&flag) ans="B"; } cout<<ans<<endl; } }
#include<iostream> #include<string> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; bool asnake(string s){ int n=s.size(); if(n%2 || n<6)return false; string com=">\'"; rep(i,(n-4)/2)com+='='; com+='#'; rep(i,(n-4)/2)com+='='; com+='~'; if(s==com)return true; else return false; } bool bsnake(string s){ int n=s.size(); if(n%2 || n<6)return false; string com=">^"; rep(i,(n-4)/2)com+="Q="; com+="~~"; if(s==com)return true; else return false; } int main(){ int n; cin>>n; rep(p,n){ string s; cin>>s; if(asnake(s))cout<<"A"<<endl; else if(bsnake(s))cout<<"B"<<endl; else cout<<"NA"<<endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(void){ int i,j,n,a; string s,ans; cin >> n; for(i = 0 ; i < n ; i++ ){ cin >> s; ans = "NA"; if( s[0] == '>'){ if( s[1] == '\''){ a = 2; int cnt1 = 0,cnt2 = 0; if( s[a] == '='){ while( s[a] == '='){ a++; cnt1++; } if( s[a] == '#' ){ a++; if( s[a] == '='){ while( s[a] == '='){ cnt2++; a++; } if( s[a] == '~' && a + 1 == s.size() && cnt1 == cnt2) ans = "A"; } } } } else if( s[1] == '^'){ a = 2; if( s[a] == 'Q' && s[a + 1] == '='){ while( s[a] == 'Q' && s[a + 1] == '=') a += 2; if( s[a] == '~' && s[a + 1] == '~' && a + 2 == s.size()) ans = "B"; } } } cout << ans << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <cmath> #include <complex> #include <map> #include <climits> #include <sstream> using namespace std; #define reep(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) reep((i),0,(n)) #define ALL(v) (v).begin(),(v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI=6*asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vint; static const int INF=1<<24; template <class T> void initvv(vector<vector<T> > &v,int a,int b, const T &t = T()){ v.assign(a,vector<T>(b,t)); } //v.erase(unique(v.begin(),v.end()),v.end()); int main(){ int n; cin>>n; rep(i,n){ string s; cin>>s; if(s.substr(0,2)==">'"&&s.substr(s.size()-1,1)=="~"){ s=s.substr(2); s=s.substr(0,s.size()-1); bool f=true; if(s.size()==0) f=false; if(s.size()&&s[0]!='='){ f=false; } while(s.size()>1){ if(s[0]==s[s.size()-1]&&s[0]=='='){ s=s.substr(1,s.size()-2); } else{ f=false; break; } } if(f){ if(s[0]=='#'){ cout<<"A\n"; } else cout<<"NA\n"; } else{ cout<<"NA\n"; } } else if(s.substr(0,2)==">^"&&s.substr(s.size()-2,2)=="~~"){ s=s.substr(2); s=s.substr(0,s.size()-2); bool f=true; if(s.size()<2) f=false; if(s.size()>=2&&s.substr(0,2)!="Q=") f=false; while(s.size()>=2){ if(s.substr(0,2)=="Q="){ s=s.substr(2); } else{ f=false; break; } } if(f){ cout<<"B\n"; } else cout<<"NA\n"; } else{ cout<<"NA\n"; } } }
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int,int> pint; #define mp make_pair template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template<class T> void chmin(T &t, T f) { if (t > f) t = f; } template<class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int main() { int n=in(); string snake; while(n--){ cin>>snake; int i; bool a=true,b=true; if(snake.size()<6||snake.size()%2!=0){ a=false; b=false; } for(i=0;i<snake.size();i++){ if(i==0){ if(snake[i]!='>'){ a=false; b=false; } } if(i==1){ if(snake[i]!='\'')a=false; if(snake[i]!='^')b=false; } if(i*2==snake.size()){ if(snake[i]!='#')a=false; } if(i==snake.size()-1){ if(snake[i]!='~'){ a=false; b=false; } } if(i==snake.size()-2){ if(snake[i]!='~')b=false; } if(i!=0&&i!=1&&i*2!=snake.size()&&i!=snake.size()-1){ if(snake[i]!='=')a=false; } if(i%2==0&&i!=0&&i!=snake.size()-2){ if(snake[i]!='Q')b=false; } if(i%2==1&&i!=1&&i!=snake.size()-1){ if(snake[i]!='=')b=false; } } if(a){ cout<<"A\n"; }else if(b){ cout<<"B\n"; }else{ cout<<"NA\n"; } } return 0; }
#include <iostream> using namespace std; bool chk_a(const string s) { bool c = true; int f, b; f = b = 0; for (int i = 0; i < s.size(); i++) { if (s[i] != '=' && s[i] != '#') return false; if (c && s[i] == '#') c = false; else if (s[i] == '=' && c) f++; else b++; } return (f == b) ? true : false; } bool chk_b(const string s) { for (int i = 0; i < s.size(); i += 2) if (s[i] != 'Q' || s[i + 1] != '=') return false; return true; } int main() { int n; cin >> n; while (n--) { string inp; bool flag = false; cin >> inp; if (inp.size() >= 5 && inp[0] == '>' && inp[inp.size() - 1] == '~') { if (inp[1] == '\'') { // Aの判定 if (chk_a(inp.substr(2, inp.size() - 3))) { cout << "A" << endl; flag = true; } } else if (inp.size() >= 6 && inp[1] == '^' && inp[inp.size() - 2] == '~') { // Bの判定 if (chk_b(inp.substr(2, inp.size() - 4))) { cout << "B" << endl; flag = true; } } } if (!flag) cout << "NA" << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { const string Type[] = {"A", "B", "NA"}; int n; while (cin >> n) { for (int i = 0; i < n; ++i) { string snake; cin >> snake; int ans = 2; int length = static_cast<int>(snake.size()); if (snake[0] == '>' && snake[length-1] == '~') { if (length >= 5 && snake[1] == '\'' && snake.find_first_of("#") != string::npos) { int sharp = snake.find_first_of("#"); bool valid = true; for (int j = 2; j < sharp && valid; ++j) { if (snake[j] != '=') valid = false; } for (int j = sharp+1; j < length-1 && valid; ++j) { if (snake[j] != '=') valid = false; } if (valid && sharp-2 == length-2-sharp) ans = 0; } else if (length >= 6 && snake[1] == '^' && snake[length-2] == '~') { bool valid = true; for (int j = 2; j < length-2 && valid; j += 2) { if (snake[j] != 'Q' || snake[j+1] != '=') valid = false; } if (valid) ans = 1; } } cout << Type[ans] << endl; } } return 0; }
#include <iostream> #include <algorithm> #include <string> using namespace std; string kaga(string s,int num){ string san; for(int i=0;i<num;i++)san+=s; return san; } void check(string s){ for(int i=1;i<99;i++){ string a,b; a=">'"+kaga("=",i)+'#'+kaga("=",i)+'~'; b=">^"+kaga("Q=",i)+"~~"; if(a==s){ cout<<"A"<<endl; goto end; } if(b==s){ cout<<"B"<<endl; goto end; } } cout<<"NA"<<endl; end:; } int main(){ int n; string s; for(cin>>n;n>0;n--){ cin>>s; check(s); } return 0; }
#include <iostream> //”CˆÓ•¶Žš‚ðÁ‚·ŠÖ” int clear(std::string s, std::string f){ int pos; while(pos = s.find(f), pos != std::string::npos) s.replace(pos,f.size(),""); if(s == "")return 1; return 0; } int main(){ int n; std::cin >> n; while(n--){ std::string sn, res = ""; std::cin >> sn; //Type A //“ª‚ª>'CK”ö‚ª~C‚©‚‚¨• ‚Ì•”•ª‚ªŠï”‚Å‚ ‚é if(sn.substr(0,2) == ">'" && sn[sn.size()-1] == '~' && (sn.size()-3) % 2 == 1){ std::string st = sn.substr(2,sn.size()-3); //‚¨• ‚̐^‚ñ’†‚ª# if(st[st.size()/2] == '#'){ st.replace(st.size()/2,1,""); //#ˆÈŠO‚ª‚·‚ׂÄ= // int eq = 1; // for(int i=0;i<st.size();i++){ // if(st[i] != '='){eq = 0;break;} // } // if(eq)std::cout << "A" << std::endl; if(st != "") if(clear(st,"="))res = "A\n"; } } //Type B if(sn.substr(0,2) == ">^" && sn.substr(sn.size()-2,2) == "~~" && (sn.size()-4) % 2 == 0){ std::string st = sn.substr(2,sn.size()-4); if(st != "") if(clear(st,"Q="))res = "B\n"; } if(res == "")res = "NA\n"; std::cout << res; } }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(n); i++) #define REP2(i,x,n) for(int i=x; i<(n); i++) #define ALL(n) begin(n),end(n) struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int check( string S ) { //A if( S[ 0 ] == '>' && S[ 1 ] == '\'' && S[ S.size() - 1 ] == '~' && S.size() >= 6 ) { S = S.substr( 2, S.size() - 3 ); if( S.find_first_not_of( "#=", 0 ) != string::npos ) return 0; return S.substr( 0, S.find('#') ).size() == S.substr( S.find( '#' ) + 1, S.size() - 1 ).size() ? 1 : 0; } //B if( S[ 0 ] == '>' && S[ 1 ] == '^' && S[ S.size() - 1 ] == '~' && S[ S.size() - 2 ] == '~' && S.size() >= 6 ) { S = S.substr( 2, S.size() - 4 ); if( S.find_first_not_of( "Q=", 0 ) != string::npos || S.size() % 2 != 0 ) return 0; for( int i = 0; i < S.size(); i += 2 ) { if( S[ i ] != 'Q' && S[ i + 1 ] != '=' ) return 0; } return 2; } return 0; } int main() { int N; cin >> N; vector<string> res{ "NA", "A", "B" }; string S; while( cin >> S ) { cout << res[ check( S ) ] << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main() { int n,i,j; string str; cin >> n; for(i=0;i<n;i++) { cin >> str; if(str[0]=='>') { if(str[1]=='\'') { int num=0; for(j=2;j<str.size();j++) { if(str[j]=='=') num++; else if(num>0 && str[j]=='#') { for(j+=1;j<str.size();j++) { if(j==str.size()-1 && str[j]=='~' && num==0) cout << "A" << endl; else if(j!=str.size()-1 && str[j]=='=') num--; else { cout << "NA" << endl; break; } } break; } else { cout << "NA" << endl; break; } } } else if(str[1]=='^') { if(str.size()<6) cout << "NA" << endl; else { for(j=2;j<str.size();j++) { if(j==str.size()-2 && str[j]=='~' && str[j+1]=='~') { cout << "B" << endl; break; } else if(j==str.size()-2 && (str[j]!='~' || str[j+1]!='~')) { cout << "NA" << endl; break; } else if((j%2==0 && str[j]!='Q') || (j%2==1 && str[j]!='=')) { cout << "NA" << endl; break; } } } } else cout << "NA" << endl; } else cout << "NA" << endl; } }
#include<iostream> #include<string> using namespace std; int main(){ int n,j,fa,fb,acount,acount2,i; string data; cin >> n; getline(cin,data); for(j = 0; j < n; j++){ fa = 0; fb = 0; acount = acount2 = 0; getline(cin,data); if(data.length() < 6) data = "OOHAZURE"; if(data[0] == '>' && data[1] == '\''){ fa = 1; i = 2; while(data[i] == '='){ acount++; i++; } if(data[i] != '#') fa = 0; i++; while(data[i] == '='){ acount2++; i++; } if(i != data.length()-1) fa = 0; if(acount != acount2) fa = 0; if(data[data.length()-1] != '~'){ fa = 0; } } if(data[0] == '>' && data[1] == '^'){ fb = 1; for(i = 2; i < data.length()-3; i = i+2){ if(data[i] != 'Q' || data[i+1] != '=') fb = 0; } if(i != data.length()-2) fb = 0; if(data[data.length()-1] != '~' || data[data.length()-2] != '~') fb = 0; } if(fa == 1) cout << "A" << endl; else if(fb == 1) cout << "B" << endl; else cout << "NA" << endl; } return 0; }
//11 #include<string> #include<iostream> using namespace std; int main(){ int n; cin>>n; while(n--){ string s; cin>>s; if(s.size()>=6&&s==">'"+string((s.size()-4)/2,'=')+'#'+string((s.size()-4)/2,'=')+'~'){ cout<<'A'<<endl; }else{ int r=(s.size()-4)/2; string b; while(r--){ b+="Q="; } if(s.size()>=6&&s==">^"+b+"~~"){ cout<<'B'<<endl; }else{ cout<<"NA"<<endl; } } } return 0; }
#include<iostream> #include<string> using namespace std; bool isA(string s){ if(s.size() < 6 || s.size() % 2 == 1) return false; if(s.substr(0,2) != ">\'") return false; if(s[s.size() - 1] != '~') return false; int a, b; for( a = 2, b = s.size() - 2 ; a != b ; a++, b--){ if(s[a] != '=' || s[b] != '=') return false; } return s[a] == '#'; } bool isB(string s){ if(s.size() < 6 || s.size() % 2 == 1) return false; if(s.substr(0,2) != ">^") return false; if(s.substr(s.size() - 2) != "~~") return false; for(int i = 2 ; i < s.size() - 2 ; i += 2){ if(s.substr( i, 2) != "Q=") return false; } return true; } int main(){ int n; cin >> n; while(n--){ string s; cin >> s; if(isA(s)) cout << "A\n"; else if(isB(s)) cout << "B\n"; else cout << "NA\n"; } }
#include <stdio.h> #include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <fstream> #include <sstream> #include <math.h> #include <queue> #include <stack> #include <math.h> #include <string.h> using namespace std; bool hebi_a(string hebi){ if(!(hebi[0]=='>' && hebi[1]=='\''))return false; if(hebi[2]!='=')return false; int now=3; int count=1; while(1){ if(hebi[now]=='#'){ now++; break; }else if(hebi[now]=='='){ now++; count++; }else{ return false; } } while(now!=hebi.length()){ if(hebi[now]=='='){ now++; count--; }else if(hebi[now]=='~'){ now++; break; }else{ return false; } } if(now==hebi.length()&& count==0)return true; else return false; } bool hebi_b(string hebi){ if(!(hebi[0]=='>' && hebi[1]=='^'))return false; if(hebi[2]!='Q')return false; if(hebi[3]!='=')return false; int now=4; while(1){ if(hebi[now]!='Q'){ break; }else{ now++; } if(now==hebi.length())return false; if(hebi[now]!='='){ return false; }else{ now++; } if(now==hebi.length())return false; } if(now==hebi.length())return false; if(hebi[now]!='~')return false; now++; if(now==hebi.length())return false; if(hebi[now]!='~')return false; now++; if(now==hebi.length())return true; else return false; } int main(){ int n; cin>>n; for(int roop=0; roop<n; roop++){ string hebi; cin>>hebi; if(hebi_a(hebi))cout<<"A"<<endl; else if(hebi_b(hebi))cout<<"B"<<endl; else cout<<"NA"<<endl; } }
# define _CRT_SECURE_NO_WARNINGS 1 # include <iostream> # include <numeric> # include <string> # include <bitset> # include <vector> # include <algorithm> # include <cstdlib> # include <cstdio> # include <cstring> # include <cstdlib> # include <iomanip> # include <queue> # include <sstream> # include <climits> # include <cmath> # include <list> # include <functional> # include <string> # include <ctime> # include <set> # include <forward_list> # include <map> # include <stack> using namespace std; # define INF ((int)(1<<30)) # define REP(i,n) for(int i=0;i<(int)n;i++) # define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++) # define TORAD 2.0*M_PI/360.0 # define INT(x) int x;cin>>x; # define ALL(x) (x).begin(),(x).end() # define RALL(x) (x).rbegin(),(x).rend() # define DEBUG(x) cout<<#x<<" :"<<x<<endl; # define EPS 1e-12 template<class T> void debug(T a) { for (auto i : a)cout << i << endl; } typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> pii; typedef pair<int, pii> piii; int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 }; int main() { vector<string> a, b; for (int i = 1; i <= 100; i++) { string s = ">\'"; for (int j = 0; j < i; j++)s += "="; s += "#"; for (int j = 0; j < i; j++)s += "="; s += "~"; a.push_back(s); } for (int i = 1; i <= 100; i++) { string s = ">^"; for (int j = 0; j < i; j++)s += "Q="; s += "~~"; b.push_back(s); } int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; if (find(ALL(a), s)!=a.end())cout << "A" << endl; else if (find(ALL(b), s) != b.end())cout << "B" << endl; else cout << "NA" << endl; } }
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <set> #include <map> #include <string> #include <stack> #include <queue> #include <cmath> #include <cstdio> #include <istream> #include <sstream> #include <iomanip> #include <iterator> #include <climits> using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef vector<int> VI; typedef vector< VI > VVI; typedef long long LL; typedef pair<int, int> PII; typedef vector<PII> VPII; #define X first #define Y second bool check1(string s) { int n = s.size(); if (n < 6 || s[0] != '>' || s[1] != '\'' || s[n - 1] != '~') { return false; } string sub = s.substr(2, n - 3); n = sub.size(); if (!(n % 2) || sub[n / 2] != '#') { return false; } for (int i = 0; i < n / 2; i++) { if (sub[i] != '=' || sub[n - i - 1] != '=') { return false; } } return true; } bool check2(string s) { int n = s.size(); if (n < 6 || s[0] != '>' || s[1] != '^' || s[n - 1] != '~' || s[n - 2] != '~') { return false; } string sub = s.substr(2, n - 4); n = sub.size(); for (int i = 0; i < n / 2; i++) { if (sub[i * 2] != 'Q' || sub[i * 2 + 1] != '=') { return false; } } return true; } int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; if (check1(s)) { cout << "A" << endl; }else if (check2(s)) { cout << "B" << endl; }else { cout << "NA" << endl; } } return 0; }
#include<iostream> #include<string> using namespace std; int main(){ int f,i,m; string s; for(cin>>f;cin>>s;f?puts(f-2?"A":"B"):puts("NA")){ f=0; for(i=1;s[0]+s[1]==101 & (m=s.find(35))!=string::npos & s[m-i]==s[m+i];) m-++i-1 | m+i-s.size()+1 | s[m+i]-'~'||(f=1); for(i=2;s[0]+s[1]==156 & s[i]==81 & s[i+1]==61;) ++++i-s.size()+2 | s[i]+s[i+1]-252 || (f=2); } }
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() int main() { int n; cin >> n; while(n--) { string s; cin >> s; int f=0; if (s.substr(0,2) == ">'") { int i=2, j1=0,j2=0; for (;i<s.length() && s[i]=='='; i++) j1++; if (i<s.length() && s[i++] == '#') { for (;i<s.length() && s[i]=='='; i++) j2++; if (j1>0 && j1==j2 && i<s.length() && s[i] == '~') { cout << "A"; f++; } } } else if (s.substr(0,2) == ">^") { int i = 2; for (;i<s.length()-1 && s.substr(i,2) == "Q="; i+=2) ; if (i>2 && s.substr(i,2) == "~~") { cout << "B"; f++; } } if (f==0) cout << "NA"; cout << endl; } }
#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; } }
#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; }
#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:; } }
#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; }
#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; }
#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; }
#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);}}
#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; }
#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; }
#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; }
#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; }
#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; }
#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; }
#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; }
#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; }
//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; }
#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; }
#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; }
#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; }
#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; }
#include <iostream> int main(){ int n; std::cin >> n; while(n--){ std::string sn, res = ""; std::cin >> sn; //Type A //“ª‚ª>'CK”ö‚ª~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; } }
#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; }
#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; }
#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; }
#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); }
#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; }
#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; } }
#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; }
#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; }
#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; }
#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; }
#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; }