Bing It On Kattis
来源:互联网 发布:淘宝上从那里定制衣服 编辑:程序博客网 时间:2024/06/05 18:55
题目链接:https://vjudge.net/contest/173017#problem/I
题意:按顺序输入n个单词, 让你统计并输出该单词在输入之前以前缀的形式出现的次数。
思路:1)暴力求解
2)字典树(暂未学习)
暴力技巧:,用stl里面的map存<string, int>就好,string是每个单词的所有前缀
由于自己知识有限只能使用最简单的模拟,很容易超时,后来观察学长的代码,感受到了STL的巧妙(虽然我的思想也想到是这样做,但是由于自己经验欠缺无法实践)
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <cmath>#include <string>#include <set>#include <map>using namespace std;typedef long long LL;map<string, int> mp; //string中的内容作为判断的标准,int是对应数值int n;char str[40];int main(){ while (scanf("%d", &n)==1){ mp.clear(); char ch; for (int i=0; i<n; i++){ scanf("%s", str); for (int j=0; str[j]; j++){ //从i开始的原因是避免记录本身导致初始值为1 ch=str[j]; //记录当前字符 str[j]=0; //改变字符数组的结尾‘0’的位置 // printf("%s",str); mp[str]++; //添加记录所有前缀 str[j]=ch; //还原字符 } printf("%d\n", mp[str]); mp[str]++; } } return 0;}
阅读全文
0 0
- Bing It On Kattis
- Bing It On (Kattis
- Bing it
- Bing it UVALive
- UVALive 4764 Bing it
- Bing it UVALive
- Kattis
- Kattis
- Kattis
- (Kattis
- (Kattis
- (Kattis
- (Kattis
- Kattis
- Kattis
- Kattis
- Kattis
- Kattis
- 如何开发正确的、精致的、高效的程序
- 机器学习需了解“三大法宝”、、、
- 第二十二章 JAVA眼中的XML--文件写入
- hdu2433 最短路+思维
- HTML表单、HTTP Get与Post杂谈
- Bing It On Kattis
- java泛型通配符理解和使用
- 用opencv 训练cascade
- 5、利用MLP(多层感知器)创建一个新的OCR分级器;
- 部分的ul&jsp
- 编程的精进之法
- RTSP
- linux基本命令及操作4(vim,管道符,gedit)
- note2 原生数据类型