算法复健计划day1 字符串专题

Posted 中二病没有蛀牙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了算法复健计划day1 字符串专题相关的知识,希望对你有一定的参考价值。

好久没敲过题了,有点太拉了,为了保研机试,冲冲冲

字符串专题

ACWing1477
https://www.acwing.com/problem/content/1479/

#include <bits/stdc++.h>
using namespace std;

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

int main()
{
    string n;
    cin>>n;
    int sum = 0;
    for (int i =0;i < n.size();i++){
        sum += (n[i] -'0');
    }
    string strSum = to_string(sum);
    for(int i = 0;i < strSum.size(); i++){
        cout<<eng[strSum[i] - '0']<<" ";
    }
    return 0;
}

ACwing1478

#include <bits/stdc++.h>
using namespace std;


struct T
{
    int hh,mm,ss;
    T():hh(),mm(),ss(){}
    T(int x,int y,int z):hh(x),mm(y),ss(z){}
};


struct stu{
    string ID;
    string st,ed;
}st[105];

bool cmp1(stu a,stu b){
    return a.st < b.st;
}

bool cmp2(stu a,stu b){
    return a.ed > b.ed;
}

int main()
{
    int m;
    cin>>m;
    for(int i = 0;i < m; i++){
        cin>>st[i].ID>>st[i].st>>st[i].ed;
    }
    sort(st,st+m,cmp1);
    cout<<st[0].ID<<" ";
    sort(st,st+m,cmp2);
    cout<<st[0].ID<<endl;

}

Acwing1519

#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;

struct user{
    string id,p;
};

vector<user> ans;

char rep(char c){
    if(c == '1')
        return '@';
    if(c == '0')
        return '%';
    if(c == 'l')
        return 'L';
    if(c == 'O')
        return 'o';
    return c;
}

int main()
{
    int n;
    cin>>n;
    int m = 0;
    for (int i = 1;i <=n;i++)
    {
        user u;
        cin>>u.id>>u.p;
        int f = 0;
        for(int j =0;j < u.p.size();j++){
            char c = rep(u.p[j]);
            if(c!= u.p[j] ){
                u.p[j] = c;
                f = 1;
            }
        }
        if(f) {
            m++;
            ans.push_back(u);
        }
        
    }
    if(m == 0){
        if(n == 1)
            printf("There is %d account and no account is modified\\n",n);
        else 
            printf("There are %d accounts and no account is modified\\n",n);
    }
    else{
        cout<<m<<endl;
        for(auto v : ans){
            cout<<v.id<<" "<<v.p<<endl;
        }

    }
    
    return 0;
}

Acwing 1521

#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;

struct  stu
{
    string name,sex,id;
    int grade;
    stu(){}
    stu(string a,string b,string c,int d):name(a),sex(b),id(c),grade(d){}
};

vector<stu>girl,boy;
int main()
{
    int n;
    cin>>n;
    int cntM,cntF;
    cntM = cntF = 0;
    string name,sex,id;
    int gra;
    int ma = 0;
    int mi = 100;
    stu maxG,minB;
    while(n--){
        cin>>name>>sex>>id>>gra;
        if(sex == "F"){
            cntF++;
            if(gra > ma|| ma == 0){
                ma = max(ma,gra);
                maxG = stu(name,sex,id,gra);
            }
            
        }
        else {
            cntM++;
            if(gra < mi || mi == 100){
                mi = min(mi,gra);
                minB = stu(name,sex,id,gra);
            }
        }
    }
    if(cntF == 0 ) cout<<"Absent"<<endl;
    else cout<<maxG.name<<" "<<maxG.id<<endl;
    if(cntM == 0) cout<<"Absent"<<endl;
    else cout<<minB.name<<" "<<minB.id<<endl;
    if(cntF  == 0|| cntM == 0){
        cout<<"NA"<<endl;
    }
    else cout<<ma - mi<<endl;
    return 0;
}

以上是关于算法复健计划day1 字符串专题的主要内容,如果未能解决你的问题,请参考以下文章

[PLAN]暑期复健训练&其他东西

复健计划

专题采访高维视力复健体系创始人 两天看清2.0的四维六度空间集训法

机器学习算法专题(蓄力计划)二十实操代码MNIST 数据集

背包问题

片段(Java) | 机试题+算法思路+考点+代码解析 2023