1. PAT乙题 1027. 打印沙漏(20)

    ```c++ //cpp: #include #include #include using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif int a; char b; scanf("%d %c", &a, &b); int n = floor(sqrt((float)(a+1)/2)); int yushu = a - 2 * pow(n,2) + 1; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) printf(" "); for (int j = 0; j < 2 * (n - i) - 1; j++) printf("%c", b); printf("\n"); } for (int i = 1; i < n; i++) { for (int j = 0; j < n - i-1; j++) printf(" "); for (int j = 0; j < 2 * i + 1; j++) printf("%c", b); printf("\n");

    2018/01/26 PAT

  2. PAT乙题 1026. 程序运行时间(15)

    //cpp: #include <iostream> #include <algorithm> #include<math.h> using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif LOCAL int a, b; cin >> a >> b; float c = (float)(b - a) / 100.0 + 0.5; int c1 = floor(c); int h = c1 / 3600; int m = (c1 - h * 3600) / 60; int s = c1 % 60; printf("%02d:%02d:%02d", h, m, s); return 0; }

    2018/01/26 PAT

  3. PAT乙题 1025. 反转链表 (25)

    //cpp: #include <iostream> #include <algorithm> using namespace std; int main() { #ifdef LOCAL freopen("D:\\datain.txt", "r", stdin); #endif int first, k, n, temp; cin >> first >> n >> k; int data[100005], next[100005], list[100005]; for (int i = 0; i < n; i++) { cin >> temp; cin >> data[temp] >> next[temp]; } int sum = 0;//不一定所有的输入的结点都是有用的,加个计数器 while (first != -1) { list[sum++] = first; first = next[first]; } for (int i = 0; i < (sum - sum % k); i += k) reverse(begin(list) + i, begin(list) + i + k); for (int i = 0; i < sum - 1; i++) printf("%05d %d %05d\n", list[i], data[list[i]], list[i + 1]); printf("%05d %d -1", list[sum - 1], data[list[sum - 1]]); return 0; }

    2018/01/26 PAT

  4. PAT乙题1024. 科学计数法 (20)

    ```c++ #include #include #include #include #include #include #include using namespace std;

    2018/01/26 PAT

  5. PAT乙题1023. 组个最小数 (20)

    ```c++ #include #include #include #include #include #include using namespace std;

    2018/01/26 PAT

  6. PAT乙题1022. D进制的A+B (20)

    ```c++ #include #include #include #include

    2018/01/26 PAT

  7. PAT乙题1021. 个位数统计 (15)

    ```c++ #include #include #include #include #include #include using namespace std;

    2018/01/26 PAT

  8. PAT乙题1020. 月饼 (25)

    ```c++ #include #include #include #include #include #include using namespace std; struct d { double q; double lr;//利润 double bl;//比率 }; bool cmp(d a, d b) { return a.bl > b.bl; } int main() { #ifdef LOCAL freopen("d:\\datain.txt", "r", stdin); //freopen("d:\\dataout.txt", "w", stdout); #endif LOCAL vector data; int n, D; cin >> n >> D; //cout << n << " " << D << endl;

    2018/01/26 PAT

  9. PAT乙题1019. 数字黑洞 (20)

    ```c++ #include #include #include #include #include #include using namespace std; int main() { #ifdef LOCAL freopen("d:\\datain.txt", "r", stdin); //freopen("d:\\dataout.txt", "w", stdout); #endif LOCAL string n; cin >> n; n.insert(0, 4 - n.length(), '0'); bool f = false; for (int i = 0; i < n.length(); i++) { if (n[0]!=n[i]) { f = true; break; } } int a, b; string t1, t2; int n1 = stoi(n);

    2018/01/26 PAT

  10. string、char*和int转换

    对于string与int的转换, 刷题用stoi(string)函数和to_string(int)函数

    2018/01/25 C