头像

晓玲

重庆邮电大学




离线:5天前


活动打卡代码 AcWing 1477. 拼写正确

晓玲
2个月前
#include <bits/stdc++.h>
using namespace std;

string conver[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

int main() {
    string str;
    cin >> str;
    int n = 0 ;
    for (int i = 0; str[i]; i++)
        n += (str[i] - '0');
    string ans = to_string(n);
    for (int i = 0; ans[i]; i ++)
        cout << conver[ans[i] - '0'] << " ";
    return 0;
}


活动打卡代码 AcWing 458. 比例简化

晓玲
2个月前
#include <bits/stdc++.h>
using namespace std;

int main() {
    int A, B, L;
    int a, b;
    cin >> A >> B>> L;
    double d = 1e9;
    for (int i = 0; i <= L; i ++) {
        for (int j = 1; j <= L; j ++) {
            double x = (double) i / j;
            double X = (double) A / B;
            if (x >= X && x - X < d) {
                a = i, b = j;
                d = x - X;
            }
        }
    }
    cout << a << " " << b<< endl;
    return 0;
}


活动打卡代码 AcWing 445. 数字反转

晓玲
2个月前
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, st = 0;
    cin >> n;
    if (n < 0) {
        st = 1;
        n = -n;
    }
    string str = to_string(n);
    while (str.size() > 1 && str[str.size() - 1] == '0') str.pop_back();
    reverse(str.begin(), str.end());
    if (st) cout << "-";
    cout << str << endl;
    return 0;
}


活动打卡代码 AcWing 449. 质因数分解

晓玲
2个月前
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 2; ; i ++) {
        if (n % i == 0) {
            cout << n / i << endl;

            break;
        }
    }
    return 0;
}


活动打卡代码 AcWing 441. 数字统计

晓玲
2个月前
#include <bits/stdc++.h>
using namespace std;

int main() {
    int l, r;
    cin >> l >> r;
    int cnt = 0;
    for (int i = l; i <= r; i ++) {
        string str = to_string(i);
        for (int j = 0; j < str.size(); j ++)
            if (str[j] == '2')
                cnt ++;
    }
    cout << cnt << endl;
    return 0;
}


活动打卡代码 AcWing 312. 乌龟棋

晓玲
3个月前
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 41, M = 360;

int n, m;
int w[M];
int f[N][N][N][N];

int main()
{
    int b[5] = {0};
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i ++ ) scanf("%d", &w[i]);
    for (int i = 0; i < m; i ++ )
    {
        int t;
        scanf("%d", &t);
        b[t] ++ ;
    }

    for (int A = 0; A <= b[1]; A ++ )
        for (int B = 0; B <= b[2]; B ++ )
            for (int C = 0; C <= b[3]; C ++ )
                for (int D = 0; D <= b[4]; D ++ )
                {
                    int score = w[A + B * 2 + C * 3 + D * 4];
                    int &v = f[A][B][C][D];
                    v = score;
                    if (A) v = max(v, f[A - 1][B][C][D] + score);
                    if (B) v = max(v, f[A][B - 1][C][D] + score);
                    if (C) v = max(v, f[A][B][C - 1][D] + score);
                    if (D) v = max(v, f[A][B][C][D - 1] + score);
                }

    printf("%d\n", f[b[1]][b[2]][b[3]][b[4]]);
    return 0;
}



活动打卡代码 AcWing 1230. K倍区间

晓玲
3个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;
const int N = 100010;

int n, k;
LL s[N];
int cnt[N];

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i ++ )
    {
        scanf("%d", &s[i]);
        s[i] += s[i - 1];
    }

    LL res = 0;
    cnt[0] ++ ;
    for (int i = 1; i <= n; i ++ )
    {
        res += cnt[s[i] % k];
        cnt[s[i] % k] ++ ;
    }

    printf("%lld\n", res);
    return 0;
}



活动打卡代码 AcWing 425. 明明的随机数

晓玲
3个月前
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 110;

int n;
int q[N];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ ) scanf("%d", &q[i]);
    sort(q, q + n);
    int k = unique(q, q + n) - q;
    printf("%d\n", k);
    for (int i = 0; i < k; i ++ ) printf("%d ", q[i]);
    return 0;
}



活动打卡代码 AcWing 417. 不高兴的津津

晓玲
3个月前
#include <bits/stdc++.h>
using namespace std;

int main() {
    int ans = 0, day = 7, sum = 0;
    for (int i = 1; i <= 7; i ++) {
        int x, y;
        cin >> x >> y;
        if (x + y > 8) {
            if (x + y > sum) {
                sum = x + y;
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


活动打卡代码 AcWing 1402. 星空之夜

晓玲
3个月前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 110;
const double eps = 1e-6;

int n, m;
char g[N][N];
PII q[N * N];
int top;

double get_dist(PII a, PII b)
{
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

double get_hash()
{
    double sum = 0;
    for (int i = 0; i < top; i ++ )
        for (int j = i + 1; j < top; j ++ )
            sum += get_dist(q[i], q[j]);
    return sum;
}

char get_id(double key)
{
    static double hash[30];
    static int id = 0;
    for (int i = 0; i < id; i ++ )
        if (fabs(hash[i] - key) < eps)
            return i + 'a';
    hash[id ++ ] = key;
    return id - 1 + 'a';
}

void dfs(int a, int b)
{
    q[top ++ ] = {a, b};
    g[a][b] = '0';
    for (int x = a - 1; x <= a + 1; x ++ )
        for (int y = b - 1; y <= b + 1; y ++ )
        {
            if (x == a && y == b) continue;
            if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '1')
                dfs(x, y);
        }
}

int main()
{
    cin >> m >> n;
    for (int i = 0; i < n; i ++ ) cin >> g[i];

    for (int i = 0; i < n; i ++ )
        for (int j = 0; j < m; j ++ )
            if (g[i][j] == '1')
            {
                top = 0;
                dfs(i, j);
                char c = get_id(get_hash());
                for (int k = 0; k < top; k ++ )
                    g[q[k].x][q[k].y] = c;
            }

    for (int i = 0; i < n; i ++ ) cout << g[i] << endl;

    return 0;
}