zoukankan      html  css  js  c++  java
  • poj1547---结构数组

    题意:老师发给每个学生的橡皮泥相同,找出谁抢了谁的橡皮泥

    思路:结构数组存储每个学生的橡皮总量,和名字

    /*   结构数组存储用户信息--只放名称和体积
        while输入循环复用长宽高变量
        for循环求所有体积和
        求出平均值
        for循环遍历部分结构数组用输入的n决定次数
        遇到结构中小于平均值,将这个结构中的名字串
        付到vicim[]
        遇到大于的,将这个结构中名称付给bully[]
        printf("bully took clay from victim.
    ") */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    struct per{
        int volume;
        char name[10];
    };
    int main()
    {
        int n,i;
        struct per classStudentInfo[9];
        char bully[10],victim[10];
        while(scanf("%d",&n)!=EOF)
        {
            int len,wid,hei,th=0,temp;
            if(n==-1)
                break;
            temp=n;
            while(n--)
            {
                scanf("%d %d %d %s",&len,&wid,&hei,classStudentInfo[th].name);
                classStudentInfo[th].volume=len*wid*hei;
                th++;
            }
            int sumOfVol=0;
            for(i=0;i<temp;i++)
            {
                sumOfVol+=classStudentInfo[i].volume;
            }
            int averOfvol=sumOfVol/temp;
            for(i=0;i<temp;i++)
            {
                if(classStudentInfo[i].volume>averOfvol)
                    strcpy(bully,classStudentInfo[i].name);
                if(classStudentInfo[i].volume<averOfvol)
                    strcpy(victim,classStudentInfo[i].name);
            }
            printf("%s took clay from %s.
    ",bully,victim);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Python介绍
    产品经理知识体系之产品运营
    go rabbitmq延时队列
    docker安装PHP7.2及扩展
    关于js初始化对象的时间点的笔记
    gorm学习随笔
    Ubuntu18.04 安装PHP7.3
    PHP 冒泡、选择、插入排序
    MySQL 间隙锁的一些个人理解
    小程序插件 wx.navigateTo路由url设置
  • 原文地址:https://www.cnblogs.com/gabygoole/p/4486138.html
Copyright © 2011-2022 走看看