Run ID:94066
提交时间:2024-10-19 17:57:33
#include<bits/stdc++.h> using namespace std; struct book{ string name; double price; }; book bk[11]; int main(){ int n; int max=0,maxid; int min = 10000000,minid; cin>>n; for(int i=1;i<=n;i++){ cin.get(); getline(cin,bk[i].name); cin>>bk[i].price; if(max<bk[i].price){ max = bk[i].price; maxid = i; //记录最大值所在的下标; } if(min>bk[i].price){ min = bk[i].price; minid = i; //记录最小值所在的下标; } } printf("%.2lf,",bk[maxid].price); cout<<bk[maxid].name<<endl; printf("%.2lf,",bk[minid].price); cout<<bk[minid].name<<endl; }