PAT乙级1004. 成绩排名 C++
2016-07-23 16:29
465 查看
一个简单的存储处理与读取的题目,并不难,但是没有很规范的写,应该写getter setter 方法的,嘿嘿,偷懒了,希望机智的小伙伴们不要这样。祝大家变成顺利!
#include <iostream> #include <string> using namespace std; class Score { public: string name; string number; unsigned score; void display(); };//类的结尾要写分号哦~ void Score::display() { cout<<name<<" "<<number<<endl; } int main() { int input_times=0;//用户输入的次数 cin>>input_times; Score* s=new Score[input_times]; //用户初始化数组 for(int i=0;i<input_times;i++) { cin>>s[i].name; cin>>s[i].number; cin>>s[i].score; } //寻找最好成绩和最差成绩下标 unsigned best_index=0; unsigned worest_index=0; for(int i=1;i<input_times;i++) { if(s[i].score<s[worest_index].score) { worest_index=i; } if(s[i].score>s[best_index].score) { best_index=i; } } //输出 s[best_index].display(); s[worest_index].display(); //释放资源 delete[] s; system("pause"); return 0; }
相关文章推荐
- 1019. General Palindromic Number (20)
- Leetcode 111. Minimum Depth of Binary Tree (Easy) (cpp)
- 【C语言】模拟实现strstr函数
- C++ const函数返回值必须为const引用
- leetcode_c++:栈:Flatten Nested List Iterator(341)
- C++ Primer 笔记(2)第二章 变量与基本类型
- leetcode_c++:栈: Verify Preorder Serialization of a Binary Tree(331 )
- 1092. To Buy or Not to Buy (20)
- leetcode_c++:栈:Remove Duplicate Letters(316 )
- vector::clear ,vector::crbegin (c++11),vector::crend(c++11)
- vector::cend (c++ 11)
- vector::cbegin (c++11)
- 大话设计模式12----外观模式
- C++ vector用法
- 并查集C++实现
- leetcode_c++:栈: Implement Queue using Stacks(232)
- c++ 在windwos上创建盘符,并且,监控盘符里面任一文件的变动事件
- 谈谈8年C++面向对象设计的经验体会
- C/C++头文件大全
- leetcode_c++:栈: Implement Stack using Queues(225)