码迷,mamicode.com
首页 > 其他好文 > 详细

后缀字符串

时间:2020-04-16 22:32:59      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:out   stream   substr   bottom   多少   stdin   algo   cst   size   

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

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

输入格式

第一行输入一个整数 n。

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

输出格式

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

数据范围

对于 50% 的数据, 1n1e3。

对于 100% 的数据,1n1e5。

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

样例输入

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;
}

 

后缀字符串

标签:out   stream   substr   bottom   多少   stdin   algo   cst   size   

原文地址:https://www.cnblogs.com/xcfxcf/p/12715988.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!