题意:

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

题目中关键段:

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. 51nod 1088 最长回文子串

    1088 最长回文子串 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一 ...

  2. 2017 JUST Programming Contest 3.0 E. The Architect Omar

    E. The Architect Omar time limit per test 1.0 s memory limit per test 256 MB input standard input ou ...

  3. Permutation UVA - 11525(值域树状数组,树状数组区间第k大(离线),log方,log)(值域线段树第k大)

    Permutation UVA - 11525 看康托展开 题目给出的式子(n=s[1]*(k-1)!+s[2]*(k-2)!+...+s[k]*0!)非常像逆康托展开(将n个数的所有排列按字典序排序 ...

  4. 员工管理系统(集合与IO流的结合使用 beta5.0 BufferedReader/ BufferedWriter)

    package cn.gee; public class Emp { private String id;//员工编号 一般是唯一的 private String sname; private int ...

  5. IOS 绘制PDF -转

    -(void)createPdf:(UIImage *)img andText:(NSString *)text{ NSArray *paths = NSSearchPathForDirectorie ...

  6. 设置UITableViewCell 选中时的背景颜色

    自定义Cell如图 一个View上面放了四个Label 分别连线到.m文件中 @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @pro ...

  7. 科普 eclipse中的Java build

    在刚学eclipse的时候,build path是经常会用到的,但经常就是跟着教程走,额就不太懂这是干嘛的,然后今天看见极客视频里有相关的讲解,来记录一下. Build Path 是指定Java工程所 ...

  8. java websocket 简单使用【案例】

    现很多网站为了实现即时通讯,所用的技术都是轮询(polling).轮询是在特定的的时间间隔(如每1秒),由浏览器对服务器发 出HTTP request,然后由服务器返回最新的数据给客服端的浏览器.这种 ...

  9. restful api的简单理解

    百度百科的描述:一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制. RES ...

  10. PowerShell让系统可以执行.ps1文件,开机,关机,在线时间 , Function自定义函数

    Function Get-ComputerUptimeHistory { $q=' <QueryList> <Query Id="0" Path="Sy ...