统一单位再判断
2024-09-16 09:23:54
发布于:云南
34阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
long long change(long long size,string t){ //统一单位
if(t == "B") return size;
else if(t == "KB") return size * 1000;
else if(t == "MB") return size * 1000 * 1000;
else if(t == "GB") return size * 1000 * 1000 * 1000;
}
int main() {
int n; cin >> n;
long long maxx = -1;
string ans,te;
long long curs;
for(int i = 1;i <= n;i++){
cin >> curs >> te;
long long cur = change(curs,te);
if(cur > maxx){
maxx = cur;
ans = te;
}
}
if (ans == "GB") cout << maxx / (1000 * 1000 * 1000) << " GB";
else if (ans == "MB") cout << maxx / (1000 * 1000) << " MB";
else if (ans == "KB") cout << maxx / 1000 << " KB";
else if (ans == "B") cout << maxx << " B";
return 0;
}
这里空空如也
有帮助,赞一个