梁力《程序设计与C语言》_第七章 结构体【完】

#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
using namespace std;
#define maxSize 101

输出不及格学生 P238 7.2
//typedef struct Student
//{
//    char name[maxSize];
//    int score;
//}Student;
//int main()
//{
//    int n;
//    cin>>n;
//    Student s[maxSize];
//    int cnt=0;
//    for(int i=0;i<n;i++)
//    {
//        cin>>s[i].name>>s[i].score;
//    }
//    for(int i=0;i<n;i++)
//        if(s[i].score<60)
//        {
//            cnt++;
//            cout<<s[i].name<<" "<<s[i].score<<endl;
//        }
//    cout<<"总的不及格人数"<<cnt<<endl;
//}
//
//
根据复数模的大小排序输出 P239 7.3
//typedef struct Complex
//{
//    float x,y;
//    float size;
//}Complex;
//bool cmp(Complex a,Complex b)
//{
//    return a.size>b.size;
//}
//int main()
//{
//    Complex arr[maxSize];
//    int n;
//    cin>>n;
//    for(int i=0;i<n;i++)
//    {
//        cin>>arr[i].x>>arr[i].y;
//        arr[i].size=sqrt(arr[i].x*arr[i].x+arr[i].y+arr[i].y);
//    }
//    sort(arr,arr+n,cmp);
//    for(int i=0;i<n;i++)
//    {
//        cout<<arr[i].x<<" "<<arr[i].y<<" "<<arr[i].size<<endl;
//    }
//}
//
//
//
统计被点击次数 P240 7.4
//typedef struct Web
//{
//    char name[maxSize];
//    int cnt;
//}Web;
//int main()
//{
//    Web w[maxSize];
//    for(int i=0;i<5;i++)
//    {
//        cin>>w[i].name;
//        w[i].cnt=0;
//    }
//    char x[maxSize];
//    for(int i=0;i<3;i++)
//    {
//        cin>>x;
//        for(int j=0;j<5;j++)
//        {
//            if(strcmp(x,w[j].name)==0)
//            {
//                w[j].cnt++;
//            }
//        }
//    }
//    for(int j=0;j<5;j++)
//    {
//        cout<<w[j].cnt<<endl;
//    }
//}
//

删除与字符串相同的所有字符 P242 7.5
//typedef struct String
//{
//    char ch[101];
//    int len;
//};
//void Delete(String s,String t)
//{
//    int i=0,j=0;
//    int x=i;
//    while(i<s.len)
//    {
//        int cnt=0;
//        while(j<t.len)
//        {
//            if(s.ch[i]==t.ch[j])
//            {
//                cnt++;
//                i++;
//                j++;
//            }
//            else
//                break;
//        }
//        //cout<<cnt;
//        if(cnt==t.len)
//        {
//            for(int c=i;c<s.len;c++)
//            {
//                s.ch[c-t.len]=s.ch[c];
//            }
//            s.len-=t.len;
//            i-=t.len;
//        }
//        else
//        {
//            i=++x;
//            j=0;
//        }
//    }
//    for(int i=0;i<s.len;i++)
//        cout<<s.ch[i];
//}
//int main()
//{
//    String s,t;
//    cin>>s.ch;
//    int i=0;
//    while(s.ch[i])
//    {
//        i++;
//    }
//    s.len=i;
//    cin>>t.ch;
//    int j=0;
//    while(t.ch[j])
//    {
//        j++;
//    }
//    t.len=j;
//    Delete(s,t);
//}


//
输出平均成绩最高的学生信息 P245 7.7
//typedef struct Student
//{
//    int sno;
//    char name[maxSize];
//    double score1,score2,score3,score;
//}Student;
//bool cmp(Student a,Student b)
//{
//    return a.score>b.score;
//}
//int main()
//{
//    Student s[maxSize];
//    for(int i=0;i<5;i++)
//    {
//        cin>>s[i].sno>>s[i].name>>s[i].score1>>s[i].score2>>s[i].score3;
//        s[i].score=(s[i].score1+s[i].score2+s[i].score3)/3;
//    }
//    sort(s,s+5,cmp);
//    cout<<s[0].sno<<s[0].name<<s[0].score1<<s[0].score2<<s[0].score3<<s[0].score<<endl;
//}
//
//
软件延时器 P248 7.9
//typedef struct Time
//{
//    int hour,min,sec;
//}Time;
//void update(Time &t)
//{
//    t.sec++;
//    if(t.sec>=60)
//    {
//        t.sec=0;
//        t.min++;
//        if(t.min>=60)
//        {
//            t.min=0;
//            t.hour++;
//        }
//    }
//}
//void display(Time t)
//{
//    cout<<t.hour<<" "<<t.min<<" "<<t.sec<<endl;
//}
//int main()
//{
//    struct Time t;
//    t.hour=0;
//    t.min=0;
//    t.sec=0;
//    for(;;)
//    {
//        update(t);
//        display(t);
//    }
//}
//
//
建立一个关于学生数据的链表 P251 7.10
//typedef struct LNode{
//    int num;
//    float score;
//    struct LNode *next;
//}LNode;
//int main()
//{
//    int x;
//    float y;
//    LNode *head=(LNode*)malloc(sizeof(LNode));
//    head->next=NULL;
//    LNode *p=head;
//    for(int i=0;i<5;i++)
//    {
//        cin>>x>>y;
//        LNode *q=(LNode*)malloc(sizeof(LNode));
//        q->num=x;
//        q->score=y;
//        p->next=q;
//        p=q;
//        p->next=NULL;
//    }
//    LNode *s=head;
//    while(s->next)
//    {
//        cout<<s->next->num<<" "<<s->next->score<<endl;
//        s=s->next;
//    }
//}
//
//
//
计算某日是这一年的第几天 P275 4
//typedef struct Time{
//    int year,month,day;
//}Time;
//int IsYeap(Time t)  //判断是不是闰年
//{
//    if(t.year%400==0||(t.year%100!=0&&t.year%4==0))
//    {
//        return 1;
//    }
//    return 0;
//}
//int month[13][2]={ //闰年2月有29天
//    0,0,
//    31,31,
//    28,29,
//    31,31,
//    30,30,
//    31,31,
//    30,30,
//    31,31,
//    31,31,
//    30,30,
//    31,31,
//    30,30,
//    31,31,
//};
//void NextDay(Time &t)
//{
//    t.day++;
//    if(t.day>month[t.month][IsYeap(t)])
//    {
//        t.day=1;
//        t.month++;
//        if(t.month>12)
//        {
//            t.month=1;
//            t.year++;
//        }
//    }
//}
//int buf[3001][13][32];
//int main()
//{
//    Time t;
//    Time t2;
//    cin>>t2.year>>t2.month>>t2.day;
//    t.year=0;
//    t.month=0;
//    t.day=0;
//    buf[t.year][t.month][t.day]=0;
//    int cnt=0;
//    while(t.year!=3001)
//    {
//        buf[t.year][t.month][t.day]=cnt;
//        NextDay(t);
//        cnt++;
//    }
//    int d=buf[t2.year][t2.month][t2.day]-buf[t2.year][1][1]+1;
//    cout<<d<<endl;
//}
//
//
//
输出成绩最高的学生 P275 5
//typedef struct Student
//{
//    int sno;
//    char name[maxSize];
//    char sex[maxSize];
//    int score1,score2,score3,score;
//}Student;
//int main()
//{
//    Student s[maxSize];
//    int max=0;
//    int maxp=0;
//    int cnt[maxSize];
//    int len=0;
//    for(int i=0;i<3;i++)
//    {
//        cin>>s[i].sno>>s[i].name>>s[i].sex>>s[i].score1>>s[i].score2>>s[i].score3;
//        s[i].score=s[i].score1+s[i].score2+s[i].score3;
//        if(s[i].score>max)
//        {
//            max=s[i].score;
//            maxp=i;
//        }
//        if(s[i].score1<60||s[i].score2<60||s[i].score3<60)
//        {
//            cnt[len++]=i;
//        }
//    }
//    cout<<s[maxp].sno<<" "<<s[maxp].name<<" "<<
//    s[maxp].sex<<" "<<s[maxp].score1<<" "<<s[maxp].score2<<" "<<s[maxp].score3<<" "
//    <<s[maxp].score<<endl;
//    for(int i=0;i<len;i++)
//    {
//        cout<<s[i].sno<<" "<<s[i].name<<" "<<s[i].sex<<" "<<s[i].score1<<" "<<s[i].score2
//        <<" "<<s[i].score3<<" "<<s[i].score<<endl;
//    }
//}
//
//
编写一个候选人得票的统计程序 P275 6
//typedef struct Candidate
//{
//    char name[maxSize];
//    int vote;
//}Candidate;
//int main()
//{
//    Candidate c[maxSize];
//    for(int i=0;i<5;i++)
//    {
//        cin>>c[i].name;
//        c[i].vote=0;
//    }
//    char x[maxSize];
//    while(1)
//    {
//        cin>>x;
//        int flag=0;
//        for(int i=0;i<5;i++)
//        {
//            if(strcmp(x,c[i].name)==0)
//            {
//                c[i].vote++;
//            }
//            else if(strcmp(x,"end")==0)
//            {
//                flag=1;
//                break;
//            }
//        }
//        if(flag==1)
//            break;
//    }
//    for(int i=0;i<5;i++)
//    {
//        cout<<c[i].name<<" "<<c[i].vote<<endl;
//    }
//}
//
//
//
将一个已生成的链表逆序 P276 9
//typedef struct LNode
//{
//    int data;
//    struct LNode *next;
//}LNode;
//
//int main()
//{
//    LNode *head=(LNode*)malloc(sizeof(LNode));
//    head->next=NULL;
//    LNode *p=head;
//    int t;
//    for(int i=0;i<5;i++)
//    {
//        cin>>t;
//        LNode *q=(LNode*)malloc(sizeof(LNode));
//        q->data=t;
//        p->next=q;
//        p=q;
//        q->next=NULL;
//    }
//    LNode *s0=head;
//    LNode *s1=s0->next;
//    LNode *s2=s1->next;
//    s1->next=NULL;   //!要加上这一句,否则会导致最后一个节点指向的不是NULL,输出时陷入死循环
//    while(s2)
//    {
//        LNode *r=s2->next;
//        s2->next=s1;
//        s0->next=s2;
//        s1=s2;
//        s2=r;
//    }
//    LNode *d=head;
//    while(d->next)
//    {
//        cout<<d->next->data<<" ";
//        d=d->next;
//    }
//}
//
//
//
凡报到“3”者,退出圈子 P276 10
//typedef struct LNode
//{
//    int data;
//    struct LNode *next;
//}LNode;
//int main()
//{
//    LNode *head=(LNode*)malloc(sizeof(LNode));
//    head->data=1;
//    LNode *p=head;
//    int len=1;
//    for(int i=2;i<=13;i++)
//    {
//        LNode *q=(LNode*)malloc(sizeof(LNode));
//        q->data=i;
//        p->next=q;
//        p=q;
//        len++;
//    }
//    p->next=head;
//    LNode *pre=head;
//    LNode *s=pre->next;
//    int cnt=0;
//    while(len>=3)
//    {
//        cnt++;
//        if(cnt==2)
//        {
//            // cout<<s->data<<" ";
//            pre->next=s->next;
//            cnt=0;
//            len--;
//        }
//        pre=pre->next;
//        s=pre->next;
//    }
//    cout<<s->data<<" "<<pre->data<<endl;
//}
//
//

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值