QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#50177 | #4804. Regular Expression | bvd# | TL | 1ms | 3684kb | C++ | 1.0kb | 2022-09-25 02:30:14 | 2022-09-25 02:30:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define sz(x) (int) (x).size()
string s;
vector<string> firstChar;
vector<string> secondChar;
void init() {
rep(i,'a','z'+1) {
string s(1, i);
firstChar.push_back(s);
}
firstChar.push_back(".");
secondChar = firstChar;
secondChar.push_back("+");
secondChar.push_back("*");
secondChar.push_back("?");
}
void solve() {
getline(cin, s);
if (sz(s) == 0) {
cout << 0 << ' ' << 1;
return;
}
int cnt = 0;
for (auto c: firstChar) {
regex e = regex(c);
if (regex_match(s, e)) cnt++;
}
if (cnt > 0) {
cout << 1 << ' ' << cnt;
return;
}
for (auto c: firstChar) for (auto d: secondChar) {
regex e = regex(c+d);
if (regex_match(s, e)) {
cnt++;
}
}
cout << 2 << ' ' << cnt;
return;
}
int main() {
ios_base::sync_with_stdio(0);
int t; cin >> t; getline(cin, s);
init();
rep(i,0,t) {
solve();
cout << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3684kb
input:
2 a ab
output:
1 2 2 6
result:
ok 2 lines
Test #2:
score: -100
Time Limit Exceeded
input:
35857 a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc bd be bf bg bh bi bj bk bl bm bn bo bp bq br bs bt bu bv bw bx by bz ca cb cc cd ce cf cg ch ci cj ck cl cm cn co cp cq cr cs ct cu cv cw cx cy cz da db dc...
output:
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 8 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 8 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 ...