计算机学院大学生程序设计竞赛(2015’12)Study Words
Study Words
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 195 Accepted Submission(s): 66
One day an idea came up to me: I download an article every day, choose the 10 most popular new words to study.
A word's popularity is calculated by the number of its occurrences.
Sometimes two or more words have the same occurrences, and then the word with a smaller lexicographic has a higher popularity.
Each case has two parts.
<oldwords>
...
</oldwords>
<article>
...
</article>
Between <oldwords> and </oldwords> are some old words (no more than 10000) I have already learned, that is, I don't need to learn them any more.
Words between <oldwords> and </oldwords> contain letters ('a'~'z','A'~'Z') only, separated by blank characters (' ','\n' or '\t').
Between <article> and </article> is an article (contains fewer than 1000000 characters).
Only continuous letters ('a'~'z','A'~'Z') make up a word. Thus words like "don't" are regarded as two words "don" and "t”, that's OK.
Treat the uppercase as lowercase, so "Thanks" equals to "thanks". No words will be longer than 100.
As the article is downloaded from the internet, it may contain some Chinese words, which I don't need to study.
If there are fewer than 10 new words, output all of them.
Output a blank line after each case.
2
<oldwords>
how aRe you
</oldwords>
<article>
--How old are you?
--Twenty.
</article>
<oldwords>
google cn huluobo net i
</oldwords>
<article>
文章内容:
I love google,dropbox,firefox very much.
Everyday I open my computer , open firefox , and enjoy surfing on the inter-
net.
But these days it's strange that searching "huluobo" is unavail-
able.
What's wrong with "huluobo"?
</article>
old
twenty firefox
open
s
able
and
but
computer
days
dropbox
enjoy
今天是2015年最后一个星期日,我用了好长好长好长时间做了这道题,测试答案不应该错,可是.........
好伤心、
不想再修改了。。。。就让它一直错吧!
下面的是正确的答案哦!
#include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int T;
char s[100+10];
char r[100+10];
map<string,int>m;
struct dan
{
char s[100+10];
int num;
}d[1000000+10];
int sum;
int tot;
bool cmp(const dan&a,const dan&b)
{
if(a.num==b.num) return strcmp(a.s,b.s)<0;
return a.num>b.num;
} //转小写
void F()
{
for(int i=0;s[i];i++)
if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]-'A'+'a';
}
void work()
{
int len=strlen(s);
tot=0;
for(int i=0;i<=len;i++)
{
if(s[i]>='a'&&s[i]<='z') r[tot++]=s[i];
else
{
r[tot]='\0';
if(strlen(r)>0) m[r]=-1;
tot=0;
}
}
}
void work2()
{
int len=strlen(s);
tot=0;
for(int i=0;i<=len;i++)
{
if(s[i]>='a'&&s[i]<='z') r[tot++]=s[i];
else
{
r[tot]='\0';
if(strlen(r)>0)
{
if(m[r]!=-1)
{
if(m[r]==0) strcpy(d[sum++].s,r);
m[r]++;
}
}
tot=0;
}
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
int flag=0;
m.clear();
sum=0;
while(1)
{
scanf("%s",s);
if(strcmp(s,"<oldwords>")==0) {flag=1;continue;}
if(strcmp(s,"</oldwords>")==0) {flag=2;continue;}
if(strcmp(s,"<article>")==0) {flag=3;continue;}
if(strcmp(s,"</article>")==0) break;
if(flag==1)
{
F();
work();
}
if(flag==3)
{
F();
work2();
}
}
for(int i=0;i<sum;i++) d[i].num=m[d[i].s];
sort(d,d+sum,cmp);
for(int i=0;i<min(10,sum);i++) printf("%s\n",d[i].s);
printf("\n");
}
return 0;
}
@执念 "@☆但求“❤”安★下次我们做的一定会更好。。。。
为什么这次的题目是英文的。。。。QAQ...
计算机学院大学生程序设计竞赛(2015’12)Study Words的更多相关文章
- hdu 计算机学院大学生程序设计竞赛(2015’11)
搬砖 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...
- 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排
1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words
#include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
Polygon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
The Country List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...
- 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle
#include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...
- 计算机学院大学生程序设计竞赛(2015’12) 1004 Happy Value
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...
随机推荐
- HDU 4803 Poor Warehouse Keeper (贪心+避开精度)
555555,能避开精度还是避开精度吧,,,,我们是弱菜.. Poor Warehouse Keeper Time Limit: 2000/1000 MS (Java/Others) Memor ...
- css3 nth-child 与 nth-of-type 的区别
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1709 一.深呼吸,直 ...
- MVC模式(三层架构模式)
(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller). MVC模式最早由Try ...
- IOC基本理解
什么是IOC? IOC全称为控制反转(Inversion Of Control),别名依赖注入(Dependency Injection). 控制反转即指我们获取依赖的方式发生了反转. 假设存在如下情 ...
- JavaScript插件
Spket ide Spket ide是强大的工具包为了JavaScript和XML的开发,这个强大的编辑器对JavaScript, XUL/XBLand Yahoo! Widget的开发都有全面的支 ...
- seo优化入门教程:认识搜索引擎
对于从来没有学过seo或者零基础的人来说,搜索引擎可能都不太了解.所以我们先来认识搜索引擎有哪些,同时为什么我们要学习搜索引擎优化. 从目前全球的一个搜索引擎来说的话,他的分支是非常多的,甚至可以讲, ...
- VC/MFC中计算程序运行时间
转自原文VC/MFC中计算程序运行时间 说明,这四种方法也分别代表了类似的实现,在MFC中,所可以从哪些类集合去考虑. 方法一 利用GetTickCount函数(ms) CString str; lo ...
- JS实现根据密码长度 显示安全条
原文:http://www.open-open.com/code/view/1431324883763 //根据密码长度显示安全条 <ul class="clear"> ...
- nc和telnet配合使用
nc -l 9932 -c 用nc监听9932端口 telnet 180.150.184.115 29933 telnet 29932 端口
- 服务器----1U、2U、3U、4U
U是一种表示服务器外部尺寸的单位,是unit的缩略语,详细的尺寸由作为业界团体的美国电子工业协会(EIA)所决定. 之所以要规定服务器的尺寸,是为了使服务器保持适当的尺寸以便放在铁质或铝质的机架上.机 ...