XiaoHuang's Space
XiaoHuang's Space
XiaoHuang
May the force be with you.
『题解』BZOJ3172 [TJOI2013]单词
Posted: Dec 11, 2019
Last Modified: Dec 13, 2019
This article was last modified days ago. The content of this post may be outdated!

Portal

Portal1:BZOJ

Portal2:Luogu

Description

某人读论文,一篇论文是由许多单词组成。但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次。

Input

第一个整数$n$,表示有多少个单词,接下来$n$行每行一个单词。每个单词由小写字母组成,$n \leq 200$,单词长度不超过$10^{6}$。

Output

输出$n$个整数,第$i$行的数字表示第$i$个单词在文章中出现了多少次。

Sample Input

3
a
aa
aaa

Sample Output

6
3
1

Solution

暴力出奇迹!

Code

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>

using namespace std;

const int MAXN=205;
int n;
string st[MAXN];
int main() {
    scanf("%d",&n);
    for (int i=1; i<=n; i++)
        cin >> st[i];
    for (int i=1; i<=n; i++) {
        int ans=0;
        for (int j=1; j<=n; j++)
            if (j!=i) {//每次都暴力找一遍
                int last=0, k=st[j].find(st[i], last);
                while (~k) {
                    last=k+1;
                    k=st[j].find(st[i], last);
                    ans++;
                }
            }
        printf("%d\n",++ans);//要加上自己的那个
    }
    return 0;
}

Attachment

测试数据下载:https://www.lanzous.com/i3jv07a

Article License: CC BY-NC-ND 4.0
Article Author: XiaoHuang
  1. 1. Portal
  2. 2. Description
  3. 3. Input
  4. 4. Output
  5. 5. Sample Input
  6. 6. Sample Output
  7. 7. Solution
  8. 8. Code
  9. 9. Attachment
Newer Post
『题解』Codeforces2A Winner
Older Post
『题解』Coderforces142B Help General
Buy me a beer?
-->
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×