5-1 ~ 5-4
来源:互联网 发布:粒子群算法图像去噪 编辑:程序博客网 时间:2024/04/30 00:49
//5-1 UVa 1593 /* alignment n. 队列,成直线;校准;结盟 customizable adj. 可定制的 align vt. 排列 vertical adj. 垂直的,直立的;n.垂直线,垂直面 */ int main() { string s; vector<vector<string> > strcache; int maxlen[1005] = { 0 }; //IN(); OUT(); CLOSE(); while(getline(cin, s)) { stringstream ss(s); string word; vector<string> svec; while(ss >> word) { //cout << word; int i = svec.size(); maxlen[i] = max(maxlen[i], (int )word.size()); svec.push_back(word); } strcache.push_back(svec); } for(int i = 0; i < strcache.size(); i++) { for(int j = 0; j < strcache[i].size(); j++) { cout << strcache[i][j]; int t = maxlen[j]+1-strcache[i][j].size(); if(j != strcache[i].size()-1) while(t--) cout << ' '; } cout << endl; } return 0; }
//5-2 UVa 1594/*period n. 周期*/int main() { int T; scanf("%d", &T); while(T--) { int n, x; scanf("%d", &n); vector<int> zero(n, 0); vector<int> n_tuple; set<vector<int> > tuples; for(int i = 0; i < n; i++) { scanf("%d", &x); n_tuple.push_back(x); } tuples.insert(n_tuple); for(int i = 0; i < 1000; i++) { vector<int> t; for(int j = 0; j < n; j++) { x = abs(n_tuple[j] - n_tuple[(j+1)%n]); t.push_back(x); } n_tuple = t; if(t == zero) { printf("ZERO\n"); break; } if(tuples.count(t)) { printf("LOOP\n"); break; } tuples.insert(t); } } return 0;}
//习题5-3 卡片游戏(Throwing cards away I, UVa 10935)/*deck n. 甲板;行李仓;露天平台vt. 装饰;装甲板;打扮discard vt. 抛弃;放弃;丢弃 vi. 放弃 n . 抛弃;被丢弃的东西或人*/int main() { int n; while(scanf("%d", &n) && n) { deque<int> cards; printf("Discarded cards:"); for(int i = 1; i <= n; i++) cards.push_back(i); int flag = 1; while(cards.size() > 1) { if(flag) flag = 0; else printf(","); printf(" %d", cards.front()); cards.pop_front(); int t = cards.front(); cards.push_back(t); cards.pop_front(); } printf("\n"); printf("Remaining card: %d\n", cards.front()); } return 0;}
//习题5-4 交换学生(Foreign Exchange, UVa 10763)int main() { int n, a, b; //IN(); OUT(); while(scanf("%d", &n) && n) { map<pair<int, int>, int> cnt; for(int i = 0; i < n; i++) { scanf("%d%d", &a, &b); pair<int, int> p(a, b); cnt[p]++; } bool flag = true; for(auto i = cnt.begin(); i != cnt.end(); i++) { int a = (*i).first.second, b = (*i).first.first; pair<int, int> p(a, b); //cout << a << b; if(!cnt.count(p) || cnt[p] != (*i).second) { flag = false; break; } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
0 0
- 5-1 ~ 5-4
- C:1-5-4
- 4 . 5 . 1 多维数组
- javascript 4-5章1
- 对数组进行特定的从小到大的排序如将1,1,2,2,3,3,4,4,5,5,5,5,5,5排序成1,2,3,4,5,1,2,3,4,5,5,5,5,5
- 求1-5的和/积。1+2+3+4+5,1*2*3*4*5
- Django之{"del": {"1": ["5"]}, "add": {"1": ["5", "4"]}}数据处理
- 练习5-3&&5-4&&5-5
- 5/4
- 4-5
- 4-5
- 5-4
- 4-5
- 5-4
- 5- 4
- 5-4
- 4、5
- 1,2,3,4,5输出
- 干货实操:微服务Spring Cloud 系列(二) Eureka服务发现与服务注册(strand alone)
- 命名法 的 简洁归纳表
- java I/O操作相关的类
- 快速H.264编码算法的研究及实现
- xcode 老是卡在running custom shell scripts
- 5-1 ~ 5-4
- 剑指offer 15-反转链表
- Druid连接池以及监听
- struts2-令牌拦截器防止表单重复提交
- php 把数据导入excel表格中
- tcp定时器调研
- STM8L在中断中写IO异常的问题
- js保留2位小数
- 深度学习零基础之框架配置Windows+caffe+VS2013+python