codeforces Calendar
来源:互联网 发布:java h5微信支付接口 编辑:程序博客网 时间:2024/05/12 19:47
题目链接:http://codeforces.com/problemset/problem/58/D
题目:有 n个城市(n为偶数),然后n个城市的名字,用这些名字来出版这么个东西( calendar ),要求按照(n/2)行输出,且每行要等长。
#include<iostream>#include<cstring>#include<string>#include<cstdio>#include<algorithm>using namespace std;const int MAX=10005;string str1[MAX];char ch[100];bool mark[MAX];string str2[MAX];int main(void){ int n; int i,j; int length=0; memset(mark, false, sizeof(mark)); scanf("%d", &n); for(i=0; i<n; ++i) { scanf("%s", ch); str1[i].assign(ch); length+=str1[i].size(); } length/=n/2; char d; scanf("%s", ch); d=ch[0]; sort(str1, str1+n); int k=0; for(i=0; i<n; ++i) { if(mark[i]) continue; for(j=i+1; j<n; ++j) { if(!mark[j] && str1[i].size()+str1[j].size()==length) { mark[j]=true; if(str1[i]+d+str1[j]<str1[j]+d+str1[i]) sprintf(ch, "%s%c%s",str1[i].c_str(), d, str1[j].c_str()); else sprintf(ch, "%s%c%s",str1[j].c_str(), d, str1[i].c_str()); str2[k++].assign(ch); break; } } } sort(str2, str2+n/2); for(i=0; i<n/2; ++i) printf("%s\n", str2[i].c_str()); return 0;}
0 0
- codeforces Calendar
- codeforces 304 B. Calendar
- Codeforces Round #183 (Div. 2) B. Calendar
- codeforces 304B. Calendar (日期相减)
- 【63.63%】【codeforces 724A】Checking the Calendar
- [codeforces]A. Checking the Calendar 水题
- Codeforces 724A. Checking the Calendar
- Codeforces 724A-Checking the Calendar
- CodeForces 724A Checking the Calendar
- 【codeforces 760A】Petr and a calendar
- Codeforces Round #393 Petr and a calendar
- Codeforces 760A-Petr and a calendar
- CodeForces 760A Petr and a calendar
- CodeForces 172 D.Calendar Reform(数论)
- CodeForces 760APetr and a calendar
- calendar
- calendar
- Calendar
- 肾(病)家庭理疗
- 肝(病)家庭理疗
- eclipse,wtp配置
- 推介博客:旗舰评论——战略航空军元帅的旗舰
- FreeBSD带有许多简单而功能强大的命令
- codeforces Calendar
- 最长回文
- Longest Palindromic Substring
- bzoj1012线段树水题
- 零至二岁宝宝故事(一)
- iphone QQ音乐锁屏歌词实现思路
- xmltype.extractValue
- strcpy、wcscpy与_tcscpy关系 strcpy_s与strcpy比较
- Android 一个apk多个ICON执行入口