计算机学院大学生程序设计竞赛(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 ...
随机推荐
- ndarray:一种多维数组对象
ndarray是一个通用的同构数据多维容器,也就是说,其中的所有元素必须是相同类型的.每个数组都有一个shape(一个表示各维度大小的元组)和一个dtype(一个用于说明数组数据类型的对象). In ...
- uva 11991 查询中容器的运用
题目大意:一个n个整数的数组,m条查询指令.(1<=n,m<=100 000)每次询问第k个整数v的下标值,若不存在输出0. #include<iostream> #inclu ...
- MongoDB_副本集集群模式
主从模式: 在10.3.13.213 主节点, 10.3.2.33 从节点.mongodb 安装路径均为:/usr/local/server/mongodb 参考文章:http://www.lance ...
- ctrl+c,ctrl+d,ctrl+z在linux程序中意义和区别
原文: http://blog.csdn.net/sxhlovehmm/article/details/41318111 [侵删] ctrl+c和ctrl+z都是中断命令,但是他们的作用却不一样. ...
- vcenter api 接口获取开发
通过连接vcenter 管理服务器,获取其下所有的:存储,网络,ESXI实体机,虚拟机相关信息的脚步: #!/opt/python3/bin/python3 #Author: zhaoyong &qu ...
- 心脏滴血漏洞复现(CVE-2014-0160)
漏洞范围: OpenSSL 1.0.1版本 漏洞成因: Heartbleed漏洞是由于未能在memcpy()调用受害用户输入内容作为长度参数之前正确进 行边界检查.攻击者可以追踪OpenSSL所分配的 ...
- Liunx常用命令(备用)
常用指令 ls 显示文件或目录 -l 列出文件详细信息l(list) -a 列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir ...
- ElasticSearch生产模式开发模式的区分
ElasticSearch生产模式开发模式的区分 network.host: 0.0.0.0 如果network.host不是localhost就是生产模式, 开发模式中的warning就是生产模式中 ...
- c程序设计语言第一章2
练习1.13编写一个程序,打印输入中单词长度的直方图.水平方向的直方图比较容易绘制,垂直方向的直方图则要困难些 #include <stdio.h> #include <stdlib ...
- 在运行hadoop是出现Master的9000端口拒绝访问的情况
出现9000端口拒绝访问的情况有可能是防火墙没有开放9000端口,可以选择关闭防火墙或者卸载防火墙,如果还是无法解决这种情况可能是因为hadoop的启动顺序不对. 应该按照如下得顺序启动 Step2: ...