作业参考

第一次发,有错误请大佬们批评指正,如果喜欢别忘记点赞评论一波

第一题
#include<iostream>  
using namespace std;
struct ssd { int id; string name; char sex; int score;}e[5];
int main() {
    for (int i = 0; i < 5; i++)
    {
        cout << "Please input the ID:" << endl;
        cin >> e[i].id;
        cout << "Please input the name:" << endl;
        cin >> e[i].name;
        cout << "Please input the sex:" << endl;
        cin >> e[i].sex;
        cout << "Please input the score:" << endl;
        cin >> e[i].score;
    }
    for (int i = 0; i < 5; i++){
        cout << e[i].id<<" ";
        for (int x = 0; x <e[i].name.size(); x++){
            cout << e[i].name[x];
        }
        cout << " "<<e[i].sex << " " << e[i].score<<endl;
    }
    cout << "Please input the name you want delete:\n";
    string jk;
    int lpl = 0;
    cin >> jk;
    for (int i = 0; i < 5; i++){
        int cx = 0;
        for (int j = 0; j < jk.size(); j++) {
            if (jk[j] != e[i].name[j]) {
                cx = 1;
                break;
            }
        }
        if (cx == 0)
            lpl = i;
    }
    for (int i = 0; i < 5; i++) {
        if (i == lpl)
            continue;
        else
        {
            cout << e[i].id << " ";
            for (int x = 0; x < e[i].name.size(); x++) {
                cout << e[i].name[x];
            }
            cout << " " << e[i].sex << " " << e[i].score << endl;
        }
    }

}

第二题
#include<iostream>  
using namespace std;
struct ssd { int year; int month; int date; }e[5];
int fox(int year,int month, int data,int c) {
    if (month == 1)
        return data;
    if (month == 2)
        return data + 31;
    int counters2 = month % 2;
    if (counters2 != 0)//为奇数
    {
        int g = 0;
        if (c == 1)//闰年
            g = (month / 2) * 61 - 2 + data+1;
        else
            g=(month / 2) * 61 - 3+ data+1;
        return g;
    }
    else {//为偶数
        int h = 0;
        if(c==1)
            h = (month / 2) * 61 - 32 + data+1;
        else
            h= (month / 2) * 61 - 33 + data+1;
        return h;
    }
}
int main() {
    int counters = 0;//默认不是闰年
    cin >> e[0].year >> e[0].month >> e[0].date;
    if ((e[0].year % 4 == 0 && e[0].year % 100 != 0) || (e[0].year % 400 == 0))
        counters = 1;//为闰年
    int ssd =fox(e[0].year, e[0].month, e[0].date, counters);
    cout << ssd;
}


第三题
#include<iostream>  
using namespace std;
struct ssd { int year; int month; int date; }e[5];
int days(int year,int month, int data,int c) {
    if (month == 1)
        return data;
    if (month == 2)
        return data + 31;
    int counters2 = month % 2;
    if (counters2 != 0)//为奇数
    {
        int g = 0;
        if (c == 1)//闰年
            g = (month / 2) * 61 - 2 + data+1;
        else
            g=(month / 2) * 61 - 3+ data+1;
        return g;
    }
    else {//为偶数
        int h = 0;
        if(c==1)
            h = (month / 2) * 61 - 32 + data+1;
        else
            h= (month / 2) * 61 - 33 + data+1;
        return h;
    }
}
int main() {
    int counters = 0;//默认不是闰年
    cin >> e[0].year >> e[0].month >> e[0].date;
    if ((e[0].year % 4 == 0 && e[0].year % 100 != 0) || (e[0].year % 400 == 0))
        counters = 1;//为闰年
    int ssd = days(e[0].year, e[0].month, e[0].date, counters);
    cout << ssd;
}

第四题
#include<iostream>  
using namespace std;
struct student { int number=0; string name; int grade=0;}e[5];
bool operator <(student a, student b) {
    if (a.grade == b.grade)
        return a.name < b.name;
    else
        return a.grade < b.grade;
}
/*10 liming 90
15 wanglei 60
13 xiaoming 30
19 laming 95
20 cxk 60*///输入样例
int main() {
    e[0] = { 10 ,"liming",90 };
    e[1] = { 15,"wanglei",60 };
    e[2] = { 13,"xiaoming",30 };
    e[3] = { 19,"laming",95 };
    e[4] = { 20,"cxk",60 };
    sort(e, e + 5);
    for (int x = 0; x <5 ; x++){
        cout << e[x].number << " " << e[x].grade<<endl;
    }
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值