计算机学院大学生程序设计竞赛(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 ...
随机推荐
- R语言入门视频笔记--2--一些简单的命令
一.对象 1.列举当前内存中的对象 ls() 2.删除不需要的对象 rm(某对象名称) 3.查看向量长度 length(某向量名称) 4.查看向量类型 mode(某向量名称) 二.函数 1.seq函数 ...
- 漫话最小割 part1
codeforces 724D [n个城市每个城市有一个特产的产出,一个特产的最大需求.当i<j时,城市i可以运最多C个特产到j.求所有城市可以满足最大的需求和] [如果直接最大流建图显然会T. ...
- T1079 回家 codevs
http://codevs.cn/problem/1079/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver~死坑 题目描述 Description 现在是晚 ...
- noip2013华容道
题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...
- Hadoop三种模的安装配置过程
JDK+Hadoop安装配置.单机模式配置 以下操作在SecureCRT里面完成 1.关闭防火墙 firewall-cmd --state 显示防火墙状态running/not running sys ...
- MySQL 5.6.20-4 and Oracle Linux DTrace
https://blogs.oracle.com/wim/entry/mysql_5_6_20_4?utm_source=tuicool&utm_medium=referral By WimC ...
- ubutu强制结束进程 kill -9 ProcessID
强制终止进程 kill -9 2128 表示强制结束进程号 2128 对应的进程.
- 递归获取JSON内容的key-value值
方法主体: 使用时,请在类中先声明一个Map,參数形式例如以下: JSONObject jobj = new JSONObject(JSONContent); 首次请传递jobj.
- Effective C++ 条款六 若不想使用编译器自动生成的函数,就该明确拒绝
class HomeForSale //防止别人拷贝方法一:将相应的成员函数声明为private并且不予实现 { public: private: HomeForSale(const HomeForS ...
- Json——使用Json jar包实现Json字符串与Java对象或集合之间的互相转换
总结一下利用Json相关jar包实现Java对象和集合与Json字符串之间的互相转换: 1.创建的User类: package com.ghj.packageofdomain; public clas ...