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) 见:http://blog.csdn.net/hale1007/article/details/20243059
1025. 反转链表 (25)
同PAT-A-1074. Reversing Linked List (25) 见:http://blog.csdn.net/hale1007/article/details/20570989