zoukankan      html  css  js  c++  java
  • C++数据结构结构体 new

    C++数据结构-结构体

    学生信息

    http://oj.61coding.cn/problem.php?cid=1028&pid=0

    #include<bits/stdc++.h>
    using namespace std;
    struct student{
         string name;
         char sex;
         int age;
         double weight;
    };
    int main(){
         student stu;
         cin >> stu.name >> stu.sex >> stu.age >> stu.weight;
         cout << stu.name <<" "<< stu.sex <<" "<< stu.age <<" ";
         cout << fixed << setprecision(1) << stu.weight << endl;
         return 0;
    }

    年龄排序

    http://oj.61coding.cn/problem.php?cid=1028&pid=1

    #include<bits/stdc++.h>
    using namespace std;
    struct stu{
        string name;
        string sex;
        int year,month;
    };
    const int MAXN = 110;
    stu a[MAXN];
     
    bool cmp(stu stu1,stu stu2){
        if(stu1.year!=stu2.year){
            return stu1.year>stu2.year; 
        }
        return stu1.month>stu2.month;
    }
    int main(){
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++)
              cin >> a[i].name >> a[i].sex >> a[i].year >> a[i].month;
        sort(a+1,a+n+1,cmp);
        for(int i = 1; i <= n; i++){
              cout<< a[i].name <<" "<< a[i].sex<<" ";
              cout<< a[i].year <<" "<< a[i].month<<endl;
        }
        return 0;
    }

    猴子选大王

    #include<bits/stdc++.h>
    using namespace std;
    int m,n;
    bool a[101];
    int main(){
        cin>>m>>n;
        int num=0,w=m,t=0;
        while(m>1){
            t++;
            if(a[t]==false){
                num++;
            }
            if(num==n){
                a[t]=true;
                num=0;
                m--;
            }
            if(t==w){
                t=0;
            }
        }
        for(int i=1;i<=w;i++){
            if(a[i]==false){
                cout<<i;
                break; 
            }
        } 
    }
    #include<bits/stdc++.h>
    using namespace std;
    int m,n;
    bool a[1001];
    int main(){
        cin>>m>>n;
        int num=0,w=m,t=0;
        int nn=n%m;
    if(nn==0){
    nn=m;
    }
    while(m>1){ t++; if(a[t]==false){ num++; } if(num==nn){ a[t]=true; num=0; m--; nn=n%m;
    if(nn==0){
    nn=m;
    }
    } if(t==w){ t=0; } } for(int i=1;i<=w;i++){ if(a[i]==false){ cout<<i; break; } } }
    #include<bits/stdc++.h>
    using namespace std;
    struct monkey{
        int num;
        int next;
    }a[1010]; 
    
    int main(){
        int n,k,count=0,remain,cur,pre;
        cin>>n>>k;
        for(int i=1;i<n;i++){
            a[i].num=i;
            a[i].next=i+1;
        }
        
        a[n].num=n;
        a[n].next=1;
        remain=n;
        cur=1;
        pre=n;
        while(remain>1){
            count++;
            if(count==k){
                a[pre].next=a[cur].next;
                remain--;
                count=0;
            }else{
                pre = cur;
            }
            cur=a[cur].next;
        }
        cout<<a[cur].num<<endl;
        return 0;
    }
    #include<bits/stdc++.h>
    using namespace std;
    struct monkey{
        int num;//当前猴子位置 
        int next;//下一个猴子位置 
    }a[1010]; 
    
    int main(){
        //n只猴子 报数到k时出圈  
        int n,k;
        //从0报数开始计数到count=k时出圈 remain当前还剩余可报数的猴子
        int count=0,remain;
        // 当前猴子位置和前一个猴子位置 当前出队,需要修改pre的next 
        int cur,pre;
        
        cin>>n>>k;
        for(int i=1;i<n;i++){//n-1个点建立循环链表 
            a[i].num=i;
            a[i].next=i+1;
        }
        //第n个点特殊处理 
        a[n].num=n;//第n个点建立循环链表 
        a[n].next=1;//第n个点建立循环链表
        
        remain=n;//默认剩余可以报数为n 
        
        int kk=k%remain;
        if(kk==0){
            kk=remain;
        }
        cur=1;//当前从第一个开始
        pre=n;//删除第一个使用 
        while(remain>1){//报数到k出圈 剩下最后一个猴子为止
            count++;//报数加1 
            if(count==kk){//报数到k的猴子出圈 
                a[pre].next=a[cur].next;//链表中删除当前猴子
                remain--;//出圈 猴子数减一 
                count=0;//从0开始重新报数 
                kk=k%remain;
                if(kk==0){
                    kk=remain;
                }
            }else{
                pre = cur;//记录当前猴子的前一个猴子位置 
            }
            cur=a[cur].next;//当前猴子的下一个位置 
        }
        cout<<a[cur].num<<endl;//剩余最后一个猴子的位置 
        return 0;
    }

    奖学金

    http://oj.61coding.cn/problem.php?cid=1028&pid=3

    #include<bits/stdc++.h>
    using namespace std;
    struct node{
        int num,chi,mat,eng,tot;
    };
    node a[311];
    bool cmp(node x,node y){
        if (x.tot !=y.tot){
            return x.tot>y.tot;
        }else if (x.chi!=y.chi){
                return x.chi>y.chi;
              } else return x.num<y.num;
    }
    int main(){
        int n;
    
        cin>>n;
        for (int i=1;i<=n;i++){
            cin>>a[i].chi>>a[i].mat>>a[i].eng;
            a[i].num=i;
            a[i].tot=a[i].chi+a[i].eng+a[i].mat;
        }
        sort(a+1,a+n+1,cmp);
        for (int i=1;i<=5;i++){
            cout<<a[i].num<<" "<<a[i].tot<<endl;
        }
        return 0;
    }

    桌面窗体重叠

    http://oj.61coding.cn/problem.php?cid=1028&pid=4

    #include<bits/stdc++.h>
    using namespace std;
    struct twindow{
        int left,right,top,bottom;
    };
    twindow wina,winb,tmp;
     
    twindow indata(){
        twindow tmp;
        cin >> tmp.left >> tmp.right >> tmp.top >> tmp.bottom;
        return tmp;
    }
     
    int main(){
    
        wina = indata();
        winb = indata();
        tmp.left = max(wina.left,winb.left);
        tmp.right = min(wina.right,winb.right);
        tmp.top = max(wina.top,winb.top);
        tmp.bottom = min(wina.bottom,winb.bottom);
        int s = (tmp.right - tmp.left) * (tmp.bottom - tmp.top);
        if((tmp.right <= tmp.left) || (tmp.bottom <= tmp.top)) s = 0;
        cout << s << endl;
        return 0;
    }
    纽扣机器人活动中心 从事机器人比赛、机器人等级考试、少儿scratch编程、信息学奥赛等研究学习。欢迎感兴趣的朋友交流 QQ:1187789228 http://www.61coding.cn/
  • 相关阅读:
    JavaScript数组方法
    模拟js数组indexOf方法
    js数组排序
    发布Exchange的SMTP,POP3服务器:ISA2006系列之十八
    用智能卡构建身份验证的马其诺防线:ISA2006系列之二十三
    Java与CSharp的相同与不同
    创建可传递的林信任,Active Directory系列之二十
    组策略指派Office2003分发,Active Directory系列之二十三
    发布Exchange的RPC以及RPC Over HTTPS:ISA2006系列之十九
    初步理解组策略,Active Directory系列之二十一
  • 原文地址:https://www.cnblogs.com/myeln/p/15707236.html
Copyright © 2011-2022 走看看