The 3n + 1 problem
中文題目:https://zerojudge.tw/ShowProblem?problemid=c039
#include <iostream>
using namespace std;
int main() {
int i, j;
while (cin >> i >> j) {
int mx = 0;
for (int n=min(i, j); n<=max(i, j); n++) {
int n1 = n, cnt = 1;
while (n1 != 1) {
if (n1 % 2) n1 = 3*n1 + 1;
else n1 /= 2;
cnt++;
}
mx = max(mx, cnt);
}
cout << i << " " << j << " " << mx << "\n";
}
return 0;
}
You can say 11
題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=21&page=show_problem&problem=1870#google_vignette中文題目:https://zerojudge.tw/ShowProblem?problemid=d235
#include <iostream>
using namespace std;
int main() {
string s;
while (cin >> s) {
if (s == "0") break;
int odd = 0, even = 0;
for (int i=0; i<s.size(); i++) {
if (i % 2) {
odd += s[i] - '0';
} else {
even += s[i] - '0';
}
}
if ((odd - even) % 11 == 0) {
cout << s << " is a multiple of 11.\n";
} else {
cout << s << " is not a mutiple of 11.\n";
}
}
return 0;
}
Bangla Numbers
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
int a[] = {10000000, 100000, 1000, 100};
string s[] = {"kuti", "lakh", "hajar", "shata"};
string ans;
string num2str(ll x) {
string s = "";
while (x) {
s += '0' + (x % 10);
x /= 10;
}
reverse(s.begin(), s.end());
return s;
}
void solve(ll x) {
if (x >= a[0]) {
solve(x / a[0]);
ans += " " + s[0];
x %= (int) a[0];
}
for (int i=0; i<4; i++) {
if (x / a[i] > 0) {
ans += " " + num2str(x / a[i]) + " " + s[i];
x %= a[i];
}
}
if (x > 0) ans += " " + num2str(x);
}
int main() {
ll N;
int Case = 1;
while (cin >> N) {
cout << " " << Case++ << ".";
if (N == 0) cout << " 0\n";
else {
ans = "";
solve(N);
cout << ans << "\n";
}
}
return 0;
}