题意:

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

题目中关键段:

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. 利用爬虫将Yuan先生的博客文章爬取下来

    由于一次巧遇,我阅读了Yuan先生的一篇博客文章,感觉从Yuan先生得博客学到很多东西,很喜欢他得文章.于是我就关注了他,并且想阅读更多出自他手笔得博客文章,无奈,可能Yuan先生不想公开自己得博客吧 ...

  2. gRPC入门

    一.gRPC简介 在介绍gRPC之前先说一下RPC(Remote Procedure Call),也叫远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.相比 ...

  3. 理解C++中拷贝构造函数

    拷贝构造函数的功能是用一个已有的对象来初始化一个被创建的同样对象,是一种特殊的构造函数,具有一般构造函数的所有特性,当创建一个新对象的时候系统会自动调用它:其形参是本类对象的引用,它的特殊功能是将参数 ...

  4. Python上下文管理器(Context managers)

    上下文管理器(Context managers) 上下文管理器允许你在有需要的时候,精确地分配和释放资源. 使用上下文管理器最广泛的案例就是with语句了.想象下你有两个需要结对执行的相关操作,然后还 ...

  5. A Simple Task CodeForces - 11D

    A Simple Task CodeForces - 11D 题意:输出一个无向图的简单环数量.简单环指无重复边的环.保证图无重边自环. ans[i][j]表示"包含i中的点,以i中第一个点 ...

  6. 题解报告:hdu 1039 Easier Done Than Said?

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1039 Problem Description Password security is a trick ...

  7. Hanlder + 弱引用防内存漏泄示例*

    Hanlder + 弱引用防内存漏泄示例: public class MainActivity extends AppCompatActivity { public final MyHandler h ...

  8. synchronized(5)修饰语句块之:synchronized(XXX.class)

    synchronized(XXX.class)有两种写法 synchronized(XXX.class)或者synchronized(obj.getClass()) Class也是一个类xxx.cla ...

  9. paint之Graphics

    在paint方法里面,这个Graphics类就相当于一支画笔.而且就画在那个component里面,比如frame. 看例子代码: import java.awt.*; public class Te ...

  10. Android Studio中找出不再使用的资源

    顶部Analyze菜单中选择Run Inspection by Name 在弹出的输入框中输入unused resources