求条
查看原帖
求条
1038334
wth2026楼主2024/5/10 18:59
#include <iostream>
#include <cstring>
#include <algorithm>

#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f

using namespace std;

int son[100005][128], idx, ans;

void add(string str) {
	int q = 0, u;

	for (int i = 0; i < str.size(); ++ i) {
		u = str[i];

		if (!son[q][u]) {
			son[q][u] = ++ idx;
			
			if (str[i - 1] == '/') {
				++ ans;
			}
		}
		
//		++ cnt[q];
		q = son[q][u];
	}

//	++ cnt[q];
}

//int ask(string str) {
//	int q = 0, u;
//
//	for (int i = 0; i < str.size(); ++ i) {
//		u = str[i];
//
//		if (!son[q][u]) {
//			return 0;
//		}
//
//		q = son[q][u];
//	}
//
//	return cnt[q];
//}
//
int n, m, T;
char opt;
string str;

void init();

signed main() {
	init();
	cin >> n;

	while (n --) {
		cin >> str;
		add(str);
		cout << ans << endl;
	}

	return 0;
}

void init() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

看评测返回,应该是是不是会小一。

2024/5/10 18:59
加载中...