ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
#define FAIL 0
#define SUCCESS 1
#include <ctype.h>
typedef string::const_iterator State;
#include <cstdio>
#include <ctime>
#include <regex>
using namespace std;
#define FAILED -1
/* 閾ェ菴懊お繝ウ繧ク繝ウ */
int my_regex_match(const char *text, const char *pattern) {
string a = text;
string b = pattern;
ofstream c("tmp1.txt");
c << b << endl;
c << text << endl;
system("a.exe < tmp1.txt > tmp2.txt");
ifstream d("tmp2.txt");
string s;
d >> s;
c.close();
d.close();
cout << "End" << endl;
return stoll(s);
}
/* 繧ク繝」繝�ず */
int stl_regex_match(const char *text, const char *pattern) {
match_results<string::const_iterator> mr;
auto r = regex(pattern);
string s = text;
bool result = regex_search(s, mr, r);
if (result)
return mr.position(0);
else
return FAILED;
}
void strip(char *s) {
while (s[0]) {
if (s[1] == '\n') s[1] = '\0';
s++;
}
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s testcase.txt\n", argv[0]);
exit(1);
}
int T, N;
char pattern[1002], str[10002], N_str[20], T_str[20];
FILE *f = fopen(argv[1], "r");
if (!f) {
fprintf(stderr, "File Open Error.\n");
exit(1);
}
fgets(T_str, 10, f);
strip(T_str);
T = atoi(T_str);
while (T--) {
fgets(pattern, 1001, f);
fgets(N_str, 10, f);
strip(pattern);
strip(N_str);
N = atoi(N_str);
printf("=======================\n");
printf("Pattern: %s\n", pattern);
for (int i = 0; i<N; i++) {
fgets(str, 10001, f);
strip(str);
printf("\n--- Case %d ---\n", i + 1);
int str_length = strlen(str);
if (str_length <= 60)
printf("Text: %s\n", str);
else
printf("Text: %.25s...%s(len: %d)\n", str, str + (str_length - 25), str_length);
clock_t startTime, endTime;
startTime = clock();
int stl_res = stl_regex_match(str, pattern);
endTime = clock();
printf("STL Time: %.2lf[ms]\n", (double)((long long)(endTime - startTime) * 1000) / CLOCKS_PER_SEC);
startTime = clock();
int my_res = my_regex_match(str, pattern);
endTime = clock();
printf("MY Time: %.2lf[ms]\n", (double)((long long)(endTime - startTime) * 1000) / CLOCKS_PER_SEC);
printf("Status: %s (STL: %d, MY: %d)\n", stl_res == my_res ? "AC" : "WA", stl_res, my_res);
}
}
fclose(f);
}