排位赛第二场 K. Citations

题目:

思路:

读取:我们采用 getline(cin,s)来

观察题目发现,每个}的上一行的最后是没有","的,我们读取的时候补上
这里有坑:当用读入第二行的2时,我们需要用一个getline把整行读掉

输出:

我们采用字符串排序的方式把所有的对象标准化。
然后分析作者这个对象,对不同的情况分类输出。

代码

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
signed main()
{
IOS;
int t;
string s;
cin>>t;
while(t--)
{
int n;
cin>>n;
getline(cin,s);
for(int i=1;i<=n;i++)
{
vector<string>a(10);
for(auto & it:a)
{
getline(cin,it);
if(it[it.size()-1]!=',')
{
it+=",";
}
}
sort(a.begin()+1,a.end()-1); //这里sort容易写错,注意区间是 左闭右开 写成[a.beging()+1,a.begin()+8+1);
cout<<a[1].substr(8,2);
string ans;
for(int i=8;i<a[1].length();i++)
{
if(a[1][i]=='}')
{
ans+=". ";
break;
}
if(a[1][i]==' '&&a[1][i-1]!=',')
{
ans+=". ";
ans+=a[1][i+1];
}else if(a[1][i]==' '&&a[1][i-1]==',')
{
ans+=", ";
ans+=a[1].substr(i+1,2);
}
}
ans=ans+a[6].substr(7,a[6].length()-9)+". ";
ans=ans+a[2].substr(9,a[2].length()-11)+". ";
ans=ans+a[8].substr(6,a[8].length()-8)+";";
ans=ans+a[7].substr(8,a[7].length()-10);
ans=ans+"("+a[3].substr(8,a[3].length()-10)+")"+":";
ans=ans+a[4].substr(7,a[4].length()-9)+".";
cout<<ans<<"\n";
}
}
}

本文作者:TimMCBen

本文链接:https://www.cnblogs.com/TimMCBen/p/16008010.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   TimMCBen  阅读(16)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.