计蒜客 11066 A letter from Chensg
来源:互联网 发布:mac 照片所在文件夹 编辑:程序博客网 时间:2024/04/26 01:38
Description
m个字符串,求最长连续子串
Algorithm
每个串,求每个子串
用set 和 map 存起
set是用了判重的,防止每个串里有重复的
map是全局的
然后就A了
STL大法好
Code
#include <cstdio>#include <string>#include <iostream>#include <map>#include <set>using namespace std;void solve(){ map<string, int> mymap; int m; scanf("%d\n", &m); for (int i = 0; i < m; i++) { set<string> myset; string s; getline(cin, s); for (int j = 0; j < s.size() - 3; j++) { for (int k = 3; k < s.size() - j; k++) { string str = s.substr(j, k); if (myset.find(str) == myset.end()) { mymap[str]++; myset.insert(str); } } } } string ans; for (map<string, int>::iterator it = mymap.begin(); it != mymap.end(); it++) { if (it->second == m) { if ((it->first).size() > ans.size()) { ans = it->first; continue; } if ((it->first).size() == ans.size() && (it->first < ans)) { ans = it->first; } } } if (ans == "") ans = "No significant commonalities"; cout << ans << endl;}int main(){// freopen("input.txt", "r", stdin); int n; scanf("%d\n", &n); for (int i = 0; i < n; i++) solve();}
0 0
- 计蒜客 11066 A letter from Chensg
- 北京林业大学“计蒜客”杯程序设计竞赛 D. A letter from Chensg
- 北京林业大学“计蒜客”杯程序设计竞赛 网络赛 D-A letter from Chensg【最长公共子序列LCS】
- a letter from bill gates
- A letter from my friend
- Dear Steve Jobs: A Letter From a Mother
- A. Letter
- A. Letter
- letter from jjhou
- Farewell letter from Edward
- A letter from Seals to human海豹寄給人类的一封信
- LeetCode 17.Letter Combinations of a Phone Number & 19.Remove Nth Node From End of List
- Memo for a letter
- A Dear John Letter
- A Letter for Help
- A Love Letter
- A Love Letter
- A Love Letter
- C++ new分配失败运行机制
- Java读取properties文件
- mysql隔离级别理解
- 关于Spring中的<context:annotation-config/>配置
- UVA_11137_Ingenuous Cubrency
- 计蒜客 11066 A letter from Chensg
- popupwindow 显示和消失的动画
- java对象排序
- 非计算机科班出身,如何成为一名技术牛人?
- Lua核心编程之进阶&总结
- ActionBar的使用
- Aspose.words合并文档、邮件合并功能
- 面试:数组:合并区间:058
- zcmu1727