codeforces 1090B切题记录

本文介绍了一种解决文献引用乱序问题的算法,通过使用C++实现,利用哈希表和自定义结构体进行文献引用的排序。文章详细展示了算法的具体实现过程,包括输入输出示例,以及如何通过比较函数实现正确的文献排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写在前面:说实话我做这道题目的时候异常的蒙逼,那个傻逼 大佬出的,TMD是pdf格式就算了,你大爷连提交地方或者测试数据都没有,怎么判断程序是否正确啊!!!所以如果有大佬拥有测试数据或者提交方法请在下方评论区联系我,万分感谢。

题目原文:(鉴于优快云没有上传附件的功能,再次提供文件链接,有需要者自行下载)
下载链接
复制版:在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
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>哈希一下参考文献的标识,然后模拟就行了。根本没什么难度(是不可能的)。

现在给出几种解法。
1、

#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";
    }
}

剩余解法会在以后逐步补充,如果有大佬发现什么问题欢迎留言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值