题意:

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

题目中关键段:

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. nginx静态资源服务器简单配置

    有时候我们可以把服务器的一些文件放在固定目录以便下载,比如image,css,js等.就可以使用nginx转发静态资源. 参考链接:https://blog.csdn.net/name_is_wl/a ...

  2. 进击的Python【第八章】:动态导入模块、断言、socket开发之SSH,FTP

    一.动态导入模块 知道一个模块名的字符串形式,通过字符串来导入模块 mod = __import__("lib.aa") print(mod) instance = getattr ...

  3. redis相关配置

    redis相关配置1.yum 源码 rpm yum 快速,间接,高效,解决依赖关系,(自动安装到某个路径,不可控),通过yum安装的软件查询命令 rpm -ql nginx yum源的软件包可能版本非 ...

  4. 环境变量解释以及在Linux下的环境变量设置

    一.环境变量解释 环境变量是什么? 引用百度百科里面的解释:环境变量是操作系统中一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息.例如Windows系统中的path环境变量,当要求 ...

  5. Hdu 3605 Escape (最大流 + 缩点)

    题目链接: Hdu 3605  Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...

  6. 自定义Image HtmlHelper

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

  7. Sort排序浅聊

    集合是什么?笔者简易描述:数组是不可变的,所以我们使用集合来代替. using.System.Collections; 非泛型集合 using.System.Collections.Gernerc;泛 ...

  8. lua centos 安装报错

    yum install libtermcap-devel ncurses-devel libevent-devel readline-devel

  9. 460在全志r16平台tinav3.0系统下使用i2c-tools

    460在全志r16平台tinav3.0系统下使用i2c-tools 2018/9/6 19:05 版本:V1.0 开发板:SC3817R SDK:tina v3.0 1.01原始编译全志r16平台ti ...

  10. Android基础夯实--重温动画(四)之属性动画 ValueAnimator详解

    宝剑锋从磨砺出,梅花香自苦寒来:千淘万漉虽辛苦,吹尽狂沙始到金: 长风破浪会有时,直挂云帆济沧海 一.摘要 Animator类作为属性动画的基类,它是一个抽象类,它提供了实现动画的基本架构,但是我们不 ...