zoukankan      html  css  js  c++  java
  • *1399甲流病人初筛

     1 #include<iostream>
     2 using namespace std;
     3 const float t=37.5;
     4 struct br{
     5     string name;
     6     float tw;
     7     int isks;
     8 };//结构体的定义 
     9 int n,s=0;
    10 struct br a[300];// 定义了一个类型为struct br的数组a 
    11 bool pd(struct br x)//注意这儿参数为结构体 
    12 {
    13     if(x.tw>=t&&x.isks)return true;
    14     else return false;
    15 }
    16 int main()
    17 {
    18     cin>>n;
    19     for(int i=0;i<n;i++)
    20     {
    21         cin>>a[i].name>>a[i].tw>>a[i].isks;
    22     }
    23     for(int i=0;i<n;i++)
    24     {
    25         if(pd(a[i]))
    26         {
    27         cout<<a[i].name<<endl;    
    28         s++;
    29         }
    30         
    31     }
    32     cout<<s;
    33     return 0;
    34 } 

    C++中结构体的声明和定义

    //定义一个结构体,类型为struct Student
    struct  Student     
    {
        string name;
        double eng;
        double ch;
    }; 
     
    //定义了一个结构体,类型为struct Student;且定义了一个结构体实例,名叫Stu
    10  struct  Student    
    11  {
    12      string name;
    13      double eng;
    14      double ch;
    15  }Stu; 
    16   
    17  //定义了无名的结构体,且定义了一个结构体实例,名叫Stu
    18  struct 
    19  {
    20      string name;
    21      double eng;
    22      double ch;
    23  }Stu; 
    24   
    25  //重定义结构体,类型为struct Student 或者是Stu
    26  typedef struct  Student  
    27  {
    28      string name;
    29      double eng;
    30      double ch;
    31  }Stu; 
    32   
    33  //重定义结构体,类型为Stu
    34  typedef struct  
    35  {
    36      string name;
    37      double eng;
    38      double ch;
    39  }Stu;
    40   

    如果用typedef则,Stu stu; 
    否则,struct Student stu; 

  • 相关阅读:
    Mysql的ONLY_FULL_GROUP_BY
    Redis报错“ OOM command not allowed when used memory > 'maxmemory' ”
    redis发布订阅客户端报错
    使用IDEA远程调试SpringBoot程序
    kafk学习笔记(一)
    Ubuntu中卸载node和npm并重装
    一些常用的类型转换
    一台电脑配置多个GigHub账号
    百度网盘文件直接下载方法(跳过每次需要启动百度网盘下载的方式)
    如何激活IDEA工具,亲测有效
  • 原文地址:https://www.cnblogs.com/tflsnoi/p/7967717.html
Copyright © 2011-2022 走看看