Vito's Family
中文題目:https://zerojudge.tw/ShowProblem?problemid=a737
題解:#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int T, r;
cin >> T;
while (T--) {
cin >> r;
int s[r];
for (int i=0; i<r; i++) {
cin >> s[i];
}
sort(s, s+r);
int sum = 0;
for (int i=0; i<r; i++) {
sum += abs(s[i] - s[r/2]);
}
cout << sum << "\n";
}
return 0;
}
Hashmat the Brave Warrior
中文題目:https://zerojudge.tw/ShowProblem?problemid=a012
#include <iostream>
using namespace std;
int main() {
long long n1, n2;
while (cin >> n1 >> n2) {
cout << abs(n1 - n2) << "\n";
}
return 0;
}
Primary Arithmetic
中文題目:https://zerojudge.tw/ShowProblem?problemid=c014
#include <iostream>
using namespace std;
int main() {
int n1, n2;
while (cin >> n1 >> n2) {
int carry = 0, cnt = 0;
if (n1 == 0 && n2 == 0) break;
while (n1 > 0 || n2 > 0) {
int temp = n1%10 + n2%10 + carry;
if (temp >= 10) {
carry = temp / 10;
cnt++;
} else {
carry = 0;
}
n1 /= 10;
n2 /= 10;
}
if (cnt == 0) cout << "No carry operation.\n";
else if (cnt == 1) cout << "1 carry operation.\n";
else cout << cnt << " carry operations.\n";
}
return 0;
}