专栏文章
题解:P13849 [CERC 2023] Equal Schedules
P13849题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mio466ki
- 此快照首次捕获于
- 2025/12/02 13:04 3 个月前
- 此快照最后确认于
- 2025/12/02 13:04 3 个月前
说实话,这读入真恶心...
读入用 C++ 的 string 类型会更方便。
其实此题可用 存储
思路:
- 先读入一个字符串 ,若
a=="------"结束读入。否则执行 。 - 读入一个整数和一个字符串,将 转化为数字,并令相对应的
map[str]减去两个整数之差。
再次读入,但这次让
map[str] 加上两个整数之差。然后,利用 自动给数组关键字排序的特性,用迭代器遍历 ,判断是否为 ,并标记。
最后,若没有输出(即标记未改变),输出
No differences found.。代码:
CPP#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
map<string,int>mp;
int main()
{
string a,c;
int b;
while(cin>>a,a!="------")//读入很重要!!!
{
cin>>b>>c;
int x=0;
for(char i:a)
x=x*10+i-'0';
mp[c]-=b-x;
}
a=c="";
while(cin>>a,a!="======")
{
cin>>b>>c;
int x=0;
for(char i:a)
x=x*10+i-'0';
mp[c]+=b-x;
}
bool k=false;
map<string,int>::iterator it=mp.begin();
while(it!=mp.end())
{
if((*it).s<0)
{
cout<<(*it).f<<" "<<(*it).s<<'\n';
k=true;
}
else if((*it).s>0)
{
cout<<(*it).f<<" +"<<(*it).s<<'\n';
k=true;
}
it++;
}
if(!k)
cout<<"No differences found.";
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...