HDOJ 1236 with three methods using C++
来源:互联网 发布:视频加边框软件是什么 编辑:程序博客网 时间:2024/06/08 13:18
HDOJ 1236 with three methods using C++
Conventional Method: #include <iostream>#include<algorithm>#include <stdio.h>using namespace std; const int Max = 1010;struct Student{ charname[30]; intscore;}s[Max]; int score[10]; bool cmp(const Student&a, const Student &b){ if(a.score > b.score) return true; else if(a.score == b.score && strcmp(a.name, b.name)< 0) return true; else return false;} int main(){ intn, m, line, ps, pn, pass; while(scanf("%d",&n) && n) { scanf("%d%d",&m, &line); for(int i(0); i<m; ++i) scanf("%d", score+i); for(inti(0); i<n; ++i) { s[i].score= 0; scanf("%s",s[i].name); scanf("%d",&ps); for(intj(0); j<ps; ++j) { scanf("%d",&pn); s[i].score+= score[pn-1]; } } sort(s, s+n, cmp); for(pass=0;pass < n && s[pass].score >= line; ++pass); printf("%d\n",pass); for(inti(0); i<pass; ++i) printf("%s%d\n", s[i].name, s[i].score); } system("pause"); return0;} Operator Overloading Method: #include <iostream>#include <algorithm>#include <stdio.h>using namespace std; const int Max = 1010;struct Student{ charname[30]; intscore; friend bool operator <(const Student &a, const Student&b) { if(a.score > b.score) return true; else if(a.score == b.score && strcmp(a.name,b.name) < 0) return true; else return false; }}; Student s[Max];int score[10]; int main(){ intn, m, line, ps, pn, pass; while(scanf("%d",&n) && n) { scanf("%d%d",&m, &line); for(inti(0); i<m; ++i) scanf("%d",score+i); for(inti(0); i<n; ++i) { s[i].score= 0; scanf("%s",s[i].name); scanf("%d",&ps); for(intj(0); j<ps; ++j) { scanf("%d",&pn); s[i].score+= score[pn-1]; } } sort(s, s+n); for(pass=0;pass < n && s[pass].score >= line; ++pass); printf("%d\n",pass); for(inti(0); i<pass; ++i) printf("%s%d\n", s[i].name, s[i].score); } system("pause"); return0;} Function Object Method: #include <iostream>#include <algorithm>#include <stdio.h>using namespace std; const int Max = 1010;struct Student{ charname[30]; intscore;}; Student s[Max];int score[10]; class Comp{public: bool operator()(const Student &a, const Student &b) { if(a.score > b.score) return true; else if(a.score == b.score && strcmp(a.name,b.name) < 0) return true; else return false; }}; int main(){ intn, m, line, ps, pn, pass; while(scanf("%d",&n) && n) { scanf("%d%d",&m, &line); for(inti(0); i<m; ++i) scanf("%d",score+i); for(inti(0); i<n; ++i) { s[i].score= 0; scanf("%s",s[i].name); scanf("%d",&ps); for(intj(0); j<ps; ++j) { scanf("%d",&pn); s[i].score+= score[pn-1]; } } sort(s, s+n, Comp()); for(pass=0;pass < n && s[pass].score >= line; ++pass); printf("%d\n",pass); for(inti(0); i<pass; ++i) printf("%s%d\n", s[i].name, s[i].score); } system("pause"); return0;}
0 0
- HDOJ 1236 with three methods using C++
- Win32 Series - Using the Timer: Three Methods
- Fetching data with GET,POST methods by using NSURLConnection
- Three Discretization Methods
- Using OpenAPI with C++[1]
- Using OpenAPI with C++[2]
- Using OpenAPI with C++[3]
- Using C++ With Objective-C
- Using C++ With Objective-C
- Using C++ With Objective-C
- Using C++ With Objective-C
- Calling Java Class Methods from C with JNI
- Playing Around with Methods Overloading, C-language and Operators (1)
- HDOJ 5340 Three Palindromes
- HDOJ 5430 Three Palindromes
- Using Lua with C++: A short tutorial
- Not using parentheses with new [C++]
- Using libmemcached with C and C++
- 20160527关于工作
- iOS之百度云推送
- 勾股数
- 第二章 网络通信基本原理
- C# 压缩文件夹
- HDOJ 1236 with three methods using C++
- iOS多线程的初步研究(五)-- 如何让NSURLConnection在子线程中运行
- iOS多线程的初步研究(三)-- NSRunLoop
- 计算机网络概述
- iOS多线程的初步研究(四)-- NSTimer
- 164_动态控制绘制索引
- 物理层
- 1013. 数素数 (20)
- 165_根据位置处理触摸事件