算法复健计划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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值