【入门1】顺序结构
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << "Hello,World!" << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << " * " << endl;
cout << " *** " << endl;
cout << "*****" << endl;
cout << " *** " << endl;
cout << " * " << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
cout << a + b << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
char c;
cin >> c;
cout << " " << c << " " << endl;
cout << " " << c << c << c << " " << endl;
cout << c << c << c << c << c << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
cout << a * b << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
char c;
cin >> c;
cout << (char)(c - 32) << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
reverse(s.begin(), s.end());
cout << s << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
double a, b;
cin >> a >> b;
printf("%.3f\n", a / b);
cout << b * 2 << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main ()
{
double a, b, c;
cin >> a >> b >> c;
double p = (a + b + c) / 2;
double ans = sqrt(p * (p - a) * (p - b) * (p - c));
printf("%.1f", ans);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main () {
int s, v;
cin >> s >> v;
int t = (s + v - 1) / v + 10;
int n = 24 * 60 + 8 * 60 - t;
if (n >= 24 * 60) {
n -= 24 * 60;
}
int hr = n / 60;
int mt = n % 60;
if (hr < 10 && mt < 10) {
cout << "0" << hr << ":0" << mt << endl;
}else if (hr < 10 && mt > 10) {
cout << "0" << hr << ":" << mt << endl;
}else if (hr > 10 && mt < 10) {
cout << hr << ":0" << mt << endl;
}else {
cout << hr << ":" << mt << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const double pi = 3.14;
const int tv = 20000;
int main () {
int h, r;
cin >> h >> r;
double v = pi * r * r * h;
int ans = (tv + v - 1) / v;
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main () {
int a, b;
cin >> a >> b;
int m = a * 10 + b;
cout << m / 19 << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main () {
int h1, m1, h2, m2;
cin >> h1 >> m1 >> h2 >> m2;
int ans = h2 * 60 + m2 - h1 * 60 - m1;
cout << ans / 60 << " " << ans % 60 << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main () {
double a, b, c;
cin >> a >> b >> c;
cout << a * 0.2 + b * 0.3 + c * 0.5 << endl;
return 0;
}
【入门2】分支结构
#include<bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
if (T == 1) {
// 粘贴问题 1 的主函数代码,除了 return 0
cout << "I love Luogu!";
} else if (T == 2) {
// 粘贴问题 2 的主函数代码,除了 return 0
cout << 2 + 4 << " " << 10 - 2 - 4;
} else if (T == 3) {
// 请自行完成问题 3 的代码
cout << 14 / 4 << endl;
cout << 14 - 14 % 4 << endl;
cout << 14 % 4 << endl;
} else if (T == 4) {
// 请自行完成问题 4 的代码
cout << 500.0 / 3 << endl;
} else if (T == 5) {
// 请自行完成问题 5 的代码
cout << (260 + 220) / (12 + 20) << endl;
} else if (T == 6) {
// 请自行完成问题 6 的代码
double a = 6, b = 9;
double c = sqrt(a * a + b * b);
cout << c << endl;
} else if (T == 7) {
// 请自行完成问题 7 的代码
cout << 110 << endl;
cout << 110 - 20 << endl;
cout << 0 << endl;
} else if (T == 8) {
// 请自行完成问题 8 的代码
int r = 5;
double pi = 3.141593;
cout << 2 * pi * r << endl;
cout << r * r * pi << endl;
cout << 4.0 / 3 * pi * r * r * r << endl;
} else if (T == 9) {
// 请自行完成问题 9 的代码
cout << (((1 + 1) * 2 + 1) * 2 + 1) * 2 << endl;
} else if (T == 10) {
// 请自行完成问题 10 的代码
cout << 9 << endl;
} else if (T == 11) {
// 请自行完成问题 11 的代码
cout << 100.0 / (8 - 5) << endl;
} else if (T == 12) {
// 请自行完成问题 12 的代码
cout << 'M' - 'A' + 1 << endl;
cout << char('A' - 1 + 18) << endl;
} else if (T == 13) {
// 请自行完成问题 13 的代码
int r1 = 4, r2 = 10;
double pi = 3.141593;
double v = 4.0 / 3 * pi * r1 * r1 * r1 + 4.0 / 3 * pi * r2 * r2 * r2;
v = pow(v, 1.0 / 3); //因为C++没有开立方根的函数,求它的三分之一次方可以达到同样的效果。
printf("%.0lf\n",v);
} else if (T == 14) {
// 请自行完成问题 14 的代码
cout << 50 << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int m, t, s;
cin >> m >> t >> s;
if (t == 0) cout << 0 << endl;
else cout << max(0, m - ((s + t - 1) / t)) << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
// f1 是小A态度,0 为不喜欢, 1 为喜欢
// 同理,f2 是 UIM, f3 是八尾勇,f4 是正妹
int f1 = 0, f2 = 0, f3 = 0, f4 = 0;
// t1 表示是否满足条件 1, t1 = 1 表示满足,0 为不满足
int t1 = 0, t2 = 0;
int x;
cin >> x;
if (x % 2 == 0) t1 = 1;
if (x >= 4 && x <= 12) t2 = 1;
if (t1 && t2) f1 = 1;
if (t1 || t2) f2 = 1;
if ((t1 == 1 && t2 == 0) || (t1 == 0 && t2 == 1)) f3 = 1;
if (t1 == 0 && t2 == 0) f4 = 1;
cout << f1 << " " << f2 << " " << f3 << " " << f4 << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
// 判断闰年方法:是4的倍数但不是100的倍数,或者是400的倍数。
int is_run(int y) {
if ((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0)) return 1;
return 0;
}
int main() {
int y;
cin >> y;
cout << is_run(y) << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
if (x == 1 || x == 0) {
printf("Today, I ate %d apple.", x);
}else {
printf("Today, I ate %d apples.", x);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
// n * 5 > n * 3 + 11
// 则本地,解得 n = 6
int n;
cin >> n;
if (n >= 6) {
cout << "Luogu" << endl;
}else {
cout << "Local" << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
double m, h, bmi;
cin >> m >> h;
bmi = m / (h * h);
if (bmi < 18.5) cout << "Underweight" << endl;
else if (bmi < 24) cout << "Normal" << endl;
else cout << bmi << endl << "Overweight" << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a > b) swap(a, b);
if (a > c) swap(a, c);
if (b > c) swap(b, c);
// swap 是交换函数,将 a 和 b 的值交换
cout << a << " " << b << " " << c << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int days[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool is_run(int y) {
if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) return true;
return false;
}
int main() {
int y, m;
cin >> y >> m;
if (is_run(y)) days[2] = 29;
else days[2] = 28;
cout << days[m] << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int a, b;
int ans1 = 0, ans2 = 0;
for (int i = 1; i <= 7; ++ i) {
cin >> a >> b;
int t = a + b;
if (t > 8 && t > ans2) {
ans1 = i;
ans2 = t;
}
}
cout << ans1 << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 1e9 + 5;
for (int i = 0; i < 3; ++ i) {
int a, b;
cin >> a >> b;
ans = min(ans, ((n + a - 1) / a) * b);
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a > b) swap(a, b);
if (a > c) swap(a, c);
if (b > c) swap(b, c);
if (a + b <= c) cout << "Not triangle" << endl;
if (a + b > c && a * a + b * b == c * c) cout << "Right triangle" << endl;
if (a + b > c && a * a + b * b > c * c) cout << "Acute triangle" << endl;
if (a + b > c && a * a + b * b < c * c) cout << "Obtuse triangle" << endl;
if (a + b > c && (a == b || b == c)) cout << "Isosceles triangle" << endl;
if (a + b > c && a == b && a == c && b == c) cout << "Equilateral triangle" << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
double ans = 0;
int x;
cin >> x;
ans += min(x, 150) * 0.4463;
x -= min(x, 150);
ans += min(x, 250) * 0.4663;
x -= min(x, 250);
ans += x * 0.5663;
printf("%.1lf", ans);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int x, n;
cin >> x >> n;
int ans = 0;
if (n >= 8 - x) {
n -= 8 - x;
ans += max(0, 6 - x);
ans += n / 7 * 5;
ans += min(n % 7, 5);
}else {
ans = min(5, n);
}
cout << ans * 250 << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
// 求 a, b 最大公约数
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a > b) swap(a, b);
if (a > c) swap(a, c);
if (b > c) swap(b, c);
cout << a / gcd(a, c) << "/" << c / gcd(a, c) << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 15;
int a[N];
int main() {
for (int i = 0; i < 10; ++ i) {
cin >> a[i];
}
int x;
cin >> x;
x += 30;
int ans = 0;
for (int i = 0; i < 10; ++ i) {
if (a[i] <= x) ++ ans;
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[5];
int main() {
cin >> a[0] >> a[1] >> a[2];
if (a[0] > a[1]) swap(a[0], a[1]);
if (a[0] > a[2]) swap(a[0], a[2]);
if (a[1] > a[2]) swap(a[1], a[2]);
string s;
cin >> s;
for (int i = 0; i < s.size(); ++ i) {
int t = s[i] - 'A';
cout << a[t] << " ";
}
cout << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string p = "0123456789X";
int main() {
string s;
cin >> s;
int ans = 0, t = 1, sz = s.size();
for (int i = 0; i < sz - 1; ++ i) {
if (s[i] == '-') continue;
ans += (s[i] - '0') * (t ++);
}
ans %= 11;
if (p[ans] == s[sz - 1]) cout << "Right" << endl;
else {
s[sz - 1] = p[ans];
cout << s << endl;
}
return 0;
}
【入门3】循环结构
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n;
int x = 1001;
for (int i = 0; i < n; ++ i) {
cin >> t;
if (x > t) {
x = t;
}
}
cout << x << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n;
int x = 1001;
while (-- n) {
cin >> t;
if (x >= t) x = t;
}
cout << x << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
double sum1 = 0, sum2 = 0, cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= n; ++ i) {
if (i % k == 0) {
sum1 += i;
++ cnt1;
}else {
sum2 += i;
++ cnt2;
}
}
printf("%.1lf %.1lf", sum1 / cnt1, sum2 / cnt2);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int cnt1 = n / k;
int cnt2 = n - cnt1;
double sum1 = cnt1 * (2 * k + k * (cnt1 - 1)) / 2;
double sum2 = n * (1 + n) / 2 - sum1;
printf("%.1lf %.1lf", sum1 / cnt1, sum2 / cnt2);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
int ans = 1;
while (x != 1) {
x /= 2;
++ ans;
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int tot = 1;
for (int i = n; i >= 1; -- i) {
for (int j = 1; j <= i; ++ j) {
if (tot < 10) cout << "0" << tot;
else cout << tot;
++ tot;
}
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
vector<int> add(vector<int> a, vector<int> b) {
vector<int> ret;
int len = min((int)a.size(), (int)b.size());
int at = 0, i = 0;
for (; i < len; ++ i) {
int t = a[i] + b[i] + at;
at = t / 10;
ret.push_back(t % 10);
}
while (i < (int)a.size()) {
int t = a[i] + at;
at = t / 10;
ret.push_back(t % 10);
++ i;
}
while (i < (int)b.size()) {
int t = b[i] + at;
at = t / 10;
ret.push_back(t % 10);
++ i;
}
while (at) {
ret.push_back(at % 10);
at /= 10;
}
return ret;
}
vector<int> mul(vector<int> a, vector<int> b) {
vector<int> ret(a.size() + b.size() + 5, 0);
for (int i = 0; i < a.size(); ++ i) {
for (int j = 0; j < b.size(); ++ j) {
ret[i + j] += a[i] * b[j];
}
}
for (int i = 0; i + 1 < ret.size(); ++ i) {
ret[i + 1] += ret[i] / 10;
ret[i] %= 10;
}
while (ret.size() > 1 && ret.back() == 0) ret.pop_back();
return ret;
}
vector<int> get(int x) {
vector<int> ans;
if (x == 0) {
ans.push_back(0);
return ans;
}
while (x) {
ans.push_back(x % 10);
x /= 10;
}
return ans;
}
vector<int> jie(int n) {
if (n == 1) return get(1);
return mul(get(n), jie(n - 1));
}
void printV(vector<int> t) {
for (int i = t.size() - 1; i >= 0; -- i) {
cout << t[i];
}
cout << endl;
}
int main() {
int n;
cin >> n;
vector<int> ans = get(0);
for (int i = 1; i <= n; ++ i) {
ans = add(ans, jie(i));
}
printV(ans);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
int ans = 0;
for (int i = 1; i <= n; ++ i) {
int t = i;
while (t) {
if (x == t % 10) ++ ans;
t /= 10;
}
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double sum = 0;
int ans = 0;
while (sum <= n) {
++ ans;
sum += 1.0 / ans;
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0, c = 1;
for (int i = 1; i <= n; i += c ++) {
for (int j = i; j <= min(n, i + c - 1); ++ j) ans += c;
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; ++ i) sum += i;
cout << sum << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int n) {
if (n <= 1) return false;
for (int i = 2; i <= sqrt(n); ++ i) {
if (n % i == 0) return false;
}
return true;
}
int main() {
int n;
cin >> n;
int sum = 0, cnt = 0;
vector<int> v;
for (int i = 2; ; ++ i) {
if (is_prime(i)) {
if (sum + i <= n) {
sum += i;
v.push_back(i);
++ cnt;
}else break;
}
}
for (int i = 0; i < v.size(); ++ i) {
cout << v[i] << endl;
}
cout << cnt << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 5;
bool isnp[MAXN];
vector<int> primes; // 质数表
void init(int n)
{
for (int i = 2; i <= n; i++)
{
if (!isnp[i])
primes.push_back(i);
for (int j = 0; j < primes.size(); ++ j)
{
int p = primes[j];
if (p * i > n)
break;
isnp[p * i] = 1;
if (i % p == 0)
break;
}
}
}
bool check(int x) {
string s;
while (x) {
char c = '0' + (x % 10);
x /= 10;
s += c;
}
for (int i = 0, j = s.size() - 1; i <= j; ++ i, -- j) {
if (s[i] != s[j]) return false;
}
return true;
}
int main() {
init(10000000);
vector<int> ans;
int a, b;
cin >> a >> b;
for (int i = 0; i < primes.size(); ++ i) {
int v = primes[i];
if (v >= a && v <= b && check(v)) ans.push_back(v);
}
for (int i = 0; i < ans.size(); ++ i) {
cout << ans[i] << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
double n, sum = 0, step = 2;
int cnt = 0;
cin >> n;
while (sum < n) {
sum += step;
++ cnt;
step *= 0.98;
}
cout << cnt << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int s = 0, n;
cin >> n;
while (n) {
s = s * 10 + n % 10;
n /= 10;
}
cout << s << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> f(n + 5);
f[1] = 1, f[2] = 1;
for (int i = 3; i <= n; ++ i) {
f[i] = f[i - 1] + f[i - 2];
}
printf("%.2lf", f[n]);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int mx = 0, mn = 1005;
for (int i = 0; i < n; ++ i) {
int x;
cin >> x;
mx = max(mx, x);
mn = min(mn, x);
}
cout << mx - mn << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0, last = -1, cur = 0;
for (int i = 0; i < n; ++ i) {
int x;
cin >> x;
if (x == last + 1) ++ cur;
else cur = 1;
ans = max(ans, cur);
last = x;
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; ++ i) {
if (n % i == 0) {
cout << n / i << endl;
break;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int tot = 1;
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < n; ++ j) {
if (tot < 10) {
cout << "0" << char('0' + tot);
}else cout << tot;
++ tot;
}
cout << endl;
}
cout << endl;
tot = 1;
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < n; ++ j) {
if (j < n - i - 1) {
cout << " ";
continue;
}
if (tot < 10) {
cout << "0" << char('0' + tot);
}else cout << tot;
++ tot;
}
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int n;
cin >> n;
for (int i = 0; i < n; ++ i) {
int t;
cin >> t;
v.push_back(t);
}
sort(v.begin(), v.end());
double sum = 0;
for (int i = 1; i < n - 1; ++ i) sum += v[i];
printf("%.2lf", sum / (n - 2));
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
printf("%ld\n%ld\n", N / 364L - 3L * max(1L, (N - 36400L) % 1092L ? (N - 36400L) / 1092L + 1L : (N - 36400L) / 1092L), max(1L, (N - 36400L) % 1092L ? (N - 36400L) / 1092L + 1L : (N - 36400L) / 1092L));
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int sum = 0, cur = 0;
vector<int> v;
for (int i = 0; i < 12; ++ i) {
int x;
cin >> x;
v.push_back(x);
}
for (int i = 0; i < 12; ++ i) {
cur += 300;
cur -= v[i];
if (cur < 0) {
cout << "-" << i + 1 << endl;
return 0;
}
int t = max(0, cur / 100) * 100;
cur -= t;
sum += t;
}
cout << sum * 1.2 + cur << endl;
return 0;
}
【入门4】数组
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N], ans[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++ i) {
cin >> a[i];
for (int j = i - 1; j >= 0; -- j) {
if (a[j] < a[i]) {
++ ans[i];
}
}
}
for (int i = 0; i < n; ++ i) {
cout << ans[i] << " ";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N];
int main() {
int i = 0;
while (1) {
cin >> a[i];
if (a[i] == 0) break;
++ i;
}
while (-- i >= 0) {
cout << a[i] << " ";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int n;
cin >> n;
v.push_back(n);
while (n != 1) {
if (n & 1) {
n = n * 3 + 1;
v.push_back(n);
}else {
n /= 2;
v.push_back(n);
}
}
for (int i = v.size() - 1; i >= 0; -- i) {
cout << v[i] << " ";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int a[N];
int main() {
int n, m;
cin >> n >> m;
while (m -- ) {
int l, r;
cin >> l >> r;
for (int i = l; i <= r; ++ i) {
a[i] ++;
}
}
int cnt = 0;
for (int i = 0; i <= n; ++ i) {
if (a[i] == 0) ++ cnt;
}
cout << cnt << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1E3 + 5;
int sc[N][3];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < 3; ++ j) {
cin >> sc[i][j];
}
}
int ans = 0;
for (int i = 0; i < n; ++ i) {
for (int j = i + 1; j < n; ++ j) {
int sum = 0, f = 1;
for (int k = 0; k < 3; ++ k) {
sum += sc[i][k] - sc[j][k];
if (abs(sc[i][k] - sc[j][k]) > 5) {
f = 0;
break;
}
}
if (f && abs(sum) <= 10) ++ ans;
}
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 25;
int a[N][N][N];
int main() {
int w, x, h;
cin >> w >> x >> h;
int q;
cin >> q;
while (q --) {
int x1, x2, y1, y2, z1, z2;
cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
for (int i = x1; i <= x2; ++ i) {
for (int j = y1; j <= y2; ++ j) {
for (int k = z1; k <= z2; ++ k) {
a[i][j][k] = 1;
}
}
}
}
int ans = 0;
for (int i = 1; i <= w; ++ i) {
for (int j = 1; j <= x; ++ j) {
for (int k = 1; k <= h; ++ k) {
if (a[i][j][k] == 0) ++ ans;
}
}
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 35;
int a[N];
int ans[8];
int main() {
int n;
cin >> n;
for (int i = 0; i < 7; ++ i) {
int x;
cin >> x;
a[x] = 1;
}
while (n --) {
int cnt = 0;
for (int i = 0; i < 7; ++ i) {
int x;
cin >> x;
if (a[x]) ++ cnt;
}
ans[cnt] ++;
}
for (int i = 7; i >= 1; -- i) cout << ans[i] << " ";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 45;
int n, a[N][N], x, y;
int main() {
cin >> n;
x = 0, y = n / 2;
for (int i = 1; i <= n * n; ++ i) {
a[x][y] = i;
int xt = (x - 1 + n) % n, yt = (y + 1) % n;
if (!a[xt][yt]) x = xt, y = yt;
else x = (x + 1) % n;
}
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < n; ++ j) {
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
char W[10][5][3]=//W[i][j][k]表示第i个数字的第j行的第k列,(手打累死了)
{
{//0
'X','X','X',
'X','.','X',
'X','.','X',
'X','.','X',
'X','X','X',
},
{//1
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
},
{//2
'X','X','X',
'.','.','X',
'X','X','X',
'X','.','.',
'X','X','X',
},
{//3
'X','X','X',
'.','.','X',
'X','X','X',
'.','.','X',
'X','X','X',
},
{//4
'X','.','X',
'X','.','X',
'X','X','X',
'.','.','X',
'.','.','X',
},
{//5
'X','X','X',
'X','.','.',
'X','X','X',
'.','.','X',
'X','X','X',
},
{//6
'X','X','X',
'X','.','.',
'X','X','X',
'X','.','X',
'X','X','X',
},
{//7
'X','X','X',
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
},
{//8
'X','X','X',
'X','.','X',
'X','X','X',
'X','.','X',
'X','X','X',
},
{//9
'X','X','X',
'X','.','X',
'X','X','X',
'.','.','X',
'X','X','X',
}
};
int n;
char s[110];
int main(){
cin>>n;//输入n
for(int i=0;i<n;i++){
cin>>s[i];//输入要打印的字符
}
for(int i=0;i<5;i++){//枚举每一行
for(int j=0;j<n;j++){//枚举每一个数字
for(int k=0;k<3;k++){//枚举每个数字的列
cout<<W[s[j]-'0'][i][k];//输出,因为s[j]为字符,所以要减去'0'
}
if(j!=n-1) cout<<'.';//如果最后一列,就不需要打印'.'
}
cout<<endl;//换行
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int c[15];
int main() {
int m, n;
cin >> m >> n;
for (int i = m; i <= n; ++ i) {
int t = i;
while (t) {
c[t % 10] ++;
t /= 10;
}
}
for (int i = 0; i < 10; ++ i) cout << c[i] << " ";
cout << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++ i) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < n; ++ i) {
int f = 0;
for (int j = 0; j < n; ++ j) {
if (i == j) continue;
if (f) break;
for (int k = j + 1; k < n; ++ k) {
if (i == k) continue;
if (a[i] == a[j] + a[k]) {
++ ans;
f = 1;
break;
}
}
}
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4;
int a[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++ i) {
cin >> a[i];
}
int ans = 1e6;
for (int i = m - 1; i < n; ++ i) {
int sum = 0;
for (int j = i - m + 1; j <= i; ++ j) {
sum += a[j];
}
ans = min(ans, sum);
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N];
int main() {
int s1, s2, s3;
cin >> s1 >> s2 >> s3;
for (int i = 1; i <= s1; ++ i) {
for (int j = 1; j <= s2; ++ j) {
for (int k = 1; k <= s3; ++ k) {
a[i + j + k] ++;
}
}
}
int cnt = 0, ans = 0;
for (int i = 1; i <= s1 + s2 + s3; ++ i) {
if (a[i] > cnt) {
cnt = a[i];
ans = i;
}
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int a[N];
int main() {
int n;
cin >> n;
while (n --) {
double x, y;
cin >> x >> y;
for (double i = 1; i <= y; ++ i) {
int id = x * i;
if (a[id] == 0) a[id] = 1;
else a[id] = 0;
}
}
for (int i = 1; ; ++ i) {
if (a[i] == 1) {
cout << i << endl;
break;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int main() {
int tot = 1, n;
cin >> n;
int i = 0, j = 0;
a[i][j] = 1;
while (tot < n * n) {
while (j + 1 < n && !a[i][j + 1]) a[i][++ j] = ++ tot;
while (i + 1 < n && !a[i + 1][j]) a[++ i][j] = ++ tot;
while (j - 1 >= 0 && !a[i][j - 1]) a[i][-- j] = ++ tot;
while (i - 1 >= 0 && !a[i - 1][j]) a[-- i][j] = ++ tot;
}
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < n; ++ j) {
printf("%3d", a[i][j]);
}
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[25][25];
int main() {
int n;
cin >> n;
a[0][0] = 1;
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= i; ++ j) {
a[i][j] = a[i - 1][j] + a[i - 1][j - 1];
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int s[105][105];
int n, m, k;
bool check(int x, int y) {
if (x < 0 || y < 0 || x >= n || y >= n) return false;
return true;
}
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= m + k; ++ i) {
int a, b;
cin >> a >> b;
-- a, -- b;
for (int x = -2; x <= 2; ++ x) {
for (int y = -2; y <= 2; ++ y) {
if ((i > m || abs(x) + abs(y) <= 2) && check(a + x, b + y)) {
s[a + x][b + y] ++;
}
}
}
}
int ans = 0;
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < n; ++ j) {
if (s[i][j] == 0) ++ ans;
}
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i = 0, cnt = 0;
while (cnt < n * n) {
int x;
cin >> x;
while (x --) {
if (cnt % n == 0 && cnt) cout << endl;
if (i % 2) cout << 1;
else cout << 0;
++ cnt;
}
++ i;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int ans[100000];
int main() {
char c, last = '0';
int cnt = 0, n = 0;
while (cin >> c){
++ n;
if (c == last) ans[cnt] ++;
else {
last = c;
ans[++ cnt] ++;
}
}
cout << sqrt(n) << " ";
for (int i = 0; i <= cnt; ++ i) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n;
char a[15][15],b[15][15],c[15][15],d[15][15];
bool work1()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[j][n-i+1]=a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(b[i][j]!=c[i][j])
return 0;
return 1;
}
bool work2()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[n-i+1][n-j+1]=a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(b[i][j]!=c[i][j])
return 0;
return 1;
}
bool work3()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[n-j+1][i]=a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(b[i][j]!=c[i][j])
return 0;
return 1;
}
bool work4()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[i][n-j+1]=a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(b[i][j]!=c[i][j])
return 0;
return 1;
}
bool work5()
{
work4();
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=b[i][j];
if(work1())
return 1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=b[i][j];
if(work2())
return 1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=b[i][j];
if(work3())
return 1;
return 0;
}
bool work6()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(b[i][j]!=c[i][j])
return 0;
return 1;
}
void work()
{
if(work1())
{
cout<<1;
return ;
}
if(work2())
{
cout<<2;
return ;
}
if(work3())
{
cout<<3;
return ;
}
if(work4())
{
cout<<4;
return ;
}
if(work5())
{
cout<<5;
return ;
}
if(work6())
{
cout<<6;
return ;
}
cout<<7;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
d[i][j]=a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>c[i][j];
work();
return 0; //完美的结束QAQ
}
【入门5】字符串
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); ++ i) s[i] = toupper(s[i]);
cout << s << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n;
cin >> s;
for (int i = 0; i < s.size(); ++ i) {
s[i] = (s[i] - 'a' + n) % 26 + 'a';
}
cout << s << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int x) {
if (x <= 1) return false;
for (int i = 2; i <= sqrt(x); ++ i) {
if (x % i == 0) return false;
}
return true;
}
int c[30];
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); ++ i) {
c[s[i] - 'a'] ++;
}
int mx = 0, mn = 101;
for (int i = 0; i < 26; ++ i) {
mx = max(mx, c[i]);
if (c[i])
mn = min(mn, c[i]);
}
int t = mx - mn;
if (is_prime(t)) {
cout << "Lucky Word" << endl;
cout << t << endl;
}else {
cout << "No Answer" << endl;
cout << 0 << endl;
}
return 0;
}
#include <iostream> //cin & cout 用iostream
#include <cstring> //memset & strlen 用cstring
#include <cstdio> //sscanf & sprintf 用cstdio
using namespace std;
int main(){
char a;//a用于存储运算符
int n,c,d;//n存储个数不解释,cd存储两个数字
char s[100],b[10];//s存储最终的字符串,b临时变量
cin>>n;
for(int i=0;i<n;i++){
cin>>b;//输入一串字符,有可能是运算符,也有可能是数字
if(b[0]>='a' && b[0]<='z'){
a=b[0];//如果是运算符就存入a,然后输入数字
cin>>c>>d;
}else{
sscanf(b,"%d",&c);//如果是数字就转换b为int存储到第一个数字
cin>>d;//然后输入剩下的第二个数字
}
memset(s,0,sizeof(s));//清空原有的字符串,防止长度判断错误
if(a=='a')//用sprintf格式化
sprintf(s,"%d+%d=%d",c,d,c+d);
else if(a=='b')
sprintf(s,"%d-%d=%d",c,d,c-d);
else if(a=='c')
sprintf(s,"%d*%d=%d",c,d,c*d);
cout<<s<<endl<<strlen(s)<<endl;//输出字符串和字符串长度
}
return 0;
}
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char s[10];
gets(s);
int n = strlen(s);
int ans = 0;
for(int i = 0; i < n; i ++)
{
if (s[i] >= 'A' && s[i] <= 'Z')
ans ++;
if (s[i] >= 'a' && s[i] <= 'z')
ans ++;
if (s[i] >= '0' && s[i] <= '9')
ans ++;
}
printf("%d",ans);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
int t;
cin >> t >> s;
while (t --) {
int op, a, b;
string st;
cin >> op;
if (op == 1) {
cin >> st;
s += st;
cout << s << endl;
}else if (op == 2) {
cin >> a >> b;
s = s.substr(a, b);
cout << s << endl;
}else if (op == 3) {
cin >> b >> st;
s.insert(b, st);
cout << s << endl;
}else if (op == 4) {
cin >> st;
int f = s.find(st);
if (f == s.size()) cout << -1 << endl;
else cout << f << endl;
}
}
return 0;
}
#include<cstdio>
#include<cstring>
#include <cctype>
char article[1000000+10];
char word[10+10];
int main(){
//获取输入
gets(word);
gets(article);
int art_len,wor_len;
art_len = strlen(article);
wor_len = strlen(word);
//全转为小写
for(int i=0;i<art_len;++i) article[i]=tolower(article[i]);
for(int i=0;i<wor_len;++i) word[i]=tolower(word[i]);
int locate=-1,sum=0;
int i,j;//循环变量
for(i=0;i<art_len;++i){
if(i==0 || article[i-1]==' '){//开头或者文章前一个字符为空格开始匹配
for(j=0;j<wor_len;j++){
if(article[i+j]!=word[j]) break;//不匹配跳出这一层循环
else continue;//匹配继续匹配下一个字符
}
}
else continue;//既不是开头前一个字符也不是空格 读取article下一个字符
if((j==wor_len && article[i+j]==' ') || (j==wor_len && (i+j)==art_len)){//刚好匹配一个单词或者匹配到末尾了
if(locate==-1) locate=i;
sum++;
}
}
if(sum!=0 && locate!=-1) printf("%d %d\n",sum,locate);
else printf("-1");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int ans;
string a;
int num[26]={1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4}; //26个字母打表需要按几次
int main()
{
getline(cin, a);
for(int i = 0; i < a.length(); i ++)
{
if(a[i] >= 'a' && a[i] <= 'z') ans += num[a[i] - 'a']; //不能写a[i]!=' ',因为还有'\n'和'\r'
if(a[i] == ' ') ans ++; //不能写else因为也有'\n'和'\r',这就是这个题的坑点,我交了好几次,欲哭无泪
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string s;
cin >> n >> s;
int ans = 0;
for (int i = 0; i + 1 < n; ++ i) {
if (s[i] == 'V' && s[i + 1] == 'K') {
++ ans;
s[i] = 'v', s[i + 1] = 'k';
}
}
for (int i = 0; i + 1 < n; ++ i) {
if (s[i] == s[i + 1]) {
++ ans;
break;
}
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
int b = 0, g = 0;
for (int i = 0; i < s.size(); ++ i) {
if (i + 2 < s.size()) {
if (s[i] == 'b' || s[i + 1] == 'o' || s[i + 2] == 'y') {
++ b;
}
}
if (i + 3 < s.size()) {
if (s[i] == 'g' || s[i + 1] == 'i' || s[i + 2] == 'r' || s[i + 3] == 'l') {
++ g;
}
}
}
cout << b << endl;
cout << g << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string reverse2(string s) {
int zeroCount = 0;
reverse(s.begin(), s.end());
for (int i = 0; i < s.size(); ++ i)
if (s[i] == 48) ++ zeroCount;
else break;
s.erase(s.begin(), s.begin() + zeroCount);
return (s != "" ? s : "0");
}
string deleteTail(string s) {
int zeroCount = 0;
for (int i = s.size() - 1; i >= 0; --i)
if (s[i] == 48) ++zeroCount;
else break;
s.erase(s.end() - zeroCount, s.end());
return (s != "" ? s : "0");
}
int main() {
string s;
cin >> s;
if (s[s.size() - 1] == '%') {
cout << reverse2(s.substr(0, s.size() - 1)) << "%" << endl;
return 0;
}
for (int i = 0; i < s.size(); ++ i) {
string left, right;
if (s[i] == '/') {
left = s.substr(0, s.find("/"));
right = s.substr(s.find("/") + 1);
cout << reverse2(left) << "/" << reverse2(right) << endl;
return 0;
}
if (s[i] == '.') {
left = s.substr(0, s.find("."));
right = s.substr(s.find(".") + 1);
cout << reverse2(left) << "." << deleteTail(reverse2(right)) << endl;
return 0;
}
}
cout << reverse2(s) << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
map<string, int> q;
int main() {
q["one"]=1;q["two"]=2;q["three"]=3;q["four"]=4;q["five"]=5;q["six"]=6;q["seven"]=7;q["eight"]=8;q["nine"]=9;q["ten"]=10;
q["eleven"]=11;q["twelve"]=12;q["thirteen"]=13;q["fourteen"]=14;q["fifteen"]=15;q["sixteen"]=16;q["seventeen"]=17;q["eighteen"]=18;q["nineteen"]=19;q["twenty"]=20;
q["a"]=1;q["both"]=2;q["another"]=1;q["first"]=1;q["second"]=2;q["third"]=3;
string s;
vector<int> v;
for (int i = 0; i < 6; ++ i) {
cin >> s;
if (q[s]) {
int k = q[s] * q[s] % 100;
if (k == 0) continue;
v.push_back(k);
}
}
if (v.size() == 0) v.push_back(0);
sort(v.begin(), v.end());
cout << v[0];
for (int i = 1; i < v.size(); ++ i) {
if (v[i] < 10) cout << 0;
cout << v[i];
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
int a = 1, b = 1;
for (int i = 0; i < s1.size(); ++ i) {
a = a * (s1[i] - 'A' + 1) % 47;
}
for (int i = 0; i < s2.size(); ++ i) {
b = b * (s2[i] - 'A' + 1) % 47;
}
if (a == b) cout << "GO" << endl;
else cout << "STAY" << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[3];char s1,s2;
int main()
{
while (scanf("%c:=%c;", &s1, &s2) == 2) {
a[s1 - 'a'] = s2 >= '0' && s2 <= '9' ? s2 - '0' : a[s2 - 'a']; //赋值语句简洁明了
}
printf("%d %d %d", a[0], a[1], a[2]);
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ff[26];//定义计数数组
int main()
{
int i,j,n,maxn=0;char a[81];
for(i=0;i<4;i++)
{
gets(a);//gets读入
n=strlen(a);
for(j=0;j<n;j++)if(a[j]>='A'&&a[j]<='Z')ff[a[j]-'A']++;//统计字符出现次数
}
for(i=0;i<26;i++)maxn=max(maxn,ff[i]);//最多次数(最高柱状图)
for(i=maxn;i>0;i--){
for(j=0;j<26;j++)
if(ff[j]>=i)printf("* ");else printf(" ");//模拟,是可以输出的就输出*,否则跳过
printf("\n");}//换行
for(i=0;i<26;i++)printf("%c ",i+'A');//输出a~z
}
【入门6】函数与结构体
#include<bits/stdc++.h>
using namespace std;
double dist(pair<double, double> a, pair<double, double> b) {
double x1 = a.first, y1 = a.second;
double x2 = b.first, y2 = b.second;
double dx = x1 - x2;
double dy = y1 - y2;
return sqrt(dx * dx + dy * dy);
}
int main() {
pair<double, double> a, b, c;
double tx, ty;
cin >> tx >> ty;
a = {tx, ty};
cin >> tx >> ty;
b = {tx, ty};
cin >> tx >> ty;
c = {tx, ty};
printf("%.2lf", dist(a, b) + dist(a, c) + dist(b, c));
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int x) {
if (x <= 1) return false;
for (int i = 2; i <= sqrt(x); ++ i) {
if (x % i == 0) return false;
}
return true;
}
int main() {
int n;
cin >> n;
vector<int> ans;
for (int i = 0; i < n; ++ i) {
int t;
cin >> t;
if (is_prime(t)) {
ans.push_back(t);
}
}
for (int i = 0; i < ans.size(); ++ i) {
cout << ans[i] << " ";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool is_run(int y) {
if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) {
return true;
}
return false;
}
int main()
{
int x, y;
vector<int> ans;
cin >> x >> y;
for (int i = x; i <= y; ++ i) {
if (is_run(i)) {
ans.push_back(i);
}
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); ++ i) {
cout << ans[i] << " ";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m;
double get(vector<int> t) {
sort(t.begin(), t.end());
double sum = 0;
for (int i = 1; i < m - 1; ++ i) {
sum += t[i];
}
return sum / (m - 2);
}
int main()
{
cin >> n >> m;
double ans = 0;
for (int i = 0; i < n; ++ i) {
vector<int> t;
for (int j = 0; j < m; ++ j) {
int v;
cin >> v;
t.push_back(v);
}
ans = max(ans, get(t));
}
printf("%.2lf", ans);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int jie(int x) {
if (x == 1) return 1;
return x * jie(x - 1);
}
int main()
{
int n;
cin >> n;
cout << jie(n) << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[1025][1025];
int main()
{
int n;
cin >> n;
n = 1 << n;
a[0][n + 1] = 1;
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= n; ++ j) {
a[i][j] = a[i - 1][j] ^ a[i - 1][j + 1];
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[1025][1025], n;
void f(int len, int x, int y) {
if (len == 2) {
a[x][y] = 1;
return;
}
for (int i = x; i < x + len / 2; ++ i) {
for (int j = y; j < y + len / 2; ++ j) {
a[i][j] = 1;
}
}
f(len / 2, x + len / 2, y);
f(len / 2, x + len / 2, y + len / 2);
f(len / 2, x, y + len / 2);
}
int main()
{
cin >> n;
n = 1 << n;
f(n, 0, 0);
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < n; ++ j) {
cout << (a[i][j] == 0) << " ";
}
cout << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct MyStruct
{
string a;
int b, c, d;
int sum = 0;
}q[1005];
int main()
{
int n; cin >> n;
for (int i = 0; i < n; i++)
{
cin >> q[i].a >> q[i].b >> q[i].c >> q[i].d;
}
for (int i = 0; i < n; i++)
{
q[i].sum =q[i].b + q[i].c + q[i].d;
}
int max = 0, ans = 0;
for (int i = 0; i < n; i++)
{
if (q[i].sum > max) {
max = q[i].sum;
ans = i;
}
}
cout << q[ans].a << " " << q[ans].b << " " << q[ans].c << " " << q[ans].d << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct eee {
int yuwen,shuxue,yingyu,zf;
string s;
};
int n;
eee a[1001];
int main() {
cin >> n;
for (int i = 1; i <= n; ++ i) {
cin >> a[i].s >> a[i].yuwen >> a[i].shuxue >> a[i].yingyu;
a[i].zf = a[i].yuwen + a[i].shuxue + a[i].yingyu;
}
for (int i = 1; i < n; ++ i)
for (int j = i + 1; j <= n; ++ j) {
if (a[i].s > a[j].s) {
swap(a[i].s, a[j].s);
swap(a[i].yuwen, a[j].yuwen);
swap(a[i].shuxue, a[j].shuxue);
swap(a[i].yingyu, a[j].yingyu);
}
}
for (int i = 1; i < n; ++ i) {
for (int j = i + 1; j <= n; ++ j) {
if(abs(a[i].yuwen - a[j].yuwen) <= 5 && abs(a[i].shuxue - a[j].shuxue) <= 5 && abs(a[i].yingyu - a[j].yingyu) <= 5 && abs(a[i].zf - a[j].zf) <= 10) {
cout << a[i].s << " " << a[j].s << endl;
}
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct node {
int id;//学号
double sc1, sc2;//学业成绩和素质拓展成绩
int score;//学业成绩和素质拓展成绩的和
double final_score;//综合分数
}a[1000];//结构体定义,由于本人习惯(懒),sc1和sc2定义成了double。
int main() {
int n;
cin >> n;
for(int i=0; i<n; i++) {
cin >> a[i].id >> a[i].sc1 >> a[i].sc2;
a[i].score = a[i].sc1 + a[i].sc2;
a[i].final_score = a[i].sc1 * 0.7 + a[i].sc2 * 0.3;//计算综合分数
}
for(int i=0; i<n; i++) {
if(a[i].score > 140 && a[i].final_score >= 80) {//一定看清题
cout << "Excellent" << endl;
}
else {
cout << "Not excellent" << endl;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; ++ i) {
if (n % i == 0) {
cout << n / i << endl;
break;
}
}
return 0;
}
#include <cstdio>
#include <algorithm>
using namespace std;
bool is_prime(int x)
{
for(int i = 2;i * i <= x;i++)
{
if(x % i == 0)
return false;
}
return true;
}
void write(int a)
{
if(a == 4)
{
printf("4=2+2\n");
return;
}
for(int i = 3;i + 2 <= a;i += 2)
{
if(is_prime(i) && 2 + i == a)
{
printf("%d=2+%d\n",a,i);
return;
}
}
for(int i = 3;i + 3 <= a;i += 2)
{
if(is_prime(i) && is_prime(a - i))
{
printf("%d=%d+%d\n",a,min(i,a - i),max(i,a - i));
return;
}
}
}
int n;
int main()
{
scanf("%d",&n);
for(int i = 4;i <= n;i += 2)
write(i);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 5;
bool isnp[MAXN];
vector<int> primes; // 质数表
void init(int n)
{
for (int i = 2; i <= n; i++)
{
if (!isnp[i])
primes.push_back(i);
for (int j = 0; j < primes.size(); ++ j)
{
int p = primes[j];
if (p * i > n)
break;
isnp[p * i] = 1;
if (i % p == 0)
break;
}
}
}
bool check(int x) {
string s;
while (x) {
char c = '0' + (x % 10);
x /= 10;
s += c;
}
for (int i = 0, j = s.size() - 1; i <= j; ++ i, -- j) {
if (s[i] != s[j]) return false;
}
return true;
}
int main() {
init(10000000);
vector<int> ans;
int a, b;
cin >> a >> b;
for (int i = 0; i < primes.size(); ++ i) {
int v = primes[i];
if (v >= a && v <= b && check(v)) ans.push_back(v);
}
for (int i = 0; i < ans.size(); ++ i) {
cout << ans[i] << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
long long x = 0, s = 0, n = 0;
while (cin >> x) {
++ n;
s += x;
}
cout << s * (long long)pow(2, n - 1) << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, ans = 1;
cin >> n;
for (int i = 1; i < n; ++ i) {
ans += 1;
ans *= 2;
}
cout << ans << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct Luogu {
string name;
int age, score;
} a[10];
int main () {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].name >> a[i].age >> a[i].score;
a[i].age++, a[i].score = a[i].score *6 / 5;
if (a[i].score > 600) a[i].score = 600;
cout << a[i].name << " " << a[i].age << " " << a[i].score << endl;
}
return 0;
}