西北工业大学noj100题(C语言)
- 1.计算A+B
- 2.圆及圆球等的相关计算
- 3.计算成绩
- 4.找最大数
- 5.找幸运数
- 6.奖金发放
- 7.出租车费
- 8.是该年的第几天?
- 9.成绩转换
- 10.求建筑高度
- 11.多项式的猜想
- 12.奇特的分数序列
- 13.二分求根
- 14.级数和
- 15.整数位数
- 16.五猴分桃
- 17.计算π
- 18.完全数
- 19.两个整数之间所有的素数
- 20.最次方数
- 21.幸运数字“7”
- 22.韩信点兵
- 23.子序列的和
- 24.危险的组合
- 25.羊羊聚会
- 26.探索合数世纪
- 27.除法
- 28.粒子裂变
- 29.“1”的传奇
- 30.特殊整数
- 31.最小整数
- 32.发工资的日子
- 33.积分计算
- 34.获取指定二进制位
- 35.方差
- 36.亲和数
- 37.数据加密
- 38.循环移位
- 39.A+B II
- 40.高低交换
- 41.左上角
- 42.一维数组加法
- 43.二分查找
- 44.选择排序
- 45.左下角
- 46.冒泡排序
- 47.快速排序
- 48.边沿与内芯的差
- 49.右上角
- 50.平均值函数
- 51.特殊要求的字符串
- 53.字符串左中右
- 54.硬币测试
- 55.字符串复制
- 56.分离单词
- 57.找出数字
- 58.字符串逆序
- 59.字符串排序
- 60.删除字符
- 61.字符串加密编码
- 62.复数
AC自存
1.计算A+B
#include<stdio.h>
int main()
{
int A,B,sum;
scanf("%d %d",&A,&B);
sum = A+B;
printf("%d",sum);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
2.圆及圆球等的相关计算
#include<stdio.h>
#define pi 3.1415926
int main()
{
float r,h,l,s,sq,vq,vz;
scanf("%f %f",&r,&h);
l = 2 pi r;
s = pi r r;
sq = 4 pi r r;
vq = (4.0 / 3.0) pi r r r;//注意不能4 / 3 = 1(整数除法)
vz = s h;
printf("%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n",l,s,sq,vq,vz);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
3.计算成绩
#include<stdio.h>
int main()
{
int math,english,C;
double sum,average;
scanf("%d %d %d",&math,&english,&C);
sum = math + english + C;
average = sum / (double)3;
printf("%.6f\n%.6f",sum,average);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
4.找最大数
#include<stdio.h>
int main()
{
int A,B,C,t;
scanf("%d %d %d",&A,&B,&C);
if(A>B)
{
t = A;
A = B;
B = t;
}
if(B>C)
{
t = B;
B = C;
C = t;
}
printf("%d",C);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
5.找幸运数
#include <stdio.h>
#include <stdlib.h>
int main()
{
int A[5],B[5];
int i,j,k,x;
scanf("%d",&x);
for(i=0;i<5;i++)
{
A[i]=x%10;
x/=10;
}
k=i-1;
i=0;
for(j=k;j>=0;j–)
{
B[j]=A[i];
i++;
}
for(i=0;i<5;i++)
{
if(A[i]!=B[i])
{
printf(“no”);
return 0;
}
}
printf(“yes”);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
6.奖金发放
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
double i, reward;
scanf("%lf", &i);
if (i <= 10)
{
reward = 0.1 i;
}
else if (i > 10 && i <= 20)
{
reward = 1 + 0.075 (i - 10);
}
else if (i > 20 && i <= 40)
{
reward = 1.75 + 0.05 (i - 20);
}
else if (i > 40 && i <= 60)
{
reward = 2.75 + 0.03 (i - 40);
}
else if (i > 60 && i <= 100)
{
reward = 3.35 + 0.015 (i - 60);
}
else if (i > 100)
{
reward = 3.95 + 0.001 (i - 100);
}
else
{
printf(“error”);
}
printf("%.6lf", reward);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
7.出租车费
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
double m, n;
scanf("%lf", &m);
while ((int)m != m)
{
m = (int)m;
m++;
}
if (m <= 2)
{
n = 7;
}
else if (m > 2 && m <= 15) {
n = 7 + (m - 2) 1.5;
}
else if (m > 15) {
n = 7 + 13 1.5 + (m - 15) * 2.1;
}
printf("%.6lf", n);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
8.是该年的第几天?
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int y, m, d;
short flag = 0;
scanf("%d-%d-%d", &y, &m, &d);
if (y % 4 0 && y % 100 != 0 || y % 400 0)
flag++;
switch (m - 1)
{
case 11:d += 30;
case 10:d += 31;
case 9:d += 30;
case 8:d += 31;
case 7:d += 31;
case 6:d += 30;
case 5:d += 31;
case 4:d += 30;
case 3:d += 31;
case 2:d += 28 + flag;
case 1:d += 31;
}
printf("%d", d);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
9.成绩转换
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int i;
char c;
scanf("%d", &i);
if (i >= 90 && i <= 100) c = ‘A’;
else if (i >= 80 && i <= 89) c = ‘B’;
else if (i >= 70 && i <= 79) c = ‘C’;
else if (i >= 60 && i <= 69) c = ‘D’;
else if (i <= 60) c = ‘E’;
else printf(“error”);
printf("%c", c);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
10.求建筑高度
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
double x, y;
int h = 0;
scanf("%lf,%lf", &x, &y);
if (pow((x - 2), 2) + pow((y - 2), 2) <= 1 || pow((x - 2), 2) + pow((y + 2), 2) <= 1 || pow((x + 2), 2) + pow((y - 2), 2) <= 1 || pow((x + 2), 2) + pow((y + 2), 2) <= 1)
h = 10;
printf("%d", h);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
11.多项式的猜想
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int i=0,j=2, M = 100, s = 2;
int a[100] = {
1,1 };
while(i<3)
{
while (s < M)
{
a[j] = a[j - 2] + 2 a[j - 1];
s += a[j];
j++;
}
printf("%d\n", j-1);
M = 10;
i++;
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
12.奇特的分数序列
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int i;
double sum=0;
int a[20] = {
2,3 }, b[20] = {
1,2 };
double c[20] = {
2,1.5};
for(i=2;i<20;i++)
{
a[i] = a[i - 1] + a[i - 2];
b[i] = b[i - 1] + b[i - 2];
c[i] = (double)a[i] / (double)b[i];
}
for (i = 0; i < 20; i++)
{
sum += c[i];
}
printf("%lf", sum);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
13.二分求根
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
double x, y, z, s1, s2, s3;
scanf("%lf %lf", &x, &y);
do {
z = 0.5 (x + y);
s1 = 2 pow(x, 3) - 4 pow(x, 2) + 3 x - 6;
s2 = 2 pow(y, 3) - 4 pow(y, 2) + 3 y - 6;
s3 = 2 pow(z, 3) - 4 pow(z, 2) + 3 z - 6;
if (s1 s3 < 0) y = z;
if (s2 s3 < 0) x = z;
} while (s3 != 0);
printf("%.2lf", z);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
14.级数和
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int n;
double j, sum;
scanf("%d", &n);
for (j = 1, sum = 0; j <= n; j++)
{
sum += (pow(-1, j - 1) pow(2, j)) / ((pow(2, j) + pow(-1, j)) (pow(2, j + 1) + pow(-1, j + 1)));
}
printf("%.6lf", sum);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
15.整数位数
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
double x;
int i=0,y;
scanf("%lf", &x);
y = (int)fabs(x);
while (y)
{
y = y / 10;
i++;
}
printf("%d", i);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
16.五猴分桃
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int peach, i, t;
for (peach = 0;; peach++)
{
t = peach;
for (i = 0; i < 5; i++)
{
if (t % 5 1 && t - 1 > 0)
t = 4*((t - 1) / 5);
else
break;
}
if (5 i)
{
printf("%d %d", peach, t);
break;
}
else
continue;
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
17.计算π
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
double i, pi = 0, t;
for (i = 1, t = 0; (1 / i) >= 1e-6; i += 2, t++)
{
pi += 4 pow(-1, t) (1 / i);
}
printf("%.6lf", pi);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
18.完全数
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
int i, j, m, n, sum;
int k[50];
for (i = 2; i <= 1000; i++)
{
m = 0;
sum = 1;
memset(k, 0, sizeof(k));
for (j = 2; j < i; j++)
{
if (i % j 0)
{
k[m] = j;
sum += j;
m++;
}
}
if (sum i)
{
printf("%d=1", i);
for (n = 0; n < m; n++)
printf("+%d", k[n]);
printf("\n");
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
19.两个整数之间所有的素数
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int i, j, t, k;
scanf("%d %d", &i, &j);
if (i > j)
{
t = i;
i = j;
j = t;
}
for (k = i; k < j; k++)
{
for (t = 2; t < k; t++)
{
if (k % t 0)
break;
}
if (t k)
printf("%d ", k);
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
20.最次方数
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int x, a, i, re = 1;
scanf("%d %d", &x, &a);
for (i = 0; i < a; i++)
{
re *= x;
re = re % 1000;
}
printf("%d", re);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
21.幸运数字“7”
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int N, i, t;//N<=30000
scanf("%d", &N);
for (i = 7; i <= N; i++)
{
if (i % 7 0)
{
printf("%d ", i);
continue;
}
t = i;
while (t)
{
if (t % 10 7)
{
printf("%d ", i);
break;
}
t = t / 10;
}
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
22.韩信点兵
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int n;//n>=10&&n<=100
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
for (n = 10; n <= 100; n++)
{
if (n % 3 a && n % 5 b && n % 7 c)
{
printf("%d", n);
break;
}
}
if (n 101)
printf("-1");
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
23.子序列的和
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
double n, m, i,sum=0;
scanf("%lf %lf", &n, &m);
for (i = n; i <= m; i++)
{
sum += 1 / ((double)i * i);
}
printf("%.5lf", sum);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
24.危险的组合
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int i,j,t, n,count=0;
scanf("%d", &n);
for (i = 0; i <= pow(2, n) - 1; i++)
{
t = i;
for (j = 0; j < n; j++)
{
if((t&7)==7)
{
count++;
break;
}
t = t >> 1;
}
}
printf("%d", count);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
25.羊羊聚会
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int x, y, a, b, L, hour = 0, s, t;
scanf("%d %d %d %d %d", &x, &y, &a, &b, &L);
//x!=y,速度相等不可能相遇;
if (a == b)
printf(“impossible”);
//x!=y,速度不同时;
else
{
s = abs(x - y);
t = abs(b - a);
<span class="token keyword">if</span> <span class="token punctuation">(</span>s <span class="token operator">%</span> t <span class="token operator">==</span> <span class="token number">0</span> <span class="token operator">||</span> <span class="token punctuation">(</span>L <span class="token operator">-</span> s<span class="token punctuation">)</span> <span class="token operator">%</span> t <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span>
<span class="token punctuation">{<!-- --></span>
<span class="token keyword">for</span> <span class="token punctuation">(</span>hour <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span><span class="token punctuation">;</span> hour<span class="token operator">++</span><span class="token punctuation">)</span>
<span class="token punctuation">{<!-- --></span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>s <span class="token operator">+</span> hour <span class="token operator">*</span> t<span class="token punctuation">)</span> <span class="token operator">%</span> L <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span>
<span class="token punctuation">{<!-- --></span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> hour<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">break</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token keyword">else</span> <span class="token punctuation">{<!-- --></span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"impossible"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
26.探索合数世纪
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int prime_number(int num)//判断一个数是否为素数
{
//判定素数,只需枚举可能是素数的值进行检查(偶数、3的倍数、5的倍数、7的倍数不必检查)
if (num % 2 != 0 && num % 3 != 0 && num % 5 != 0 && num % 7 != 0)
{
int k;
//判断一个数是否为素数,不用检查2→n-1,只需检查2→根号n的范围内有无因子
for (k = 2; k <= sqrt(num); k++)//prime_number
{
if (num % k == 0)
{
break;
}
}
if (k > sqrt(num))
{
return 1;//是素数return1
}
}
else
return 0;//不是素数return0
}
int main()
{
int n, count = 0;
scanf("%d", &n);//input
int i, j;
for (i = 0;; i++)
{
int start = i * 100, end = start + 99;
for (j = start; j <= end; j++)
{
if (1 prime_number(j))//存在素数break
break;
}
if (j > end)
{
count++;
}
if (count n)
{
printf("%d %d", start, end);
break;
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
27.除法
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, c, d, e, f, g, h, i, j, n;
scanf("%d", &n);
if (n < 2 || n>79)
{
printf(“error”);
return 0;
}
for (j = 0; j <= 9; j++)
{
for (i = 0; i <= 9; i++)
{
if (i j)
continue;
else
for (h = 0; h <= 9; h++)
{
if (h j || h i)
continue;
else
for (g = 0; g <= 9; g++)
{
if (g h || g i || g j)
continue;
else
for (f = 0; f <= 9; f++)
{
if (f g || f h || f i || f j)
continue;
else
for (e = 0; e <= 9; e++)
{
if (e f || e g || e h || e i || e j)
continue;
else
for (d = 0; d <= 9; d++)
{
if (d e || d f || d g || d h || d i || d j)
continue;
else
for (c = 0; c <= 9; c++)
{
if (c d || c e || c f || c g || c h || c i || c j)
continue;
else
for (b = 0; b <= 9; b++)
{
if (b c || b d || b e || b f || b g || b h || b i || b j)
continue;
else
for (a = 0; a <= 9; a++)
{
if (a b || a c || a d || a e || a f || a g || a h || a i || a j)
continue;
else
if ((double)(a 10000 + b 1000 + c 100 + d 10 + e) /( double)(f 10000 + g 1000 + h 100 + i 10 + j) n)
{
printf("%d%d%d%d%d/%d%d%d%d%d=%d\n", a, b, c, d, e, f, g, h, i, j, n);
}
}
}
}
}
}
}
}
}
}
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
28.粒子裂变
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
int a = 1, b = 0, t;
scanf("%d", &t);
int i, new_a, new_b;
for (i = 0; i < t; i++)
{
new_a = b;
new_b = 3 a + 2 b;
a = new_a;
b = new_b;
}
printf("%d %d", a, b);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
29.“1”的传奇
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int pow_10(int i)
{
int j, ret = 1;
for (j = 0; j < i; j++)
{
ret *= 10;
}
return ret;
}
int main()
{
int n, N, count = 0;
scanf("%d",&N);
int cur, t = 1;
n = N;
while (n)
{
cur = n % 10;
n = n / 10;
if (cur 0)
{
count += N / pow_10(t) * pow_10(t - 1);
}
else if (cur 1)
{
count += N / pow_10(t) pow_10(t - 1) + N % pow_10(t - 1) + 1;
}
else if (cur > 1)
{
count += (N / pow_10(t) + 1) pow_10(t - 1);
}
t++;
}
printf("%d", count);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
30.特殊整数
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int m, n;
scanf("%d %d", &m, &n);
int i,t, count = 0, sum = 0;
for (i = pow(10,n-1); i < pow(10,n); i++)
{
if (i % m != 0)
{
t = i;
while (t)
{
if (t % 10 == m)
{
count++;
sum += i;
break;
}
t /= 10;
}
}
}
printf("%d %d", count, sum);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
31.最小整数
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int fceil(double x)
{
if (x >= 0)
{
if ((int)x x)
return x;
else
return (int)x+1;
}
else
{
if ((int)fabs(x) -x)
return x;
else
return -((int)fabs(x));
}
}
int main()
{
double x;
int y;
scanf("%lf", &x);
y = fceil(x);
printf("%d", y);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
32.发工资的日子
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int money(int n)
{
int cnt,cnt1=0, cnt2=0, cnt5=0, cnt10=0, cnt50=0, cnt100=0;
while (n >= 100)
{
n = n - 100;
cnt100++;
}
while (n >= 50)
{
n = n - 50;
cnt50++;
}
while (n >= 10)
{
n = n - 10;
cnt10++;
}
while (n >= 5)
{
n = n - 5;
cnt5++;
}
while (n >= 2)
{
n = n - 2;
cnt2++;
}
while (n >= 1)
{
n = n - 1;
cnt1++;
}
cnt = cnt1 + cnt2 +cnt5+ cnt10 + cnt50 + cnt100;
return cnt;
}
int main()
{
int n, t;
int sum = 0;
scanf("%d", &n);
int i;
for (i = 0; i < n; i++)
{
scanf("%d", &t);
sum += money(t);
}
printf("%d\n", sum);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
33.积分计算
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define delta 1e-6
double calc(double a, double b)
{
double i, ret = 0;
for (i = a; i <= b; i+= delta)
{
ret += 1 / (1 + i i) delta;
}
return ret;
}
int main()
{
double a, b;
scanf("%lf %lf", &a, &b);
printf("%lf\n", calc(a, b));
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
34.获取指定二进制位
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int getbit(int n,int k)
{
int temp=pow(2,k-1);
if (n & temp)
return 1;
else
return 0;
}
int main()
{
int n, k,ret;
scanf("%d %d", &n, &k);
ret=getbit(n, k);
printf("%d", ret);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
35.方差
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int n,N;
double sum = 0,avg=0,ret=0;
void averg(int n)
{
double x;
scanf("%lf", &x);
sum = sum + x;
if (n > 1)
averg(n - 1);
else
avg = sum / N;
ret = ret + (x - avg) * (x - avg);
}
int main()
{
scanf("%d", &n);
N = n;
averg(n);
printf("%.6lf", ret);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
36.亲和数
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int sum_of_true_constraints(int n)
{
int sum=0;
for (int i = 1; i < n; i++)
{
if (n % i == 0)
sum = sum + i;
}
return sum;
}
int main()
{
int a,b,sum_a,sum_b;
scanf("%d %d", &a, &b);
sum_a = sum_of_true_constraints(a);
sum_b = sum_of_true_constraints(b);
if (sum_a b && sum_b a)
printf(“YES”);
else
printf(“NO”);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
37.数据加密
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int change(int x)
{
int ret;
ret = (x + 5) % 10;
return ret;
}
int main()
{
int n,n1,n2,n3,n4,t;
scanf("%d", &n);
n4 = n % 10;
n4 = change(n4);
n = n / 10;
n3 = n % 10;
n3 = change(n3);
n = n / 10;
n2 = n % 10;
n2 = change(n2);
n = n / 10;
n1 = n % 10;
n1 = change(n1);
t = n4;
n4 = n1;
n1 = t;
t = n2;
n2 = n3;
n3 = t;
n = 1000 n1 + 100 n2 + 10 * n3 + n4;
printf("%d\n", n);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
38.循环移位
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int move(int val, int m)
{
if (m < 0)
{
int t1 = val << -m;//val左移|m|,右边补0
int temp = pow(2, 16) - pow(2, 16 + m);//左边m位为1
int t2 = val & temp;//左移出去的位数
return t1 + (t2 >> 16 + m);
}
else if (m > 0)
{
int t1 = val >> m;//val右移|m|,左边补0
int temp = pow(2, m) - 1;//最右m位1
int t2 = val & temp;//右移出去的位数
return (t2 << 16 - m) + t1;
}
return val;
}
int main()
{
int value, n;
scanf("%d %d", &value,&n);
value = move(value, n);
printf("%d", value);
}
- 1
- 2
- 3
- 4
- 5
- 6