// 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相关推荐

  1. STL --- UVA 123 Searching Quickly

    UVA - 123 Searching Quickly Problem's Link:   http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...

  2. uva - 123 - Searching Quickly

    题目大意: 输入一系列要被忽视的单词和题目,题目中除了要被忽视的单词外其他的都是关键字.把关键字忽略大小写按字典序排序.再把题目按照关键字的字典序输出.有几个关键字输出几次(看题目中样例).输出的时候 ...

  3. UVa Problem 109 - SCUD Busters

    // UVa Problem 109 - SCUD Busters // Verdict: Accepted // Submission Date: 2011-11-24 // UVa Run Tim ...

  4. UVa Problem 10310 Dog and Gopher (狗拿地鼠)

    // Dog and Gopher (狗拿地鼠) // PC/UVa IDs: 111301/10310, Popularity: A, Success rate: average Level: 1 ...

  5. UVa Problem 10001 Garden of Eden (伊甸园)

    // Garden of Eden (伊甸园) // PC/UVa IDs: 110806/10001, Popularity: B, Success rate: average Level: 2 / ...

  6. UVa Problem 10041 Vito’s Family (Vito 家族)

    // Vito's Family (Vito 家族) // PC/UVa IDs: 110401/10041, Popularity: A, Success rate: high Level: 1 / ...

  7. UVa Problem 10254 The Priest Mathematician (牧师数学家)

    // The Priest Mathematician (牧师数学家) // PC/UVa IDs: 110606/10254, Popularity: C, Success rate: high L ...

  8. UVa Problem 10067 Playing With Wheels (摆弄轮子)

    // Playing With Wheels (摆弄轮子) // PC/UVa IDs: 110902/10067, Popularity: C, Success rate: average Leve ...

  9. UVa Problem 10205 Stack ’em Up (完美洗牌术)

    // Stack 'em Up (完美洗牌术) // PC/UVa IDs: 110205/10205, Popularity: B, Success rate: average Level: 1 / ...

最新文章

  1. 人工智能犯罪:先行预防还是事后严惩
  2. pip在windows下安装配件/宏包
  3. POJ 3635 Full Tank?
  4. Java Web系统经常使用的第三方接口
  5. springboot mail插件/JavaMailSenderImpl 发邮件。163网易企业邮箱调用的坑。
  6. 微信小程序 - 骨架屏
  7. iris数据集_sklearn日志(二)训练集和测试集划分
  8. jquery怎么创建一个img标签
  9. Spark 云计算 ML 机器学习教程 以及 SPARK使用教程
  10. 【R语言教程】不一样的零基础教程,数据分析到论文写作一站式完成
  11. java 使用response方式下载txt文件
  12. MacOS从清空的废纸篓找回被删除文件的方法
  13. 社区价值:福山论自组织、社区、社会资本
  14. 作业1:关于使用python中scikit-learn(sklearn)模块,实现鸢尾花(iris)相关数据操作(数据加载、标准化处理、构建聚类模型并训练、可视化、评价模型)
  15. oracle招聘ocp认证,OracleOCP认证要通过哪些考试?
  16. Python 多个视频拼接成一个视频工具(附代码) | Python工具
  17. c 语言一个参数是他所有结果的总和,C Primer Plus 第六章 复习题编程练习 答案...
  18. iphone 刷机遇到的一些名词解释
  19. HTTP各种请求方法的的幂等性和安全性
  20. idea中添加查看jdk版本路径

热门文章

  1. 记忆化搜索 (蒟蒻练习生)
  2. videopose3d 用自己的视频跑结果
  3. SQL语句模糊查询 JavaWeb 项目 dao层 【常用来做搜索框】
  4. Python作为移动客户端后台服务器
  5. SolrCloud 的搭建、使用
  6. 【LINUX】系统安全
  7. 如何快速查询学术会议
  8. 解决一个JAVA小问题
  9. 华擎计算机主板型号,华擎科技 新闻中心
  10. execute与executeUpdate的区别(学习笔记)