排位赛第二场 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 中国大陆许可协议进行许可。
分类:
排位赛
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步