STL --- UVA 123 Searching Quickly
UVA - 123 Searching Quickly
Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19296
Mean:
有一个字符串集合Ignore,还有一个文本集合TXT,在TXT中除了Ignore中的单词外其他的都是关键字,现在要你根据这些关键字来给TXT文本排序(根据关键字的字典)。
注意:一行TXT文本中含多少个关键字就需要排多少次序,如果关键字的字典序相同则按照先后顺序来排。
analyse:
这题STL用的比较多,使用STL可以很好的解决去重、排序等一序列问题,而手动实现的话就稍微繁琐一点,思路并不难。
Time complexity: O(n)
Source code:
1. STL版:
/*
* this code is made by crazyacking
* Problem: UVA 123
* Verdict: Accepted
* Submission Date: 2015-05-03-20.39
* Time: 0MS
* Memory: 0KB
*/
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <cstdlib>
#include <climits>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAXN 1000010
#define LL long long
#define ULL unsigned long long
using namespace std; string tmp;
set<string> ignore;
multimap<string,string> mp; int main()
{
// freopen("C:\\Users\\crazyacking\\Desktop\\cin.txt","r",stdin);
// freopen("C:\\Users\\crazyacking\\Desktop\\cout.txt","w",stdout); ios_base::sync_with_stdio(false);
cin.tie();
int len;
string ig;
while(getline(cin,ig) && ig!="::")
ignore.insert(ig);
mp.clear();
while(getline(cin,tmp))
{
len=tmp.length();
for(int i=;i<len;++i)
tmp[i]=tolower(tmp[i]);
string t1;
int cnt;
for(int i=;i<len;++i)
{
if(tmp[i]!=' ')
{
cnt=;
int j;
t1.clear();
for(j=i;j<len;++j)
{
if(tmp[j]!=' ')
{
t1.insert(cnt,,tmp[j]);
cnt++;
tmp[j]=toupper(tmp[j]);
}
else break;
}
i=j;
if(ignore.find(t1)==ignore.end())
mp.insert(pair<string,string>(t1,tmp));
for(j=;j<len;++j)
{
tmp[j]=tolower(tmp[j]);
}
}
}
}
multimap<string,string> ::iterator iter=mp.begin();
for(;iter!=mp.end();++iter)
{
cout<<(iter->second)<<endl;
}
return ;
}
/* */
2.手动模拟:
/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-05-03-21.52
* Time: 0MS
* Memory: 1347KB
*/
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <cstdlib>
#include <climits>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAXN 1000010
#define LL long long
using namespace std; struct node
{
int n;
char word[][];
void fun(char *str)
{
int len=strlen(str);
for(int i=;i<len;i++) str[i]=tolower(str[i]); n=;
char *strPtr=strtok(str," ");
while(strPtr!=NULL)
{
strcpy(word[n++],strPtr);
strPtr=strtok(NULL," ");
}
}
}title[];
void output(int t,int pos)
{
int len=strlen(title[t].word[pos]);
for(int i=;i<len;i++)
{
title[t].word[pos][i]=toupper(title[t].word[pos][i]);
}
for(int i=;i<title[t].n;i++)
{
if(i==)
{
printf("%s",title[t].word[i]);
}
else printf(" %s",title[t].word[i]);
}
for(int i=;i<len;i++)
{
title[t].word[pos][i]=tolower(title[t].word[pos][i]);
}
puts("");
} int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
int n=;
set<string> ig,key;
set<string>::iterator it;
char temp[],str[];
while(scanf("%s",temp)!=EOF)
{
if(strcmp(temp,"::")==) break;
ig.insert(temp);
}
while(gets(str))
{
title[n].fun(str);
for(int i=;i<title[n].n;i++)
{
bool flag=false;
for(it=ig.begin();it!=ig.end();it++)
{
if(strcmp(title[n].word[i],(*it).c_str())==)
{
flag=true;break;
}
}
if(!flag) key.insert(title[n].word[i]);
}
n++;
}
for(it=key.begin();it!=key.end();it++)
{
for(int i=;i<n;i++)
{
for(int j=;j<title[i].n;j++)
{
if(strcmp((*it).c_str(),title[i].word[j])==)
{
output(i,j);
}
}
}
}
return ;
}
/* */
STL --- UVA 123 Searching Quickly的更多相关文章
- uva 123 Searching Quickly
Searching Quickly Background Searching and sorting are part of the theory and practice of computer ...
- Brute Force & STL --- UVA 146 ID Codes
ID Codes Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&a ...
- STL UVA 11995 I Can Guess the Data Structure!
题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...
- UVa 12505 Searching in sqrt(n)
传送门 一开始在vjudge上看到这题时,标的来源是CSU 1120,第八届湖南省赛D题“平方根大搜索”.今天交题时CSU突然跪了,后来查了一下看哪家OJ还挂了这道题,竟然发现这题是出自UVA的,而且 ...
- uva 1597 Searching the Web
The word "search engine" may not be strange to you. Generally speaking, a search engine se ...
- 湖南省第八届大学生程序设计大赛原题 D - 平方根大搜索 UVA 12505 - Searching in sqrt(n)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30746#problem/D D - 平方根大搜索 UVA12505 - Searchin ...
- STL UVA 11991 Easy Problem from Rujia Liu?
题目传送门 题意:训练指南P187 分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以) map #include <bits/stdc++.h> u ...
- UVa123 - Searching Quickly
题目地址:点击打开链接 C++代码: #include <iostream> #include <set> #include <map> #include < ...
- [STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary
1.set 集合 哦....对了,set有自动按照字典序排序功能..... 声明和插入操作 #include <cstdio> #include <vector> #inclu ...
随机推荐
- [Aaronyang] 写给自己的WPF4.5 笔记20 [3d课 1/4]
假设你是高中毕业的,ok,数学知识几何知识中,我们学过 x,y,z 3个轴然后就可以画出形状了. 1. 新建空白窗体,grid换成canvas,然后新增一个Viewport3D元素 3d中显示的 ...
- Android酷炫实用的开源框架——UI框架(转)
转载别人整理好的文章,列出了很多炫酷的UI开源设计 原文地址:http://www.androidchina.net/1992.html 1.Side-Menu.Android分类侧滑菜单,Yalan ...
- SSIS连接Oracle遇到的问题
Fuck!一大早上来到办公室发现 E盘被客户无缘无故干掉了,心中一万只......路过,but 接下来还是要解决问题 冷静!冷静!冷静! 问题还是要解决的 于是乎去测试开发环境 发现DW库和Repo ...
- quick -- 创建精灵和动作
local imgBg = display.newSprite("666666.jpg") :pos(display.cx, display.cy) :addTo(self) , ...
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler” http:// ...
- SQL语句删除所有表
) ) ) ) ) ) ) ) ) TABLE_NAME CONSTRAINT_NAME CONSTRAINT_NAME TABLE_NAME ) ) ) TABLE ...
- Intellij idea 乱码问题(英文操作系统)
英文操作系统导致 Debug 下的变量查看时显示乱码,可通过改变字体解决此问题.
- 《objective-c基础教程》学习笔记(八)—— 拆分接口和实现
在之前的项目中,我们编程都是直接写在一个main.m文件中.类的main()函数,@interface和@implementation部分都塞进一个文件.这种结构对于小程序和简便应用来说还可以.但是项 ...
- 【Cocos2d-Js基础教学 入门目录】
本教程视地址频在: 九秒课堂 完全免费 从接触Cocos2dx-Js以来,它的绽放的绚丽让我无法不对它喜欢.我觉得Js在不断带给我们惊喜:在开发过程中,会大大提升我们对原型开发的利用率,使用Js语言做 ...
- centos中 mysql 5.7安装
以免授权模式启动 编辑 /etc/my.cnf,添加以下内容: linux环境中:vi /etc/my.cnf 在[MySQL(和PHP搭配之最佳组合)d]配置段添加如下两行: user=mysql ...