头像

九頭竜_八一




离线:15天前


活动打卡代码 AcWing 1534. 字符串减法

#include<iostream>
#include<unordered_set>
using namespace std;

int main(){
    unordered_set<char> s;
    string s1, s2;
    getline(cin, s1);
    getline(cin, s2);
    for(int i = 0; i < s2.size(); i ++)
        s.insert(s2[i]);
    for(int i = 0; i < s1.size(); i ++)
        if(s.find(s1[i]) == s.end())
            cout << s1[i];
    return 0;
}


活动打卡代码 AcWing 1520. 男孩 vs 女孩

#include<iostream>
using namespace std;
int main(){
    string max_F_name, max_F_id, min_M_name, min_M_id;
    int max_F = -1 , min_M = 101;
    int n;
    cin >> n;
    while(n -- ){
        string name, gender, id;
        int score;
        cin >> name >> gender >> id >> score;
        if(gender == "F" && score > max_F){
            max_F_name = name;
            max_F_id = id;
            max_F = score;
        }
        if(gender == "M" && score < min_M){
            min_M_name = name;
            min_M_id = id;
            min_M = score;
        }
    }
    if(max_F == -1 || min_M == 101){
        if(max_F == -1)
            cout << "Absent" << endl;
        else
            cout << max_F_name << " " << max_F_id << endl;
        if(min_M == 101)
            cout << "Absent" << endl;
        else
            cout << min_M_name << " " << min_M_id << endl;
        cout << "NA";
    }
    else{
        cout << max_F_name << " " << max_F_id << endl;
        cout << min_M_name << " " << min_M_id << endl;
        cout << max_F - min_M;
    }
    return 0;
}



活动打卡代码 AcWing 1519. 密码

#include<iostream>
#include<vector>
using namespace std;

int main()
{
    vector<string> id, pwd;
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++ )
    {
        string _id, _pwd, tmppwd = "";
        cin >> _id >> _pwd;
        for(int j = 0;j < _pwd.size(); j ++)
            if(_pwd[j] == '1')
                tmppwd += "@";
            else if(_pwd[j] == '0')
                tmppwd += "%";
            else if(_pwd[j] == 'l')
                tmppwd += "L";
            else if(_pwd[j] == 'O')
                tmppwd += "o";
            else
                tmppwd += _pwd[j];
        if(tmppwd != _pwd)
            id.push_back(_id), pwd.push_back(tmppwd);
    }
    if(id.size() != 0){
        cout << id.size() << endl;
        for(int i = 0; i < id.size(); i ++ )
            cout << id[i] << " " << pwd[i] << endl;
    } 
    else
        if(n == 1)
            cout << "There is 1 account and no account is modified";
        else
            cout << "There are "<< n <<" accounts and no account is modified";

    return 0;
}


活动打卡代码 AcWing 1478. 签到与签出

#include<iostream>
using namespace std;

int main(){
    string open_id, open_time = "24:60:60", out_id, out_time = "00:00:00";
    int m;
    cin >> m;
    while(m -- ){
        string id, open, out;
        cin >> id >> open >> out;
        if(open < open_time)
        {
            open_id = id;
            open_time = open;
        }
        if(out > out_time)
        {
            out_id = id;
            out_time = out;
        }
    }
    cout << open_id << " " << out_id; 
    return 0;
}


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

#include<iostream>
using namespace std;
int main(){
    string s[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    string N;
    cin >> N;
    int sum = 0;
    for(int i = 0; i < N.size(); i ++ )
        sum += N[i] - '0';
    string ans = to_string(sum);
    for(int i = 0; i < ans.size(); i ++)
    {
        if(i == ans.size() - 1)
            cout << s[ans[i] - '0'];
        else
            cout << s[ans[i] - '0'] <<" ";
    }
    return 0;
}


活动打卡代码 AcWing 1473. A + B 格式

#include<iostream>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int c = a + b;
    string s = to_string(c);
    int len = s.size();
    int i = 0;
    if(s[0] == '-')
    {
        cout << s[0];
        i = 1;
    }
    bool flag = false;
    for(;i <= len;i++)
    {
        if((len - i) % 3 == 0 && len - i > 0 && flag)
            cout << ",";
        flag = true;
        cout << s[i];
    }
    return 0;
}


活动打卡代码 AcWing 154. 滑动窗口

#include<iostream>
#include<cstdio>


using namespace std;

const int N = 1e6 + 5;
int num[N], quene_max[N], quene_min[N], ans_max[N], ans_min[N];

int main(){
    int n, k;
    cin >> n >> k;
    for(int i = 0;i < n; i ++ )
        scanf("%d", &num[i]);
    ans_max[0] = 0;
    ans_min[0] = 0;
    quene_min[0] = 0;
    quene_max[0] = 0;
    int head1 = 0, tail1 = 1, head2 = 0, tail2 = 1;//head1, tail1标记quene_min队列, head2, tail2标记quene_max队列
    for(int i = 1; i < n; i ++ ){
        //最小值滑动窗口
        while(tail1 > head1 && i - quene_min[head1] + 1 > k)
            head1 ++ ;
        while(tail1 > head1 && num[i] <= num[quene_min[tail1 - 1]])  
            tail1 -- ;
        quene_min[tail1 ++ ] = i;
        ans_min[i] = quene_min[head1];
        //最大值滑动窗口
        while(tail2 > head2 && i - quene_max[head2] + 1 > k)
            head2 ++ ;
        while(tail2 > head2 && num[i] >= num[quene_max[tail2 - 1]])
            tail2--;
        quene_max[tail2 ++ ] = i;
        ans_max[i] = quene_max[head2];
    }
    for(int i = k - 1; i < n; i ++ )
        printf("%d ", num[ans_min[i]]);
    printf("\n");
    for(int i = k - 1; i < n; i ++ )
        printf("%d ", num[ans_max[i]]);
    return 0;
}


活动打卡代码 AcWing 830. 单调栈

#include<iostream>

using namespace std;

const int N = 1e5 + 5;

int st[N], top;

int main(){
    top = 0;
    int n;
    scanf("%d", &n);
    for(int i = 0;i < n; i ++ ){
        int x;
        scanf("%d", &x);
        while(top && st[top] >= x){
                top -- ;
        }
        if(top)
            printf("%d ", st[top]);
        else
            printf("-1 ");
        st[ ++ top] = x;
    }

    return 0;
}


活动打卡代码 AcWing 829. 模拟队列

#include<iostream>

using namespace std;

const int N = 1e5 + 5;
int quene[N], head, tail;

int main(){
    head =  0;
    tail = -1;

    int m;
    cin >> m;
    while(m -- ){
        string op;
        cin >> op;
        if(op == "push"){
            int x;
            cin >> x;
            quene[ ++ tail] = x;
        }
        else if(op == "pop")
            head ++ ;
        else if(op == "empty")
            if(tail >= head)
                printf("NO\n");
            else
                printf("YES\n");
        else if(op == "query")
            if(tail >= head)
                printf("%d\n", quene[head]);
    }
    return 0;
}


活动打卡代码 AcWing 828. 模拟栈

简单模拟

#include<iostream>

using namespace std;

const int N = 1e5 + 5;
int st[N], top;

int main(){
    top = -1;
    int m;
    cin >> m;
    while(m -- ){
        string op;
        cin >> op;
        if(op == "push"){
            int x;
            cin >> x;
            st[ ++ top] = x;
        }
        else if(op == "pop")
            top -- ;
        else if(op == "empty")
            if(top == -1) 
                printf("YES\n");
            else 
                printf("NO\n");
        else if(op == "query")
            if(top >= 0)
                printf("%d\n", st[top]);
    }

    return 0;
}