UvaLive 4917 Abstract Extract (模拟)
题意:
给定一篇文章, 文章中有段落, 段落中有句子。 句子只会以'!' , '.' , '?' 结尾, 求出每段中含有与他下面同样是该段落中相同单词数最多的句子, 注意, 单词忽略大小写, 重复的单词只算一个。
题目中关键段:
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 (模拟)的更多相关文章
- UVALive - 6269 Digital Clock 模拟
UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...
- UVALive - 7139(差分+模拟)
题目链接 参考 题意 N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 分析 由于车的起点和终点都为左上角,且每个格子里的人永远面对着车, ...
- UVALive 7464 Robots(模拟)
7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...
- 【Bit String Reordering UVALive - 6832 】【模拟】
题意分析 题目讲的主要是给你一个01串,然后给你要变成的01串格式,问你要转换成这一格式最少需要移动的步数. 题目不难,但当时并没有AC,3个小时的个人赛1道没AC,归根到底是没有逼自己去想,又想的太 ...
- 【Miscalculation UVALive - 6833 】【模拟】
题目分析 题目讲的是给你一个串,里面是加法.乘法混合运算(个人赛中误看成是加减乘除混合运算),有两种算法,一种是乘法优先运算,另一种是依次从左向右运算(不管它是否乘在前还是加在前). 个人赛中试着模拟 ...
- UVaLive 6809 Spokes Wheel (模拟)
题意:给定两个16进制数,问你把它转成二进制后,把第一个向左或者向右旋转最少的次数同,使得第一个变成第二个. 析:也是比较水的,按照要求做就好,注意0的情况,可能会忘记. #pragma commen ...
- UVALive 6858 Frame (模拟)
Frame 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/D Description http://7xjob4.com1.z0 ...
- Mockito 中文文档 ( 2.0.26 beta )
Mockito 中文文档 ( 2.0.26 beta ) 由于缺乏校对,难免有谬误之处,如果发现任何语句不通顺.翻译错误,都可以在github中的项目提出issue.谢谢~ Mockito框架官方地址 ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
随机推荐
- pip 的具体含义
Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip (pip3 for Pytho ...
- hihoOffer收割练习20题目1
题目1 : 无根数变有根树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵包含 N 个节点的无根树,小Hi想知道如果指定其中某个节点 K 为根,那么每个节点的父 ...
- 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...
- 题解报告:hdu 2546 饭卡(01背包)
Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...
- 框架系列~OwinSelfHost自宿主的使用
在进入mvc5之后,OWIN变更很主推,很热,关于OWIN的文章也就出来了,下面阅读了dudu和一些园友的文章,自己也做了一个SelfHost的程序,测试了一下,感觉还是比较有Core的风格,可能也是 ...
- Sping Boot返回Json格式自定义
转载请注明http://www.cnblogs.com/majianming/p/8491020.html 在写项目过程中,遇到了需要定义返回的json字段格式的问题 例如在实体属性中,我有一个字段是 ...
- jq星星评分
html代码 <div class="make_mark"> <h5>请为这次服务打分</h5> <div class="mar ...
- Git ---创建和切换分支
······································································"天下武功,唯快不破" git分支: g ...
- [Tunny]CSS LESS框架基础
[黄映焜/Tunny,20140711] Less 是一个Css 预编译器,意思指的是它可以扩展Css语言,添加功能如允许变量(variables),混合(mixins),函数(functions) ...
- logback配置模板
<?xml version="1.0" encoding="UTF-8"?> <configuration> <prope ...