題目連接:https://codeforces.com/contest/1090/problem/Bhtml
Examples
standard inputios
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 outputc++
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 inputspa
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 output3d
Correct
題意:code
文章末尾這個參考文獻的順序多是錯亂的,須要你修正一下。htm
題解:blog
就是考察字符串輸入輸出以及其餘一些操做的,用map<string,int>哈希一下參考文獻的標識,而後老老實實模擬就好了。ci
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=0; while((pos=s.find("\\cite{",beg))!=-1) { string res; for(beg=pos+6;beg<s.size() && s[beg]!='}';beg++) res+=s[beg]; mp[res]=++tot; } } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); string str; bool END=0; tot=0; mp.clear(); while(getline(cin,str)) { if(str=="\\begin{thebibliography}{99}") {END=1;continue;} if(str=="\\end{thebibliography}") break; if(!END) Find(str); else { int pos=str.find("\\bibitem{"); string res; for(pos+=9;pos<str.size() && str[pos]!='}';pos++) res+=str[pos]; cites.push_back(Cite(mp[res],str)); } } bool CORRECT=1; for(int i=0;i<cites.size();i++) if(cites[i].idx!=i+1) CORRECT=0; if(CORRECT) cout<<"Correct\n"; else { cout<<"Incorrect\n"; sort(cites.begin(),cites.end()); cout<<"\\begin{thebibliography}{99}\n"; for(int i=0;i<cites.size();i++) cout<<cites[i].str<<'\n'; cout<<"\\end{thebibliography}\n"; } }