一天蒜头君得到 n 个字符串 si,每个字符串的长度都不超过 10。
蒜头君在想,在这 n 个字符串中,以 si 为后缀的字符串有多少个呢?
输入格式
第一行输入一个整数 n。
接下来 n 行,每行输入一个字符串 si。
输出格式
输出 n 个整数,第 ii 个整数表示以 si 为后缀的字符串的个数。
数据范围
对于 50% 的数据, 1≤n≤1e3。
对于 100% 的数据,1≤n≤1e5。
所有的字符串仅由小写字母组成。
样例输入
3 ba a aba
样例输出
2 3 1
#include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <cstdio> #include <map> using namespace std; const int maxn = 1e5 + 10; int n; string a[maxn]; map<string, int>mp; int main() { //freopen("in","r",stdin); ios::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++){ cin >> a[i]; for (int j = 0; j < a[i].size(); j++) { mp[a[i].substr(j)]++; //cout << a[i].substr(j) << " "; } } for (int i = 0; i < n; i++) cout << mp[a[i]] << endl; return 0; }