MOOC程序设计期中考试1.8

来源:互联网 发布:移民澳大利亚知乎 编辑:程序博客网 时间:2024/04/28 21:43
#include <iostream>
#include <string>
using namespace std;
// 在此处补充你的代码
int main()
{
int t;
cin >> t;
Student s("Tom",12);
while( t-- ) {
int n;
cin >> n;
Student st;
for( int i = 0;i < n; ++i) {
st.Read();
st.Print();
}
cout << "****" << endl;
}
return 0;
}
输入
第一行是整数t,表明数据组数


在每组数据中,
第一行先是整数n(n<100),表示有n个学生。
接下来有n行,每行表示一个学生。先是一个无空格的字符串,表示姓名,然后是一个非负整数,表示学号。
姓名长度不超过100字符,学号小于1000。
输出
按照输入的顺序,输出每个学生的信息。先输出学号,再输出姓名,中间用单个空格隔开。
一组数据处理完后,要输出一行 "****"。
样例输入
2
3
Tom 12
Jack 20
Marry 89
2
Jade 78
White 76
样例输出
12 Tom
20 Jack
89 Marry
****
78 Jade
76 White
****
#include <iostream>#include <string>using namespace std;// 在此处补充你的代码class Student{public:int age,age1;string name,name1;Student::Student(string name_,int age_){name = name_;age = age_;}Student::Student(){}void Read(){cin>>name1;cin>>age1;}void Print(){cout<<age1<<" "<<name1<<endl;}};int main(){int t;cin >> t;Student s("Tom",12);while( t-- ){int n;cin >> n;Student st;for( int i = 0;i < n; ++i) {st.Read();st.Print();}cout << "****" << endl;}system("pause");return 0;}

0 0
原创粉丝点击