头像

TK


访客:9691

离线:6天前


活动打卡代码 AcWing 1496. 普通回文数

TK
1个月前
#include <iostream>
#include <vector>

using namespace std;

vector<int> nums;

bool check() {
    for (int i = 0, j = nums.size() - 1; i < j; i++, j--)
        if (nums[i] != nums[j])
            return false;

    return true;
}

int main() {
    int n, b;
    cin >> n >> b;

    //n=0
    if (!n) nums.push_back(0);
    //n>0
    while (n) nums.push_back(n % b), n /= b;

    if (check()) puts("Yes");
    else puts("No");

    cout << nums.back();
    for (int i = nums.size() - 2; i >= 0; i--) cout << ' ' << nums[i];

    return 0;
}


活动打卡代码 AcWing 1590. 火星数字

TK
2个月前
#include <bits/stdc++.h>

using namespace std;

char digit[][5] = {
        "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec", "tam", "hel", "maa",
        "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou",
};

int get(string word) {
    for (int i = 0; i < 25; ++i)
        if (digit[i] == word) {
            if (i < 13) return i;
            else return (i - 12) * 13;
        }
    return -1;
}

int main() {
//    freopen("in.txt", "r", stdin);

    int n;
    cin >> n;
    getchar();
    while (n--) {
        string line;
        getline(cin, line);
        stringstream sin(line);
        if (line[0] <= '9') {
            int x;
            sin >> x;
            if (x < 13) cout << digit[x] << endl;
            else {
                cout << digit[x / 13 + 12];
                if (x % 13 == 0) cout << endl;
                else cout << ' ' << digit[x % 13] << endl;
            }
        } else {
            int res = 0;
            string word;
            while (sin >> word) res += get(word);
            cout << res << endl;
        }
    }
}


活动打卡代码 AcWing 838. 堆排序

TK
2个月前
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> h;
    while (n--) {
        int x;
        cin >> x;
        h.push(x);
    }
    while (m--) {
        int t = h.top();
        cout << t << ' ';
        h.pop();
    }

}


活动打卡代码 AcWing 1504. 火星颜色

TK
2个月前
#include <iostream>

using namespace std;

char get(int x) {
    if (x <= 9) return x + '0';
    else return x + 'A' - 10;
}

int main() {
//    freopen("in.txt", "r", stdin);
    int a[3];
    for (int i = 0; i < 3; ++i) cin >> a[i];
    cout << "#";
    for (int i = 0; i < 3; ++i) cout << get(a[i] / 13) << get(a[i] % 13);
    return 0;
}



活动打卡代码 AcWing 1482. 进制

TK
2个月前
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

int get(char c) {
    if (c <= '9' && c >= '0') return c - '0';
    return c - 'a' + 10;
}

ll cal(string n, ll r) {
    ll res = 0;
    for (int i = 0; i < n.size(); ++i) {
        char &c = n[i];
        if ((double) res * r + get(c) >= 1e16) return 1e16;
        res = res * r + get(c);
    }
    return res;
}

int main() {
//    freopen("in.txt","r",stdin);
    string a, b;
    cin >> a >> b;
    int tag, radix;
    cin >> tag >> radix;

    if (tag == 2) swap(a, b);

    ll target = cal(a, radix);

    ll l = 0, r = target + 1;
    for (int i = 0; i < b.size(); ++i) {
        char &c = b[i];
        l = max(l, (ll) get(c) + 1);
    }

    while (l < r) {
        ll mid = l + r >> 1;
        if (cal(b, mid) >= target) r = mid;
        else l = mid + 1;
    }

    if (cal(b,l) != target) puts("Impossible");
    else cout << l << endl;
}


活动打卡代码 AcWing 1492. 可逆质数

TK
2个月前
#include <iostream>

using namespace std;

typedef long long ll;

bool is_prime(int n) {
    if (n == 1) return false;
    for (int i = 2; i <= n / i; ++i)
        if (n % i == 0) return false;
    return true;
}

bool check(int n, int d) {
    if (!is_prime(n)) return false;

    ll res = 0;
    while (n) res = res * d + n % d, n /= d;
    return is_prime(res);
}

int main() {
    int n, d;
    while (cin >> n >> d, n >= 1) {
        if (check(n, d)) puts("Yes");
        else puts("No");
    }
}


活动打卡代码 AcWing 1501. 回文数

TK
2个月前
#include <iostream>
#include <vector>

using namespace std;

bool check(vector<int> &num) {
    for (int i = 0, j = num.size() - 1; i < num.size(); ++i, j--)
        if (num[i] != num[j]) return false;
    return true;
}

vector<int> add(vector<int> &a, vector<int> &b) {
    if (a.size() < b.size()) return add(b, a);
    vector<int> c;
    int t = 0;
    for (int i = 0; i < a.size(); ++i) {
        t += a[i];
        if (i < b.size()) t += b[i];
        c.push_back(t % 10);
        t /= 10;
    }
    if (t) c.push_back(t);
    return c;
}

int main() {
    string n;
    int k;
    cin >> n >> k;
    vector<int> a;
    for (int i = n.size() - 1; i >= 0; --i) a.push_back(n[i] - '0');

    int cnt = 0;
    if (!check(a)) {
        while (cnt < k) {
            cnt++;
            vector<int> b(a.rbegin(), a.rend());
            a = add(a, b);
            if (check(a)) break;
        }
    }

    for (int i = a.size() - 1; i >= 0; --i) cout << a[i];
    cout << endl;
    cout << cnt << endl;

    return 0;
}



活动打卡代码 AcWing 1500. 趣味数字

TK
2个月前
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> add(vector<int> &A, vector<int> &B) {
    if (A.size() < B.size()) return add(B, A);
    vector<int> C;
    int t = 0;
    for (int i = 0; i < A.size(); ++i) {
        t += A[i];
        if (i < B.size()) t += B[i];
        C.push_back(t % 10);
        t /= 10;
    }
    if (t) C.push_back(t);
    return C;
}

int main() {
    string a;
    cin >> a;
    vector<int> A;
    for (int i = a.size() - 1; i >= 0; --i) A.push_back(a[i] - '0');
    vector<int> C = add(A, A);
    vector<int> B = C;
    sort(B.begin(), B.end());
    sort(A.begin(), A.end());

    if (B == A) puts("Yes");
    else puts("No");

    for (int i = C.size() - 1; i >= 0; --i) cout << C[i];
    cout << endl;

    return 0;
}


活动打卡代码 AcWing 1481. 多项式乘积

TK
2个月前
#include <iostream>

using namespace std;

const int N = 1010;

double a[N], b[N], c[N << 1];

void input(double a[]) {
    int k;
    cin >> k;
    while (k--) {
        int n;
        double t;
        cin >> n >> t;
        a[n]=t;
    }
}

int main() {
//    freopen("in.txt","r",stdin);
    input(a), input(b);

    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            c[i + j] += b[i] * a[j];

    int k = 0;
    for (int i = 0; i < N << 1; ++i)
        if (c[i]) k++;

    cout << k;

    for (int i = N * 2 - 1; i >= 0; --i)
        if (c[i]) printf(" %d %.1lf", i, c[i]);

    return 0;
}




TK
2个月前
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    void deleteNode(ListNode* node) {
        node->val = node->next->val;
        node->next=node->next->next;
    }
};