64,684
社区成员
发帖
与我相关
我的任务
分享
#include <functional>
#include <iostream>
#include <queue>
using namespace std;
int main() { //优先队列的排列顺序为小的在队头
int N;
cin >> N;
for (int i=0;i<N;i++) {
priority_queue<int, vector<int>, greater<int> > q;
int x;
while (1) {
cin >> x;
if (x==0) break;
q.push(x);
}
int ans = 0;
while(q.size()>1) {
int a, b;
a = q.top();
q.pop();
b = q.top();
q.pop();
q.push(a+b);
ans += a+b;
}
cout << ans <<endl;
}
return 0;
}
#include <iostream>
#include <queue>
using namespace std;
int main() { //优先队列的排列顺序为小的在队头
int N;
cin >> N;
for (int i=0;i<N;i++) {
priority_queue<int, vector<int>, greater<int> > q;
int x;
while (1) {
cin >> x;
if (x==0) break;
q.push(x);
}
int ans = 0;
while(q.size()>1) {
int a, b;
a = q.top();
q.pop();
b = q.top();
q.pop();
q.push(a+b);
ans += a+b;
}
cout << ans <<endl;
}
return 0;
}
#include <functional>
#include <iostream>
#include <strstream>
#include <queue>
#include <string>
using namespace std;
int main() { //优先队列的排列顺序为小的在队头
int N;
cin >> N;
ostrstream so;
for (int i=0;i<N;i++) {
priority_queue<int, vector<int>, greater<int> > q;
int x;
while (1) {
cin >> x;
if (x==0) break;
q.push(x);
}
int ans = 0;
while(q.size()>1) {
int a, b;
a = q.top();
q.pop();
b = q.top();
q.pop();
q.push(a+b);
ans += a+b;
}
so << ans <<endl;
}
cout << so.str();
return 0;
}
//输入:
//2
//5 2 9 11 8 3 7 0
//2 1 4 5 7 3 4 9 0
//输出:
//120
//98
//