zoukankan      html  css  js  c++  java
  • 问题 B: C语言11.2

    问题 B: C语言11.2

    时间限制: 1 Sec  内存限制: 32 MB
    献花: 141  解决: 107
    [献花][花圈][TK题库]

    题目描述

    定义一个结构体student,存储学生的学号、名字、性别和年龄,读入每个学生的所有信息,保存在结构体中,并输出。结构体student的定义如下:
    struct student {
        int num;
        char name[20];
        char sex;
        int age;
    };
    本题要求使用指向结构体数组的指针进行输入和输出。

    输入

    第一行有一个整数n,表示以下有n个学生的信息将会输入。保证n不大于20。
    以后的n行中,每一行包含对应学生的学号、名字、性别和年龄,用空格隔开。保证每一个人名都不包含空格且长度不超过15,性别用M和F两个字符来表示。

    输出

    有n行,每行输出一个学生的学号、名字、性别和年龄,用空格隔开。
    请注意行尾输出换行。

    样例输入

    3
    10101 LiLin M 18
    10102 ZhangFun M 19
    10104 WangMin F 20
    

    样例输出

    10101 LiLin M 18
    10102 ZhangFun M 19
    10104 WangMin F 20

    参考代码:

    #include<stdio.h>

    
    

    #include<string>

    
    

    #include<vector>

    
    

    #include<iostream>

    
    

    using namespace std;

    
    
    
    
    

    struct student{

    
    

             int num;

    
    

             char name[20];

    
    

             char sex;

    
    

             int age;

    
    

    };

    
    

    int main(){

    
    

             int n;

    
    

             cin>>n;

    
    

             vector<student> stu(n);    //注意>后要空一格,stu后是()

    
    

             for(int i=0;i<n;i++){

    
    

                       cin>>stu[i].num>>stu[i].name>>stu[i].sex>>stu[i].age;

    
    

             }

    
    

             for(int i=0;i<n;i++){

    
    

                       cout<<stu[i].num<<" "<<stu[i].name<<" "<<stu[i].sex<<" "<<stu[i].age<<endl;

    
    

             }

             return 0;

    }

     
  • 相关阅读:
    RE最全面的正则表达式----字符验证
    Ajax tips(my_jquery_function.js)
    Python 分布式执行测试用例
    Python black + flake8 自动化规范代码
    JavaScript学习笔记-ES5
    pytest-assume 测试用例某一断言失败继续执行后面的代码
    pytest常用命令行
    [pretty_errors] Prettifies Python exception output to make it legible
    requests-html
    Python 类 继承与重写
  • 原文地址:https://www.cnblogs.com/zhhjthing/p/7845986.html
Copyright © 2011-2022 走看看