这道题用之前的二维数组的思路是不对的,因为这道题并不是对二维数组进行查找操作而是需要对二维数组进行遍历操作,因此我查看了柳神的代码发现柳神的思路清晰方法简便因此便按照那个思路重新写了一遍:
#include <iostream>
using namespace std;
int main() {
int n, max = -1, min = 101, score;
cin >> n;
string name, num, maxname, minname, maxnum, minnum;
for(int i = 0; i < n; i++){
cin >> name >> num >> score;
if(max < score){
max = score;
maxname = name;
maxnum = num;
}
if(min > score){
min = score;
minname = name;
minnum = num;
}
}
cout << maxname << " " << maxnum << endl << minname << " " << minnum;
return 0;
}
b1028与1004属于同类型,但是有一个点是涉及到字符串的比较问题,这个很简单,就像int类型的比较一样:
cin >> name >> birth;
if(birth >= "1814/09/06" && birth <= "2014/09/06"){
t++;
if(birth > last ){
last = birth;
lname = name;
}
if(birth < first ){
first = birth;
fname = name;
}
}
网友评论