题目链接:https://codeforces.com/contest/1090/problem/B

Examples
standard input

The most famous characters of Pushkin’s works are Onegin \cite{onegin},
Dubrovsky \cite{dubrovsky} and Tsar Saltan \cite{saltan}.
\begin{thebibliography}{99}
\bibitem{saltan} A.S.Pushkin. The Tale of Tsar Saltan. 1832.
\bibitem{onegin} A.S.Pushkin. Eugene Onegin. 1831.
\bibitem{dubrovsky} A.S.Pushkin. Dubrovsky. 1841.
\end{thebibliography}

standard output

Incorrect
\begin{thebibliography}{99}
\bibitem{onegin} A.S.Pushkin. Eugene Onegin. 1831.
\bibitem{dubrovsky} A.S.Pushkin. Dubrovsky. 1841.
\bibitem{saltan} A.S.Pushkin. The Tale of Tsar Saltan. 1832.
\end{thebibliography}

standard input

The most famous characters of Pushkin’s works are Onegin \cite{onegin},
Dubrovsky \cite{dubrovsky} and Tsar Saltan \cite{saltan}.
\begin{thebibliography}{99}
\bibitem{onegin} A.S.Pushkin. Eugene Onegin. 1831.
\bibitem{dubrovsky} A.S.Pushkin. Dubrovsky. 1841.
\bibitem{saltan} A.S.Pushkin. The Tale of Tsar Saltan. 1832.
\end{thebibliography}

standard output

Correct

题意:

文章末尾这个参考文献的顺序可能是错乱的,需要你修正一下。

题解:

就是考察字符串输入输出以及其他一些操作的,用map<string,int>哈希一下参考文献的标识,然后老老实实模拟就行了。

AC代码:

#include<bits/stdc++.h>
using namespace std; struct Cite{
int idx;
string str;
Cite(){}
Cite(int _i,const string& s) {
idx=_i, str=s;
}
bool operator<(const Cite& oth)const {
return idx<oth.idx;
}
};
vector<Cite> cites; int tot;
map<string,int> mp; void Find(const string& s)
{
int pos,beg=;
while((pos=s.find("\\cite{",beg))!=-)
{
string res;
for(beg=pos+;beg<s.size() && s[beg]!='}';beg++) res+=s[beg];
mp[res]=++tot;
}
}
int main()
{
ios::sync_with_stdio();
cin.tie(), cout.tie(); string str;
bool END=;
tot=; mp.clear();
while(getline(cin,str))
{
if(str=="\\begin{thebibliography}{99}") {END=;continue;}
if(str=="\\end{thebibliography}") break;
if(!END) Find(str);
else
{
int pos=str.find("\\bibitem{");
string res;
for(pos+=;pos<str.size() && str[pos]!='}';pos++) res+=str[pos];
cites.push_back(Cite(mp[res],str));
}
} bool CORRECT=;
for(int i=;i<cites.size();i++) if(cites[i].idx!=i+) CORRECT=;
if(CORRECT) cout<<"Correct\n";
else
{
cout<<"Incorrect\n";
sort(cites.begin(),cites.end());
cout<<"\\begin{thebibliography}{99}\n";
for(int i=;i<cites.size();i++) cout<<cites[i].str<<'\n';
cout<<"\\end{thebibliography}\n";
}
}

Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]的更多相关文章

  1. Codeforces 1090A - Company Merging - [签到水题][2018-2019 Russia Open High School Programming Contest Problem A]

    题目链接:https://codeforces.com/contest/1090/problem/A A conglomerate consists of n companies. To make m ...

  2. Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]

    题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...

  3. Codeforces 1090M - The Pleasant Walk - [签到水题][2018-2019 Russia Open High School Programming Contest Problem M]

    题目链接:https://codeforces.com/contest/1090/problem/M There are n houses along the road where Anya live ...

  4. 2019 The 19th Zhejiang University Programming Contest

    感想: 今天三个人的状态比昨天计院校赛的状态要好很多,然而三个人都慢热体质导致签到题wa了很多发.最后虽然跟大家题数一样(6题),然而输在罚时. 只能说,水题还是刷得少,看到签到都没灵感实在不应该. ...

  5. 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛

    Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered  ...

  6. 模拟赛小结:2017 China Collegiate Programming Contest Final (CCPC-Final 2017)

    比赛链接:传送门 前期大顺风,2:30金区中游.后期开题乏力,掉到银尾.4:59绝杀I,但罚时太高卡在银首. Problem A - Dogs and Cages 00:09:45 (+) Solve ...

  7. C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest

    We call a string as a 0689-string if this string only consists of digits '0', '6', '8' and '9'. Give ...

  8. B.Grid with Arrows-The 2019 ICPC China Shaanxi Provincial Programming Contest

    BaoBao has just found a grid with $n$ rows and $m$ columns in his left pocket, where the cell in the ...

  9. Codeforces Gym101606 I.I Work All Day (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    I I Work All Day 这个题就是取模找最小的. 代码: 1 #include<iostream> 2 #include<cstdio> 3 #include< ...

随机推荐

  1. IEEE754标准的浮点数存储格式

    操作系统 : CentOS7.3.1611_x64 gcc版本 :4.8.5 基本存储格式(从高到低) : Sign + Exponent + Fraction Sign : 符号位 Exponent ...

  2. 每天一个linux命令(15):tail命令

    1.命令简介 tail (tail) 用来显示档案的结尾(默认为10行)至标准输出中.若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头.如果不指定文件或文件为"-" ...

  3. 升级SilverLight为5.1.50907.0后,VS调试时报“无法启动调试--未安装 Silverlight Developer 运行时。请安装一个匹配版本”的处理办法

    作者: zyl910 一.问题 今天需要调试一个SilverLight程序.运行时ie弹出了一个升级提示,于是手贱点了升级. 随后便悲剧了,VS调试时报"无法启动调试--未安装 Silver ...

  4. Ubuntu 16.04 升级git

    To update git on Ubuntu 12.04 just follow this line of commands: sudo apt-get install python-softwar ...

  5. 各种OJ网站汇总

    acmicpc.info acmicpc.info http://acmicpc.info/archives/224 此网站聚合了各种ICPC相关信息. 国内Online Judge 用户体验极佳的v ...

  6. linux内存管理之malloc、vmalloc、kmalloc的区别

    kmalloc kzalloc vmalloc malloc 和get_free_page()的区别 一.简述 1. kmalloc申请的是较小的连续的物理内存,虚拟地址上也是连续的.kmalloc和 ...

  7. Jenkins自动部署增加http状态码校验

    公司推进Jenkins自动化部署,因为web站点都是集群部署,部署需要测试指定服务器web服务是否成功启动,页面是否正常访问,经过不断baidu发现,python的request模块可以很好的解决这一 ...

  8. maven project 报错解决方法

    1 maven 在添加包后出错,project 处有红线的解决办法 Maven默认会使用本地缓存的库来编译工程,对于上次下载失败的库,maven会在~/.m2/repository/<group ...

  9. 在Java路上,我看过的一些书、源码和框架(转)

    原文地址:http://www.jianshu.com/p/4a41ee88bd82 物有本末,事有终始,知所先后,则近道矣 面试经历 关于Java面试,你应该准备这些知识点关于Java面试,你应该准 ...

  10. 资源查找器PathMatchingResourcePatternResolver的使用

    资源查找器PathMatchingResourcePatternResolver的使用 PathMatchingResourcePatternResolver是一个Ant通配符模式的Resource查 ...