PAT (Basic) 1021~1025
2014-03-05 23:34
369 查看
1021. 个位数统计 (15)
#include <iostream> #include <map> #include <string> using namespace std; int main() { map<int, int> mp; string str; cin >> str; int len = str.length(); for (int i = 0; i < len; i++) { int index = str[i] - '0'; mp[index]++; } for (int i = 0; i < 10; i++) { if (mp[i] != 0) cout << i << ":" << mp[i] << endl; } return 0; }
1022. D进制的A+B (20)
#include <iostream> #include <string> #include <algorithm> using namespace std; string dec2d(int n, int d) { string res; while (n) { res += n % d + '0'; n /= d; } reverse(res.begin(), res.end()); return res; } int main() { int a, b, d; cin >> a >> b >> d; if (a + b == 0) cout << 0; else cout << dec2d(a + b, d) << endl; return 0; }
1023. 组个最小数 (20)
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> v; for (int i = 0; i < 10; i++) { int tmp; cin >> tmp; v.push_back(tmp); } int pos = 1; for (int i = 1; i < 10; i++) { if (v[i] != 0) { pos = i; break; } } cout << pos; for (int i = 0; i < v[0]; i++) cout << 0; while (--v[pos]) cout << pos; for (int i = pos + 1; i < 10; i++) { while (v[i]--) cout << i; } cout << endl; return 0; }
1024. 科学计数法 (20)
同PAT-A-1073. Scientific Notation (20) 见:/article/2143543.html
1025. 反转链表 (25)
同PAT-A-1074. Reversing Linked List (25) 见:/article/2143557.html
相关文章推荐
- NSMutableString 的方法介绍
- mysql出错信息对照整理
- 创建线程的几种方式(代码示例)
- POJ 3255 Roadblocks 次短路
- 2014第10周三高效程序员的习惯
- POJ 3255 Roadblocks 次短路
- win7&vs2013编译webkit
- poj 3684--Physics Experiment(碰撞)
- android延时功能的实现
- J2EE学习从菜鸟变大鸟之七 Servlet
- C#后台调用前台JS函数方法
- 第五天 数组 学习笔记
- J2EE学习从菜鸟变大鸟之七 Servlet
- 进程与线程--原理
- C++中引用与指针的区别
- U-boot分析与移植(3)----U-boot stage2分析 .
- 使用MySQL5.6安装Magento时提示innodb 不支持
- Struts文件上传allowedTypes/allowedExtensions问题
- C语言中字符串结束符探究
- 链表的操作【记录】