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 ...
随机推荐
- OpenStack云计算(二)——OpenStack 计算
http://www.ibm.com/developerworks/cn/cloud/library/cl-openstack-nova-glance/
- EF Repository Update
问题描述: 解决办法: http://www.cnblogs.com/scy251147/p/3688844.html 原理: Attaching an entity of type '' faile ...
- 智能电表IEEE754 32位浮点格式
实例1 实例二
- win10初体验,我的错误代码哪里去了
今天闲着,就把WIN7升级安装成WIN10,感觉这次WIN10的升级方案确实还可以人,可以保留文件和配置升级. 升级完,试了一下宽带连接,发现错误代码没了,像下面的应该就691呢~~~
- C# 選擇本機檔案並上傳
參考自:http://www.dotblogs.com.tw/puma/archive/2008/11/07/5910.aspxhttp://www.codeproject.com/Articles/ ...
- BusyBox
http://blog.csdn.net/a345017062/article/details/6250619
- 提高FOR插入数据库动作的优化代码
await Task.Factory.StartNew(() => Parallel.ForEach(result.data.o, s => { sql = "insert in ...
- mshadow笔记
矩阵维度表示和正常相反. a[2][3],行2列3,a.shape.shape_[0]=3,a.shape.shape_[1]=2. pred.Resize( Shape2( batch_size, ...
- hao.360.cn不停跳....
最近单位里访问hao.360.cn经常会跳....无限循环,有时跳几十次后才会打开.... 但是,单位里走电信出口部分的电脑就没有问题...同样的电脑(移动出口)的用360浏览器.火狐也问题不大,关键 ...
- apache下virtualhost与location合用配置转发SVN控制访问
使用apache的文件系统配置 使用virtualhost 实现location 重定向 NameVirtualHost *:80 <VirtualHost *:80> ServerNam ...