计蒜客蓝桥杯模拟赛 后缀字符串:STL_map+贪心

2023-05-20,,

问题描述

一天蒜头君得到 n 个字符串 si​,每个字符串的长度都不超过 10。

蒜头君在想,在这 n 个字符串中,以 si​ 为后缀的字符串有多少个呢?

输入格式

第一行输入一个整数 n。

接下来 n 行,每行输入一个字符串 si​。

输出格式

输出 n 个整数,第 i 个整数表示以 si​ 为后缀的字符串的个数。

数据范围

对于 50\%50% 的数据,1≤n≤10^3。

对于 100\%100% 的数据,1 ≤n≤10^5。

所有的字符串仅由小写字母组成。

样例输入

3
ba
a
aba

样例输出

2
3
1

题目来源

2019 蓝桥杯省赛 B 组模拟赛(一)

#include <bits/stdc++.h>
using namespace std;
string a[]; int main() {
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
int n;
map<string, int>mp;
cin >> n;
for (int i = ; i < n; i++)
{
cin >> a[i];
for (int j = ; j < a[i].size(); j++) {
mp[a[i].substr(j)]++;
}
}
for (int i = ; i < n; i++)
cout << mp[a[i]] << "\n";
return ;
}

计蒜客蓝桥杯模拟赛 后缀字符串:STL_map+贪心的相关教程结束。

《计蒜客蓝桥杯模拟赛 后缀字符串:STL_map+贪心.doc》

下载本文的Word格式文档,以方便收藏与打印。