zoj2172
来源:互联网 发布:php artisan optimize 编辑:程序博客网 时间:2024/06/18 01:59
思路好复杂,排了几次序才弄出来。不过是一次AC的。
之后去看了网上的答案才发现他给的名字的长度肯定是从小到大的。。。以为是不一定的,害我排了好久序。改了一下代码简洁多了。
#include <iostream>#include <string>#include <vector>using namespace std;int main(){ int num; while(cin >> num && num) { vector<string> name2; string n; for(int m = 0;m < num;m++) { cin >> n; name2.push_back(n); } static int time = 1; cout << "SET " << time << endl; time ++; for(int m = 0;m < num;m+=2) cout << name2[m] << endl; if(num%2 == 0) for(int m = num - 1;m>0;m-=2) cout << name2[m] << endl; else for(int m = num - 2;m>0;m-=2) cout << name2[m] << endl; } return 0;}
/***************************************************************************/
#include <iostream>//若名字长度不是从小到大的#include <string>#include <vector>using namespace std;int main(){ int num; while(cin >> num && num) { vector<string> name2; string n; int len[1000],order[1000]; for(int m = 0;m < num;m++) { cin >> n; name2.push_back(n); len[m] = n.size(); } for(int m = 0;m < num;m++) { order[m] = m; } for(int m = 0;m < num;m++) { for(int k = m;k < num;k++) { if(len[m] > len[k]) { int i; i = len[m]; len[m] = len[k]; len[k] = i; i = order[m]; order[m] = order[k]; order[k] = i; } } } static int time = 1; cout << "SET " << time << endl; time ++; for(int m = 0;m < num;m+=2) cout << name2[order[m]] << endl; if(num%2 == 0) for(int m = num - 1;m>0;m-=2) cout << name2[order[m]] << endl; else for(int m = num - 2;m>0;m-=2) cout << name2[order[m]] << endl; } return 0;}
0 0
- zoj2172
- zoj2172
- ZOJ2172 Symmetric Order
- Scala的学习--- scala的环境搭建
- JavaScript中instanceof与typeof运算符的用法及区别详细解析
- 设计模式(1):单例设计模式
- 微信学习资源
- uva120--模拟
- zoj2172
- Code Forces 559 A. Gerald's Hexagon(水~)
- 如何使用 git 忽略掉已经被 git 管理的文件
- 为什么C++基类析构函数写成虚函数
- 面试题19_二叉树的镜像——剑指offer系列
- Unity3D 学习入门
- JS获取随机颜色函数
- Switch case的应用
- 博洛尼亚中文离线地图App上线