题目链接: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. 关于Discuz! X系列远程代码执行漏洞

    一.漏洞起源 突然有同事反馈,无法注册 看到这里不了解的同行估计一年懵逼,这里也是常用的漏洞攻击,可以肯定的是  badwords.php文件被修改了 ,可以查看这个文件内容 <?php $_C ...

  2. Java驱动远程连接mongoDB(简明易懂版)

    mongodb默认是不能远程连接的,而且在linux安装完你会发现,它的目录极其简单,连个配置文件都没有. 我的mongodb的版本是3.6,目前最新的.https://www.mongodb.com ...

  3. dos命令大全 黑客必知的DOS命令集合

    dos命令大全 黑客必知的DOS命令集合 一般来说dos命令都是在dos程序中进行的,如果电脑中安装有dos程序可以从开机选项中选择进入,在windows 系统中我们还可以从开始运行中输入cmd命令进 ...

  4. centos7磁盘挂载及取消

    磁盘挂载查看已经挂载磁盘数 cat /proc/scsi/scsi | grep HostHost: scsi1 Channel: 00 Id: 00 Lun: 00Host: scsi2 Chann ...

  5. SpringBoot里使用RMI进行远程方法调用

    一.Java RMI定义 Java RMI:Java远程方法调用,即Java RMI(Java Remote Method Invocation)是Java编程语言里,一种用于实现远程过程调用的应用程 ...

  6. The thumbprint of same asymmetric key is not same in 'SQL Server Connector for Microsoft Azure Key Vault' 1.0.4.0 and 'SQL Server Connector for Microsoft Azure Key

    https://support.microsoft.com/en-us/help/4470999/db-backup-problems-to-sql-server-connector-for-azur ...

  7. 通过一个小Trick实现shader的像素识别/统计操作

    2018/12/14日补充:后来发现compute shader里用AppendStructuredBuffer可以解决这类问题,请看这里:https://www.cnblogs.com/hont/p ...

  8. [加密]证书、CA、证书信任链

    转自:https://www.jianshu.com/p/6bf2f9a37feb TLS 传输层安全性协定 TLS(Transport Layer Security),及其前身安全套接层 SSL(S ...

  9. Java代码实现文件添加数字签名、验证数字签名

    Linux下实现加签.验签 1.使用OpenSSL 生成公钥和密钥: #用 OpenSSL, Linux 上自带,常用命令如下: #生成 RSA 私钥(传统格式的) openssl genrsa -o ...

  10. kafka性能测试

    参考阿里中间件团队博客的博文 Kafka vs RocketMQ——多Topic对性能稳定性的影响 使用的测试工具为Jmeter