UVa Problem 123 - Searching Quickly
// UVa Problem 123 - Searching Quickly
// Verdict: Accepted
// Submission Date: 2012-01-04
// UVa Run Time: 0.016s
//
// 版权所有(C)2012,邱秋。metaphysis # yeah dot net
//
// [解题方法]
// 简单的字符串处理和排序题。
//
// 提交时错误了一次,因为没有注意到需要忽略的关键词可能会重复给出的情况,修正后就 AC 了。
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
using namespace std;
struct title
{
string content;
string keyword;
int indexKeyword;
int indexInput;
};
string toLower(string s)
{
string r;
for (int i = 0; i < s.length(); i++)
r += (s[i] >= 'A' && s[i] <= 'Z' ? (s[i] + 32) : s[i]);
return r;
}
string toUpper(string s)
{
string r;
for (int i = 0; i < s.length(); i++)
r += (s[i] >= 'a' && s[i] <= 'z' ? (s[i] - 32) : s[i]);
return r;
}
bool cmp(title a, title b)
{
if (a.keyword == b.keyword)
{
if (toLower(a.content) == toLower(b.content))
return a.indexKeyword < b.indexKeyword;
else
return a.indexInput < b.indexInput;
}
return a.keyword < b.keyword;
}
int main (int argc, char const* argv[])
{
set < string > ignore;
vector < title > titles;
string line;
while (getline(cin, line))
{
if (line != "::")
{
// 可能会给出重复的关键词,需要消除。
if (ignore.find(line) == ignore.end())
ignore.insert(line);
}
else
{
int count = 0;
while (getline(cin, line))
{
string all = toLower(line);
int i = 0;
while (i < line.length())
{
if (line[i] == ' ')
i++;
else
{
// 将句子中出现的单词逐个分离出来。
int start = i;
string tmp;
while (i < line.length() && line[i] != ' ')
{
tmp += line[i];
i++;
}
int end = i;
// 若不是需要忽略的关键词,则生成一个标题。
tmp = toLower(tmp);
if (ignore.find(tmp) == ignore.end())
{
string keyword = toUpper(tmp);
string content = all.substr(0, start) + keyword + all.substr(end);
title t = (title) {content, keyword, start, count};
titles.push_back(t);
}
}
}
count++;
}
}
}
// 按指定规则排序。
sort(titles.begin(), titles.end(), cmp);
for (int i = 0; i < titles.size(); i++)
cout << titles[i].content << endl;
return 0;
}
UVa Problem 123 - Searching Quickly相关推荐
- STL --- UVA 123 Searching Quickly
UVA - 123 Searching Quickly Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...
- uva - 123 - Searching Quickly
题目大意: 输入一系列要被忽视的单词和题目,题目中除了要被忽视的单词外其他的都是关键字.把关键字忽略大小写按字典序排序.再把题目按照关键字的字典序输出.有几个关键字输出几次(看题目中样例).输出的时候 ...
- UVa Problem 109 - SCUD Busters
// UVa Problem 109 - SCUD Busters // Verdict: Accepted // Submission Date: 2011-11-24 // UVa Run Tim ...
- UVa Problem 10310 Dog and Gopher (狗拿地鼠)
// Dog and Gopher (狗拿地鼠) // PC/UVa IDs: 111301/10310, Popularity: A, Success rate: average Level: 1 ...
- UVa Problem 10001 Garden of Eden (伊甸园)
// Garden of Eden (伊甸园) // PC/UVa IDs: 110806/10001, Popularity: B, Success rate: average Level: 2 / ...
- UVa Problem 10041 Vito’s Family (Vito 家族)
// Vito's Family (Vito 家族) // PC/UVa IDs: 110401/10041, Popularity: A, Success rate: high Level: 1 / ...
- UVa Problem 10254 The Priest Mathematician (牧师数学家)
// The Priest Mathematician (牧师数学家) // PC/UVa IDs: 110606/10254, Popularity: C, Success rate: high L ...
- UVa Problem 10067 Playing With Wheels (摆弄轮子)
// Playing With Wheels (摆弄轮子) // PC/UVa IDs: 110902/10067, Popularity: C, Success rate: average Leve ...
- UVa Problem 10205 Stack ’em Up (完美洗牌术)
// Stack 'em Up (完美洗牌术) // PC/UVa IDs: 110205/10205, Popularity: B, Success rate: average Level: 1 / ...
最新文章
- 人工智能犯罪:先行预防还是事后严惩
- pip在windows下安装配件/宏包
- POJ 3635 Full Tank?
- Java Web系统经常使用的第三方接口
- springboot mail插件/JavaMailSenderImpl 发邮件。163网易企业邮箱调用的坑。
- 微信小程序 - 骨架屏
- iris数据集_sklearn日志(二)训练集和测试集划分
- jquery怎么创建一个img标签
- Spark 云计算 ML 机器学习教程 以及 SPARK使用教程
- 【R语言教程】不一样的零基础教程,数据分析到论文写作一站式完成
- java 使用response方式下载txt文件
- MacOS从清空的废纸篓找回被删除文件的方法
- 社区价值:福山论自组织、社区、社会资本
- 作业1:关于使用python中scikit-learn(sklearn)模块,实现鸢尾花(iris)相关数据操作(数据加载、标准化处理、构建聚类模型并训练、可视化、评价模型)
- oracle招聘ocp认证,OracleOCP认证要通过哪些考试?
- Python 多个视频拼接成一个视频工具(附代码) | Python工具
- c 语言一个参数是他所有结果的总和,C Primer Plus 第六章 复习题编程练习 答案...
- iphone 刷机遇到的一些名词解释
- HTTP各种请求方法的的幂等性和安全性
- idea中添加查看jdk版本路径