A 公式题
long long f[10010];
const int mod = 1e9 + 7;
void solve() {
f[1] = 1;
f[2] = 2;
for (int i = 3; i <= 1000; i++) {
f[i] = 2 * f[i - 1] + 3 * f[i - 2] + i;
f[i] %= mod;
// (a + b) % mod = (a % mod + b % mod) % mod
}
int n;
while (scanf("%d", &n), n) {
printf("%d\n", f[n]);
}
}
B 意大利青年的烦恼
char s[100010];
char res[100010];
void solve() {
scanf("%s", s);
int idx = 0;
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] == '4')
continue;
res[idx++] = s[i];
}
res[idx] = '\0';
if (idx == 0)
printf("YAMERO!\n");
else
printf("%s\n", res);
}
C 最大公约数
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
void solve() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", gcd(a, b));
}
D Fibonacci数列
int f[1000010];
const int mod = 10007;
int func(int n) {
if (f[n] != 0)
return f[n];
if (n == 1 || n == 2)
return 1;
int res = func(n - 1) + func(n - 2);
res %= mod;
f[n] = res;
return res;
}
void solve() {
f[1] = 1;
f[2] = 1;
int n;
scanf("%d", &n);
// (a + b) % mod = (a % mod + b % mod) %mod
// for (int i = 3; i <= n; i++) {
// f[i] = f[i - 1] + f[i - 2];
// f[i] %= mod;
// }
printf("%d\n", func(n));
}
E 走楼梯
int f[100];
void solve() {
f[1] = 1;
f[2] = 2;
int n;
scanf("%d", &n);
for (int i = 3; i <= n; i++) {
f[i] = f[i - 1] + f[i - 2];
}
printf("%d\n", f[n]);
}
F 杨辉三角
int f[100][100];
void solve() {
int n;
scanf("%d", &n);
f[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
f[i][j] = f[i - 1][j] + f[i - 1][j - 1];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
printf("%d ", f[i][j]);
}
printf("\n");
}
}
G 约数之和
void solve() {
int n;
scanf("%d", &n);
int res = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
res += i;
}
}
printf("%d\n", res);
}
H 数的阶乘
void solve() {
int n;
scanf("%d", &n);
int res = 1;
for (int i = 1; i <= n; i++) {
res *= i;
}
printf("%d\n", res);
}
I 数位五五
void solve() {
int a, b;
scanf("%d%d", &a, &b);
int res = 0;
for (int i = a; i <= b; i++) {
int x = i;
int sum = 0;
while (x) {
sum += x % 10;
x /= 10;
}
if (sum % 5 == 0)
res++;
}
printf("%d\n", res);
}
J The Biggest Water Problem
void solve() {
int n;
scanf("%d", &n);
do {
int sum = 0;
while (n) {
sum += n % 10;
n /= 10;
}
n = sum;
} while(n >= 10);
printf("%d\n", n);
}
K 水仙花数
void solve() {
int n;
scanf("%d", &n);
int nums[20], idx = 0;
int t = n;
while (n) {
nums[idx++] = n % 10;
n /= 10;
}
int res = 0;
for (int i = 0; i < idx; i++) {
int sum = 1;
for (int j = 0; j < idx; j++) {
sum *= nums[i];
}
res += sum;
}
if (res == t) {
printf("yes\n");
}
else {
printf("no\n");
}
}
int isPrime(long long n) {
if (n <= 1)
return 0;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
void solve() {
int n;
scanf("%d", &n);
long long res = n;
n /= 10;
while (n) {
res = res * 10 + n % 10;
n /= 10;
}
if (isPrime(res))
printf("prime\n");
else
printf("noprime\n");
}
M 数字统计
void solve() {
int l, r;
scanf("%d %d", &l, &r);
int res = 0;
for (int i = l; i <= r; i++) {
int x = i;
while(x) {
int t = x % 10;
x /= 10;
if (t == 2) {
res++;
}
}
}
printf("%d\n", res);
}
N 递归次数
int cnt = 0;
int fact(int n) {
cnt++;
if (n <= 0)
return 1;
return fact(n - 1) * n;
}
void solve() {
int n;
scanf("%d", &n);
fact(n);
printf("%d\n", cnt);
// printf("%d\n", n + 1);
}
O 兔子的序列
#include <math.h>
void solve() {
int n;
scanf("%d", &n);
int maxv = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
int t = sqrt(x);
if (t * t == x) {
continue;
}
if (x > maxv) {
maxv = x;
}
}
printf("%d\n", maxv);
}
标签:idx,int,res,代码,杨帆班,void,solve,scanf
From: https://www.cnblogs.com/zhi-qiu/p/17779689.html