QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607562#2428. Comma SprinklerLJY_ljyWA 46ms21100kbC++111.6kb2024-10-03 15:20:242024-10-03 15:20:25

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 15:20:25]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:21100kb
  • [2024-10-03 15:20:24]
  • 提交

answer

//Trie树(字典树)练习 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;

const int MAXN = 1000010;
char str[MAXN], Ans[MAXN];
int exist[MAXN], End[MAXN], len, Bound[MAXN];
int eid, cnt, nex[MAXN][30], Type[MAXN];

// 空格 0, 句号 1,逗号 2
int main() {
	while (scanf("%s", str + 1) != EOF) {
		int n = strlen(str + 1), m;
		cnt++;
		if ('a' <= str[n] && str[n] <= 'z') m = n;
		else m = n - 1;
		Type[cnt] = (Type[cnt - 1] % 3) * 3;
		if ('.' == str[n]) Type[cnt] ++;
		if (',' == str[n]) Type[cnt] += 2; 
		for (int i = len + 1; i <= len + m; i++)
			Ans[i] = str[i - len];
		len = len + m;
		Bound[cnt] = len;
		int p = 0;
		for (int i = 1; i <= m; i++) {
			int c = str[i] - 'a';
			if (!nex[p][c]) nex[p][c] = ++eid;
			p = nex[p][c];
 		}
 		if (Type[cnt] % 3 == 2 && exist[p] % 3 == 0)
 			exist[p] += 2;
 		if (Type[cnt] / 3 == 2 && exist[p] / 3 == 0)
 			exist[p] += 6; 
 		End[cnt] = p;
	}
	for (int i = 1; i <= cnt; i++) {
		if (exist[End[i + 1]] / 3 == 2 && exist[End[i]] % 3 == 0 && Type[i] % 3 != 1)
			exist[End[i]] += 2;
		if (exist[End[i - 1]] % 3 == 2 && exist[End[i]] / 3 == 0 && Type[i] / 3 != 1)
			exist[End[i]] += 6; 
	}
	for (int i = 1; i <= cnt; i++) {
		for (int j = Bound[i - 1] + 1; j <= Bound[i]; j++)
			printf("%c", Ans[j]); 
		if ((exist[End[i]] % 3 == 2 && Type[i] % 3 != 1) || (exist[End[i + 1]] / 3 == 2 && Type[i + 1] / 3 != 1)) {
			printf(",");
		} 
		if (Type[i] % 3 == 1) printf(".");
		printf(" ");
	}
	return 0;
} 

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5932kb

Test #2:

score: 0
Accepted
time: 0ms
memory: 5920kb

Test #3:

score: 0
Accepted
time: 1ms
memory: 5848kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 5928kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 5900kb

Test #6:

score: 0
Accepted
time: 46ms
memory: 16660kb

Test #7:

score: 0
Accepted
time: 39ms
memory: 21056kb

Test #8:

score: -100
Wrong Answer
time: 35ms
memory: 21100kb