1. c++头文件与预处理器

    引用头文件的语法 使用预处理指令 #include 可以引用用户和系统头文件。它的形式有以下两种:

    2018/01/26 C

  2. c++多态

    C++多态意味着调用成员函数时,会根据调用函数的对象的类型来执行不同的函数;

    2018/01/26 C

  3. c++反转

    algorithm.h

    2018/01/26 C

  4. c++优先队列自定义排序

    引入头文件queue

    2018/01/26 C

  5. C++类

    C++ 类定义

    2018/01/26 C

  6. PAT乙题 1032. 挖掘机技术哪家强(20)

    #include <iostream> #include <algorithm> #include<math.h> #include<string> #include<vector> #include<ctype.h> #include<set> using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif int n; cin >> n; int d[100005]; fill(d, d + 100005, 0); int a; int b; for (int i = 0; i < n; i++) { scanf("%d %d", &a, &b); d[a] += b; } int maxd = 0.0; int maxi = 0; for (int i = 0; i < 100005; i++) { if (d[i] > maxd) { maxd = d[i]; maxi = i; } } printf("%d %d", maxi, maxd); }

    2018/01/26 PAT

  7. PAT乙题 1031. 查验身份证(15)

    //cpp: #include <iostream> #include <algorithm> #include<math.h> #include<string> #include<vector> #include<ctype.h> #include<set> using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif int n; string a; cin >> n; char m[12] = { '1','0','X','9','8','7','6','5','4','3','2' }; int b[17] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 }; bool flag = true; for (int i = 0; i < n; i++) { cin >> a; int sum = 0; for (int j = 0; j < 17; j++) { sum += (a[j] - '0')*b[j]; //cout << "+" << a[j] - '0'; } //cout <<"sum"<< sum << endl; sum = sum % 11; //cout << sum << endl; //cout << m[sum] << endl; if (m[sum] != a[17]) { cout << a << endl; flag = false; } } if (flag) cout << "All passed"; }

    2018/01/26 PAT

  8. PAT乙题 1030. 完美数列(25)

    //cpp: #include <iostream> #include <algorithm> #include<math.h> #include<string> #include<vector> #include<ctype.h> #include<set> using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif int n, p; cin >> n >> p; long long d[100005]; for (int i = 0; i < n; i++) { scanf("%lld", &d[i]); } sort(begin(d), begin(d) + n); int maxc = 0; for (int i = 0; i < n; i++) { for (int j = i + maxc; j < n; j++) { if (d[j] <= d[i] * p) { int t = j - i + 1; if (t > maxc) maxc = t; } else break; } } cout << maxc; return 0; }

    2018/01/26 PAT

  9. PAT乙题 1029. 旧键盘(20)

    //cpp: #include <iostream> #include <algorithm> #include<math.h> #include<string> #include<vector> #include<ctype.h> #include<set> using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif string a, b; cin >> a >> b; int j = 0; set<char> s; for (int i = 0; i < b.length(); i++) { while (a[j] != b[i]) { if(s.find(toupper(a[j]))==s.end()) printf("%c", toupper(a[j])); s.insert(toupper(a[j])); //cout << a[j]; j++; } j++; //cout << "++++" << b[i] << endl; } while (j < a.length()) { if (s.find(toupper(a[j])) == s.end()) printf("%c", toupper(a[j])); s.insert(toupper(a[j])); //cout << a[j]; j++; } return 0; }

    2018/01/26 PAT

  10. PAT乙题 1028. 人口普查(20)

    //cpp: #include <iostream> #include <algorithm> #include<math.h> #include<string> using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif string max1, min1; int count = 0; int n; cin >> n; string t1,t2; string min2 = "1814/09/06"; string max2 = "2014/09/06"; max1 = min2; min1 = max2; string min3, max3; for (int i = 0; i < n; i++) { cin >> t1 >> t2; if (t2 >= min2 && t2 <= max2) { count++; if (t2 >= max1) { max1 = t2; max3 = t1; } if (t2 <= min1) { min1 = t2; min3 = t1; } } } cout << count; if(count>0) cout<<" " << min3 << " " << max3; return 0; }

    2018/01/26 PAT