题意:

给定一篇文章, 文章中有段落, 段落中有句子。 句子只会以'!' , '.' , '?' 结尾, 求出每段中含有与他下面同样是该段落中相同单词数最多的句子, 注意, 单词忽略大小写, 重复的单词只算一个。

题目中关键段:

A topic sentence for a paragraph is the single sentence in the paragraph that best describes the paragraph’s content. For our purposes, we will select the earliest sentence in the paragraph that maximizes the number of distinct words in S that also occur in any following sentence within the same paragraph.

分析:

英文模拟题需要多读几次题目才能明白意思, 段中下面(following)的句子就是, 如果一段有四句, 1 要和 234比, 2 和 34比, 3和4比,不可能是最后一句。

然后我们用先把每篇文章记录下来, 用一个string将多行转化为一行, 因为gets没有读入回车, 所以要添加回车, 然后再分开每个段落处理就好,

每个段落我们如果要处理句子只要3个数据, 句子的头,尾,不同的(distinct)单词数

句子头尾的话我们用一个2个变量在string里面找就行, 然后set<string>记录下每个句子不同的单词数。

然后比较输出即可。

 #include <bits/stdc++.h>
using namespace std;
char a[][];
bool para(int st, int ed){
string s;
set<string> dic;
for(int i = st; i < ed; i++){//将很多行的段落 转换为只有一行的string
s += a[i], s += '\n';
}
int len = s.size();
vector<int> sen_be; //标记句子开头
vector<int> sen_ed; //句子结尾
vector<set<string> > sen_word;// 每个句子的distinct单词
int k = , l = ;
//闭区间[k,l] 为句子
int once = , t = ;
for(;;){ while(s[k] == ' ' || s[k] == '\n') {
k++;
if(k >= len) break;
}
if(k >= len) break;
while(s[l] != '?' && s[l] != '!' && s[l] != '.'){
l++;
if(l >= len) break;
}
if(l >= len) break;
sen_be.push_back(k);
sen_ed.push_back(l);
l++;
k = l;
} /*-----------下面处理这段中所有的句子-----------*/ int n_sen = sen_be.size();
if(n_sen < ){
return false;
}
for(int i = ; i < n_sen; i++){
int k1, l1;
k1 = sen_be[i], l1 = sen_ed[i];
string temp = s.substr(k1,l1-k1);
set<string> temp1;
stringstream ss(temp);
string temp_word;
while(ss >> temp_word){
string word = "";
for(int i = ; i < temp_word.size(); i++){
if(isalnum(temp_word[i]))
word += tolower(temp_word[i]);
}
temp1.insert(word);
}
sen_word.push_back(temp1);
}
int mcnt = , k2 = sen_be[], l2 = sen_ed[];
for(int i = ; i < n_sen; i++){
int cnt = ;
for(set<string> :: iterator it = sen_word[i].begin(); it != sen_word[i].end(); it ++){
for(int j = i + ; j < n_sen; j++){
if(sen_word[j].count(*it)){
cnt++;
break;
}
}
}
if(cnt > mcnt){
mcnt = cnt;
k2 = sen_be[i];
l2 = sen_ed[i];
}
} for(int i = k2; i <= l2; i++){
putchar(s[i]);
}
printf("\n");
return true;
}
void art(int n){
int last = ;
bool flag = false; //标记是否所有段落都小于3个句子, 如果是要输出空行
for(int i = ; i < n; i++){
if(a[i][] == ){
if(para(last,i))
flag = true;
last = i + ;
}
}
if(last != n)
if(para(last, n))
flag = true;
if(!flag) printf("\n");
puts("======");
}
int main(){
int line = ;
while(gets(a[line])){//gets是不会读入回车符的, 但fgets会
if(strcmp(a[line],"***") == ){ // article
art(line);
line = ;//每读完一篇文章就让line 归0
}
else if(strcmp(a[line], "******") == ){
art(line);
break;
}
else line++;
}
}

UvaLive 4917 Abstract Extract (模拟)的更多相关文章

  1. UVALive - 6269 Digital Clock 模拟

    UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...

  2. UVALive - 7139(差分+模拟)

    题目链接 参考 题意 N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 分析 由于车的起点和终点都为左上角,且每个格子里的人永远面对着车, ...

  3. UVALive 7464 Robots(模拟)

    7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...

  4. 【Bit String Reordering UVALive - 6832 】【模拟】

    题意分析 题目讲的主要是给你一个01串,然后给你要变成的01串格式,问你要转换成这一格式最少需要移动的步数. 题目不难,但当时并没有AC,3个小时的个人赛1道没AC,归根到底是没有逼自己去想,又想的太 ...

  5. 【Miscalculation UVALive - 6833 】【模拟】

    题目分析 题目讲的是给你一个串,里面是加法.乘法混合运算(个人赛中误看成是加减乘除混合运算),有两种算法,一种是乘法优先运算,另一种是依次从左向右运算(不管它是否乘在前还是加在前). 个人赛中试着模拟 ...

  6. UVaLive 6809 Spokes Wheel (模拟)

    题意:给定两个16进制数,问你把它转成二进制后,把第一个向左或者向右旋转最少的次数同,使得第一个变成第二个. 析:也是比较水的,按照要求做就好,注意0的情况,可能会忘记. #pragma commen ...

  7. UVALive 6858 Frame (模拟)

    Frame 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/D Description http://7xjob4.com1.z0 ...

  8. Mockito 中文文档 ( 2.0.26 beta )

    Mockito 中文文档 ( 2.0.26 beta ) 由于缺乏校对,难免有谬误之处,如果发现任何语句不通顺.翻译错误,都可以在github中的项目提出issue.谢谢~ Mockito框架官方地址 ...

  9. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

随机推荐

  1. 组合数学练习题(二)——Chemist

    题意: 在一个 n 维无限空间中,一开始原点处有一个细胞.细胞每秒都会增殖,每个原有细胞都会消亡,在与它曼哈顿距离恰为 1的所有位置都会新增一个细胞.求 T 秒后,原点处会有多少细胞,答案 mod10 ...

  2. [Usaco2017 Open]Modern Art 2

    Description Having become bored with standard 2-dimensional artwork (and also frustrated at others c ...

  3. taskkill帮助信息

    taskkill帮助信息: C:\Users\xusweeter>taskkill /? TASKKILL [/S system [/U username [/P [password]]]] { ...

  4. Java中的流(1)流简介

    简介 1.在java中stream代表一种数据流(源),java.io的底层数据元.(比作成水管)2.InputStream 比作进水管,水从里面流向你,你要接收,read3.OutputStream ...

  5. Python的数据类型:list和tuple

    今天开始认真的学习python. 1.list类型 list是python的一种数据类型,它是一种有序列表,可以随时添加和删除其中的元素. 1.1 list类型的特征 list类型内的成员类型可以相同 ...

  6. [转]Monkey测试简介

    转自:http://www.cnblogs.com/manuosex/p/3215270.html 在android手机上做自动化测试,monkey比cts,Android UnitTest 好用多了 ...

  7. apache-storm-1.0.2.tar.gz的集群搭建(3节点)(图文详解)(非HA和HA)

    不多说,直接上干货! Storm的版本选取 我这里,是选用apache-storm-1.0.2.tar.gz apache-storm-0.9.6.tar.gz的集群搭建(3节点)(图文详解) 为什么 ...

  8. 自定义Image HtmlHelper

    public static void Image(this HtmlHelper helper, string src, string alt = null, object htmlAttribute ...

  9. (二)Spring容器

    大佬总结的很好,请去看大佬博客. http://www.cnblogs.com/chenssy/archive/2012/11/15/2772287.html https://www.cnblogs. ...

  10. 平板&Safari 开发tips

    css: *{ margin: 0; padding: 0;  /* 禁止用户点选网页内容 */ -webkit-touch-callout:none; -webkit-user-select:non ...