两个for循环的的思想和输出一个直角三角形类似

P2669 [NOIP2015 普及组] 金币

daybreak2626 @ 2021-05-15 15:04:52

#include<bits/stdc++.h>

using namespace std;

int main() {
    int k, h = 0, t = 0;
    cin >> k;

    for (int i = 1;i<=10000; i++) {
        for (int j = 1; j <= i; j++) {
            h = h + i;
            t++;
            if (t == k) {
                cout << h << endl;
                break;
            }
        }
    }
    return 0;
}

by _StarBird_ @ 2021-05-15 15:33:26

tlqtj,jbl


|