头像

不爱学习的图灵机




离线:20小时前


最近来访(85)
用户头像
飘向远方
用户头像
笑話
用户头像
张伟豪
用户头像
Fatin
用户头像
最后一只三脚兽
用户头像
zyrfff
用户头像
渣羞羞羞羞羞
用户头像
AcWing2AK
用户头像
AlexZhang
用户头像
0987654321
用户头像
defathom
用户头像
清风qwq
用户头像
HF_7
用户头像
平凡的人生不平凡的梦
用户头像
bxy
用户头像
fc235
用户头像
acwing_panjiaoshi
用户头像
bobo34
用户头像
come-on
用户头像
凤九

活动打卡代码 AcWing 3526. 素数

#include <bits/stdc++.h>

using namespace std;

const int N = 10010;

int n;
int primes[N], cnt;
bool st[N], T[N];

void get_primes(int n) {
    for (int i = 2;i <= n;i ++ ) {
        if (!st[i]) primes[cnt ++ ] = i, T[i] = true;

        for (int j = 0;i * primes[j] <= n;j ++ ) {
            st[i * primes[j]] = 1;

            if (i % primes[j] == 0) break;
        }
    }
}

int main() {
    get_primes(N - 1);
    while (cin >> n) {
        int t = 11;
        bool flag = 0;
        while (t < n) {
            if (T[t]) cout << t << " ", flag = 1;
            t += 10;
        }
        if (!flag) cout << "-1";
        cout << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3449. 数字根

#include <bits/stdc++.h>

using namespace std;

const int N = 1010;

char s[N];

bool check(int x) {
    return x / 10 == 0;
}

int fun(int x) {
    if (check(x)) return x;
    else {
        int t = 0;
        while (x) {
            t += x % 10;
            x /= 10;
        }
        return fun(t);
    }
}

int main() {
    while (cin >> s && s[0] != '0') {
        int t = 0;
        for (int i = 0;i < strlen(s);i ++ ) t += s[i] - '0';
        if (check(t)) cout << t << endl;
        else cout << fun(t) << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3589. 平方因子

#include <bits/stdc++.h>

using namespace std;

int n;

int main() {
    while (cin >> n) {
        bool flag = 0;
        for (int i = 2;i * i <= n;i ++ )
            if (n % (i * i) == 0) flag = 1;

        if (flag) puts("Yes");
        else puts("No");
    }
    return 0;
}


活动打卡代码 AcWing 3667. 切木棍

#include <bits/stdc++.h>

using namespace std;

int n;

int main() {
    while (cin >> n) {
        if (n % 2 != 0) puts("0");
        else cout << (n / 2 - 1) / 2 << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3596. a+b

#include <bits/stdc++.h>

using namespace std;

const int N = 1010;

char a[N], b[N];
int at[N], bt[N], ct[N];

int main() {
    while (cin >> a >> b) {
        memset (ct, 0, sizeof ct);
        memset (at, 0, sizeof at);
        memset (bt, 0, sizeof bt);
        int la = strlen(a), lb = strlen(b);
        for (int i = 0;i < la;i ++ ) at[la - i] = a[i] - '0';
        for (int i = 0;i < lb;i ++ ) bt[lb - i] = b[i] - '0';

        for (int i = 1;i <= max(la, lb);i ++ ) {
            ct[i] += at[i] + bt[i];
            if (ct[i] > 9) ct[i] -= 10, ct[i + 1] += 1;
        }

        int cnt = N - 1;
        while (!ct[cnt]) cnt -- ;
        for (int i = cnt;i >= 1;i -- ) cout << ct[i];
        cout << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3452. 进制转换

#include <bits/stdc++.h>

using namespace std;

const int N = 100010;

char s[N];

int main() {
    while (cin >> s) {
        int len = strlen(s), cnt = 0, res = 0;
        int flag = s[0] == '-';
        for (int i = len - 1;i >= 2 + flag;i -- ) {
            int t;
            if (s[i] < '0' || s[i] > '9') {
                if (s[i] >= 'A' && s[i] <= 'F' ) t = s[i] - 'A' + 10;
                else t = s[i] - 'a' + 10;
            }
            else t = s[i] - '0';
            res += t * pow (16, cnt ++ );
        }
        if (flag) cout << '-';
        cout << res << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3593. 统计单词

#include <bits/stdc++.h>

using namespace std;

const int N = 1010;

// char s[N];
string s;

int main() {
    getline(cin, s);
    // cin >> s;

    int res = 0, len = s.length();

    for (int i = 0;i < len;i ++ ) {
        if ((s[i] == ' ' && res) || s[i] == '.') {
            cout << res << " ";
            res = 0;
        }
        else if (s[i] != ' ') res ++ ;
        // cout << res << " ";
    }
    return 0;
}



#include <bits/stdc++.h>

using namespace std;

int y, m, d;
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool check(int x) {
    return x % 400 == 0 || (x % 4 == 0 && x % 100 != 0);
}

int main() {
    while (cin >> y >> m >> d) {
        bool is_r = check(y);

        for (int i = 0;i < m - 1;i ++ ) d += month[i];
        if (m > 2) d += is_r;

        cout << d << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3307. 破纪录者

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int T, n;
int a[N];

int main() {
    cin >> T;

    for (int Case = 1;Case <= T;Case ++ ) {
        cin >> n;

        for (int i = 1;i <= n;i ++ ) cin >> a[i];
        int res = 0, maxn = -1;

        for (int i = 1;i <= n;i ++ ) {
            if (a[i] > maxn) {
                if (i == n) res ++ ;
                else if (a[i] > a[i + 1]) res ++ ;
                maxn = a[i];
            }
        }

        printf ("Case #%d: %d\n", Case, res);
    }
    return 0;
}


活动打卡代码 AcWing 3474. 坠落的蚂蚁

#include <bits/stdc++.h>

using namespace std;

const int N = 110;

int n;

struct Node {
    int v, f;
}nd[N];

bool cmd (Node n1, Node n2) {
    if (n1.f == n1.f) return n1.v < n2.v;
    return n1.f > n2.f;
}

int main() {
    cin >> n;

    for (int i = 0;i < n;i ++ ) cin >> nd[i].v >> nd[i].f;

    sort (nd, nd + n, cmd);

    int flag = 1, l = 0, r = 0, mid;
    for (int i = 0;i < n;i ++ ) {
        if (flag == 1) {
            if (nd[i].f == 1) l ++ ;
            else if (nd[i].f == 0) flag = -1, mid = i;
        }
        else if (flag == -1) 
            if (nd[i].f == -1) r ++ ;
    }

    if (l > r) 
        for (int i = mid;i >= 0;i -- ) {
            if (nd[i].f == 1)
                r -- ;
            if (r == -1) {
                cout << 100 - nd[i].v << endl;
                break;
            }
        }
    else if (l < r) 
        for (int i = mid;i < n;i ++ ) {
            if (nd[i].f == -1) l -- ;
            if (l == -1) {
                cout << nd[i].v << endl;
                break;
            }
        }
    else cout << "Cannot fall!" << endl;

    return 0;
}