G. 程序设计:后缀字符串 题库链接

分值: 19

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

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

输入格式
第一行输入一个整数 n。

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

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

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

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

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

样例输入复制

3
ba
a
aba
样例输出复制

2
3
1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;

const int maxn = 1e5+5;

string a[maxn];

int main(){
	map<string,int>mp;
	int n;
	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)]++;
		}
	}
	for(int i=0;i<n;i++){
		cout<<mp[a[i]]<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值