BC1 实践出真知
#include
int main()
{
printf("Practice makes perfect!\n");
return 0;
}
BC2 我是大V
#include
int main()
{
printf("v v\n v v \n v \n");
return 0;
}
BC3 有容乃大
#include
int main()
{
printf("The size of short is %d bytes.\n", sizeof(short));
printf("The size of int is %d bytes.\n", sizeof(int));
printf("The size of long is %d bytes.\n", sizeof(long));
printf("The size of long long is %d bytes.\n", sizeof(long long));
}
BC6 小飞机
#include
int main()
{
printf(" ** \n");
printf(" ** \n");
printf("************\n");
printf("************\n");
printf(" * * \n");
printf(" * * \n");
return 0;
}
BC7 缩短二进制
#include
int main()
{
printf("%#o %#X", 1234, 1234);
return 0;
}
BC8 十六进制转十进制
#include
int main()
{
int n = 0XABCDEF;
printf("%15d", n);
return 0;
}
BC9 printf的返回值
#include
int main()
{
int a = printf("Hello world!");
printf("\n%d", a);
return 0;
}
BC10 成绩输入输出
#include
int main()
{
int score1 = 0;
int score2 = 0;
int score3 = 0;
scanf("%d %d %d", &score1, &score2, &score3);
printf("score1=%d,score2=%d,score3=%d", score1, score2, score3);
return 0;
}
BC11 学生基本信息输入输出
#include
int main()
{
long a;
float C, M, E;
scanf("%ld;%f,%f,%f", &a, &C, &M, &E);
printf("The each subject score of No. %ld is %.2f, %.2f, %.2f.", a, C, M, E);
return 0;
}
BC12 字符圣诞树
#include
int main()
{
char a;
scanf("%c", &a);
for(int i = 1; i <= 5; i++)
{
for(int j = 0; j < 5-i; j++)
{
printf(" ");
}
for(int j = 0; j < i; j++)
{
printf("%c ", a);
}
printf("\n");
}
return 0;
}
BC13 ASCII码
#include
int main()
{
int arr[] = {73, 32, 99, 97, 110, 32, 100, 111, 32, 105, 116 , 33};
int size = sizeof(arr) / sizeof(arr[0]);
for(int i = 0; i < size; i++)
{
printf("%c", arr[i]);
}
return 0;
}
BC14 出生日期输入输出
#include
int main()
{
int year;
int month;
int day;
scanf("%4d%2d%2d", &year, &month, &day);
printf("year=%d\nmonth=%02d\ndate=%02d\n", year, month, day);
return 0;
}
BC15 按照格式输入并交换输出
#include
void JH(int *a, int *b);
int main()
{
int a;
int b;
scanf("a=%d,b=%d", &a, &b);
JH(&a, &b);
printf("a=%d,b=%d", a, b);
}
void JH(int *a, int *b)
{
int c = *a;
*a = *b;
*b = c;
}
BC16 字符转ASCII码
#include
int main()
{
char ch;
while((ch = getchar()) != EOF)
{
getchar();
printf("%d\n", ch);
}
return 0;
}
BC17 计算表达式的值
#include
int main()
{
int a = 40;
int c = 212;
int num = (-8 + 22) * a - 10 + c / 2;
printf("%d", num);
}
BC18 计算带余除法
#include
int main()
{
int a;
int b;
scanf("%d %d", &a, &b);
printf("%d %d", a / b, a % b);
return 0;
}
BC19 反向输出一个四位数
#include
int main()
{
int a;
scanf("%d", &a);
while(a > 0)
{
int b = a % 10;
printf("%d", b);
a = a / 10;
}
}
BC20 kiki算数
#include
int main()
{
int a;
int b;
scanf("%d %d", &a, &b);
int c = a + b;
if(c >= 100)
c %= 100;
printf("%d", c);
return 0;
}
BC21 浮点数的个位数字
#include
int main()
{
float a;
scanf("%f", &a);
int b = (int)a;
printf("%d", b %= 10);
return 0;
}
BC22 你能活多少秒
#include
int main()
{
int age = 0;
scanf("%d", &age);
printf("%.0lf\n", age * 31560000.0);
return 0;
}
BC23 时间转换
#include
int main()
{
int seconds = 0;
int hour = 0, minute = 0, sec = 0;
scanf("%d", &seconds);
hour = seconds / 3600;
minute = (seconds % 3600) / 60;
sec = (seconds % 3600) % 60;
printf("%d %d %d", hour, minute, sec);
}
BC24 总成绩和平均分计算
#include
int main()
{
double a[3] = {0};
double sum = 0, ave = 0;
scanf("%lf %lf %lf", &a[0], &a[1], &a[2]);
printf("%.2f %.2f", a[0]+a[1]+a[2], (a[0]+a[1]+a[2])/3.0);
return 0;
}
BC25 计算体重指数
#include
int main()
{
int high = 0, weight = 0;
scanf("%d %d", &weight, &high);
printf("%.2f\n", weight / ((high / 100.0)*(high / 100.0)));
return 0;
}
BC26 计算三角形的周长和面积
#include
#include
int main()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
float d, e, p;
d = a + b + c;
p = d / 2;
e = sqrt(p * (p-a) *(p-b) * (p-c));
printf("circumference=%.2f area=%.2f", d, e);
return 0;
}
BC27 计算球体的体积
#include
#include
int main()
{
double r = 0.0;
double v = 0.0;
double pi = 3.1415926;
scanf("%lf", &r);
v = 4 / 3.0 * pi * pow(r,3);
printf("%.3lf\n", v);
return 0;
}
BC28 大小写转换
#include
int main()
{
char ch;
while((ch = getchar()) != EOF)
{
getchar();
if(ch >= "a" && ch <= "z")
printf("%c\n", (ch - 32));
else
printf("%c\n", (ch + 32));
}
return 0;
}
BC29 2的n次方计算
#include
int main()
{
int a;
int sum = 1;
scanf("%d", &a);
for(int i = 0; i < a; i++)
{
sum = sum << 1;
}
printf("%d", sum);
return 0;
}
BC30 KiKi和酸奶
#include
int main()
{
int n;
int h;
int m;
scanf("%d %d %d", &n, &h, &m);
int w = (n * h - m) / h;
printf("%d", w);
return 0;
}
BC31 发布信息
#include
int main()
{
printf("I lost my cellphone!");
return 0;
}
BC32 输出学生信息
#include
int main()
{
printf("Name Age Gender\n");
printf("---------------------\n");
printf("Jack 18 man \n");
return 0;
}
BC33 计算平均成绩
#include
int main()
{
int stu1, stu2, stu3, stu4, stu5;
scanf("%d %d %d %d %d", &stu1, &stu2, &stu3, &stu4, &stu5);
float stu_avg = (stu1 + stu2 +stu3 + stu4 + stu5) / 5.0;
printf("%.1f", stu_avg);
return 0;
}
BC34 进制A+B
#include
int main()
{
int a, b;
scanf("%x %o", &a, &b);
printf("%d", (a + b));
return 0;
}
BC35 判断字母
#include
int main()
{
char ch;
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
printf("YES");
else
printf("NO");
return 0;
}
BC36 健康评估
#include
int main()
{
double Hight;
double Weight;
double BMI;
scanf("%lf %lf", &Weight, &Hight);
BMI = Weight / (Hight*Hight);
if(BMI >= 18.5 && BMI <= 23.9)
printf("Normal\n");
else
printf("Abnormal\n");
return 0;
}
BC37 网购
#include
typedef struct Yh
{
float price;
int month;
int day;
int flag;
}YH;
int main()
{
YH XM = {0};
scanf("%f %d %d %d", &XM.price, &XM.month, &XM.day, &XM.flag);
if(XM.month == 11 && XM.day == 11)
XM.price = XM.price * 0.7;
else if(XM.month == 12 && XM.day == 12)
XM.price = XM.price * 0.8;
if(XM.flag == 1)
XM.price = XM.price - 50;
if(XM.price <= 0)
XM.price = 0;
printf("%.2f", XM.price);
return 0;
}
BC38 变种水仙花
#include
int main()
{
int a[4];
int b[4];
for(int i = 10000; i <= 99999; i++)
{
a[0] = i / 10000;
b[0] = i % 10000;
a[1] = i / 1000;
b[1] = i % 1000;
a[2] = i / 100;
b[2] = i % 100;
a[3] = i / 10;
b[3] = i % 10;
if(i == a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3])
printf("%d ", i);
}
return 0;
}
BC39 争夺前五名
#include
int main()
{
int n;
int a[50] = {0};
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for(int i = 0; i < 5; i++)
{
for(int j = i+1; j< n; j++)
{
if(a[j] > a[i])
{
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
printf("%d ", a[i]);
}
}
BC40 竞选社长
#include
int main()
{
char ch;
int A = 0, B = 0, E = 0;
while((ch = getchar()) != '0')
{
if(ch == 'A')
A++;
if(ch == 'B')
B++;
}
if(A == B)
{
printf("E\n");
return 0;
}
int flag = A > B ? 0 : 1;
if(flag == 0)
printf("A\n");
else
printf("B\n");
return 0;
}
BC41 你是天才吗?
#include
int main()
{
int Genius;
while(scanf("%d", &Genius) != EOF)
{
if(Genius >= 140)
printf("Genius\n");
}
return 0;
}
BC42 完美成绩
#include
int main()
{
int score;
while(scanf("%d", &score) != EOF)
{
if(score >= 90 && score <= 100)
printf("Perfect\n");
}
return 0;
}
BC43 及格分数
#include
int main()
{
int score;
while(scanf("%d", &score) != EOF)
{
if(score >= 60 && score <= 100)
printf("Pass\n");
else
printf("Fail\n");
}
return 0;
}
BC44 判断整数奇偶性
#include
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
if(n % 2 == 0)
printf("Even\n");
else
printf("Odd\n");
}
return 0;
}
BC45 最高分数
#include
int main()
{
int a[3] = {0};
scanf("%d %d %d", &a[0], &a[1], &a[2]);
int max = a[0];
for(int i = 1; i <= 2; i++)
{
if(a[i] > max)
max = a[i];
}
printf("%d", max);
return 0;
}
BC46 判断是元音还是辅音
#include
int main()
{
char a[10] = {'A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u'};
char ch;
int flag = 0;
while(scanf("%c", &ch) != EOF)
{
getchar();
for(int i = 0; i < 10; i++)
{
if(ch == a[i])
flag = 1;
}
if(flag == 1)
{
flag = 0;
printf("Vowel\n");
}
else
printf("Consonant\n");
}
}
BC47 判断是不是字母
#include
int main()
{
char ch;
while((ch = getchar()) != EOF)
{
getchar();
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
printf("%c is an alphabet.\n", ch);
else
printf("%c is not an alphabet.\n", ch);
}
return 0;
}
BC48 字母大小写转换
#include
int main()
{
char ch;
while((ch = getchar()) != EOF)
{
getchar();
if(ch >= 'a' && ch <= 'z')
ch = ch - 32;
else if(ch >= 'A' && ch <= 'Z')
ch = ch + 32;
printf("%c\n", ch);
}
return 0;
}
BC49 判断两个数的大小关系
#include
int main()
{
int a = 0, b = 0;
while(scanf("%d %d", &a, &b) != EOF)
{
if(a == b)
printf("%d=%d\n", a, b);
else if(a > b)
printf("%d>%d\n", a, b);
else
printf("%d<%d\n", a, b);
}
return 0;
}
BC50 计算单位阶跃函数
#include
int main()
{
int num;
while(scanf("%d", &num) != EOF)
{
if(num > 0)
printf("1\n");
else if(num == 0)
printf("0.5\n");
else
printf("0\n");
}
return 0;
}
BC51 三角形判断
#include
int main()
{
int a = 0, b = 0, c = 0;
while(scanf("%d %d %d", &a, &b, &c) != EOF)
{
if(a + b > c && b + c > a && c + a > b)
{
if(a == b && b == c)
printf("Equilateral triangle!\n");
else if(a == b || b == c || c == a)
printf("Isosceles triangle!\n");
else
printf("Ordinary triangle!\n");
}
else
printf("Not a triangle!\n");
}
return 0;
}
BC52 衡量人体胖瘦程度
#include
#include
int main()
{
int weight = 0, high = 0;
while(scanf("%d %d", &weight, &high) != EOF)
{
double BMI = weight / pow((double)high/100.0, 2.0);
if(BMI < 18.5)
printf("Underweight\n");
else if(BMI >= 18.5 && BMI <= 23.9)
printf("Normal\n");
else if(BMI > 23.9 && BMI <= 27.9)
printf("Overweight\n");
else
printf("Obese\n");
}
return 0;
}
BC53 计算一元二次方程
#include
#include
int main()
{
float a = 0, b = 0, c = 0;
float x1 = 0, x2 = 0;
float s = 0, x = 0;
while(scanf("%f %f %f", &a, &b, &c) != EOF)
{
if(a == 0)
printf("Not quadratic equation\n");
else
{
double delat = pow(b, 2.0) - 4 * a * c;
if(delat == 0)
{
x1 = (-b + sqrt(delat)) / (2 * a);
printf("x1=x2=%.2f\n", x1);
}
else if(delat > 0)
{
x1 = (-b - sqrt(delat)) / (2 * a);
x2 = (-b + sqrt(delat)) / (2 * a);
printf("x1=%.2f;x2=%.2f\n", x1, x2);
}
else
{
s = -b / (2 * a);
x = sqrt(-delat) / (2 * a);
printf("x1=%.2f-%.2fi;x2=%.2f+%.2fi\n", s, x, s, x);
}
}
}
return 0;
}
BC54 获得月份天数
#include
int main()
{
int a[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int flag = 0;
int year, month;
while(scanf("%d %d", &year, &month) != EOF)
{
flag = 0;
if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
flag = 1;
printf("%d\n", a[flag][month - 1]);
}
return 0;
}
BC55 简单计算器
#include
int main()
{
double a, b;
char ch;
scanf("%lf%c%lf", &a, &ch, &b);
switch(ch)
{
case '+':
printf("%.4f+%.4f=%.4f\n", a, b, (a+b));
break;
case '-':
printf("%.4f-%.4f=%.4f\n", a, b, (a-b));
break;
case '*':
printf("%.4f*%.4f=%.4f\n", a, b, (a*b));
break;
case '/':
if(b == 0)
printf("Wrong!Division by zero!\n");
else
printf("%.4f/%.4f=%.4f\n", a, b, (a/b));
break;
default:
printf("Invalid operation!\n");
break;
}
return 0;
}
BC56 线段图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
while(num--)
printf("*");
printf("\n");
}
return 0;
}
BC57 正方形图案
#include
int main()
{
int num = 0;
while((scanf("%d", &num)) != EOF)
{
int n = num;
while(num--)
{
for(int i = 0; i < n; i++)
{
printf("* ");
}
printf("\n");
}
}
return 0;
}
BC58 直角三角形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = 1; i <= num; i++)
{
int j = i;
while(j--)
printf("* ");
printf("\n");
}
}
return 0;
}
BC59 翻转直角三角形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = num; i >= 1; i--)
{
int j = i;
while(j--)
printf("* ");
printf("\n");
}
}
return 0;
}
BC60 带空格直角三角形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = num - 1; i >= 0; i--)
{
int j = i;
while(j--)
printf(" ");
int n = num - i;
while(n--)
printf("* ");
printf("\n");
}
}
return 0;
}
BC61 金字塔图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = num - 1; i >= 0; i--)
{
int j = i;
while(j--)
printf(" ");
int n = num - i;
while(n--)
printf("* ");
printf("\n");
}
}
return 0;
}
BC62 翻转金字塔图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = num; i > 0; i--)
{
for(int j = i; j < num; j++)
printf(" ");
int n = i;
while(n--)
printf("* ");
printf("\n");
}
}
return 0;
}
BC63 菱形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int p = 1; p <= num; p++)
{
int mmp = num - p + 1;
while(mmp--)
printf(" ");
int pp = p;
while(pp--)
printf("* ");
printf("\n");
}
for(int i = num + 1 ; i > 0; i--)
{
for(int j = i; j < num + 1; j++)
printf(" ");
int n = i;
while(n--)
printf("* ");
printf("\n");
}
}
return 0;
}
BC64 K形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = num + 1; i > 1; i--)
{
int mmp = i;
while(mmp--)
printf("* ");
printf("\n");
}
for(int i = 1; i <= num + 1; i++)
{
int n = i;
while(n--)
printf("* ");
printf("\n");
}
}
return 0;
}
BC65 箭形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = 1; i <= num + 1; i++)
{
int mmp = (num - i + 1) * 2;
for(int j = mmp; j > 0; j--)
printf(" ");
int nmmp = i;
while(nmmp--)
printf("*");
printf("\n");
}
for(int i = num; i > 0; i--)
{
int op = (num - i + 1) * 2;
while(op--)
printf(" ");
int oo = i;
while(oo--)
printf("*");
printf("\n");
}
}
return 0;
}
BC66 反斜线形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = 0; i < num; i++)
{
int j = i;
for(int j = 0; j < i; j++)
printf(" ");
printf("* \n");
}
}
return 0;
}
BC67 正斜线形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = num - 1; i >= 0; i--)
{
int j = i;
for(int j = 0; j < i; j++)
printf(" ");
printf("* \n");
}
}
return 0;
}
BC68 X形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = 1; i <= num; i++)
{
for(int j = 1; j <= num; j++)
{
if(i == j || j == num - i + 1)
printf("*");
else
printf(" ");
}
printf("\n");
}
}
return 0;
}
BC69 空心正方形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = 1; i <= num; i++)
{
for(int j = 1; j <= num; j++)
{
if(i == 1 || i == num || j == 1 || j == num)
printf("* ");
else
printf(" ");
}
printf("\n");
}
}
return 0;
}
BC70 空心三角形图案
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = 1; i <= num; i++)
{
for(int j = 1; j <= num; j++)
{
if(j == i || j == 1 || i == num)
printf("* ");
else
printf(" ");
}
printf("\n");
}
}
return 0;
}
BC71 新年快乐
#include
int main()
{
printf("Happy New Year*2019*\n");
return 0;
}
BC72 平均身高
#include
int main()
{
float h1, h2, h3, h4, h5;
scanf("%f %f %f %f %f", &h1, &h2, &h3, &h4, &h5);
printf("%.2f", (h1+h2+h3+h4+h5)/5.0);
return 0;
}
BC73 挂科危险
#include
int main()
{
int score = 0;
scanf("%d", &score);
if(score >= 0 && score <= 3)
printf("Good\n");
else if(score >= 4 && score <= 9)
printf("Danger\n");
else
printf("Danger++\n");
}
BC74 HTTP状态码
#include
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
switch(n)
{
case 200:
printf("OK\n");
break;
case 202:
printf("Accepted\n");
break;
case 400:
printf("Bad Request\n");
break;
case 403:
printf("Forbidden\n");
break;
case 404:
printf("Not Found\n");
break;
case 500:
printf("Internal Server Error\n");
break;
case 502:
printf("Bad Gateway\n");
break;
}
}
return 0;
}
BC75 数字三角形
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
for(int i = 1; i <= num; i++)
{
for(int j = 1; j <= i; j++)
{
printf("%d ", j);
}
printf("\n");
}
}
return 0;
}
BC76 公务员面试
#include
void sort(int a[], int length);
int main()
{
int a[7] = {0};
while(scanf("%d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6]) != EOF)
{
sort(a, 7);
printf("%.2f\n", (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6])/5.0);
}
return 0;
}
void sort(int a[], int length)
{
int max = 0;
int min = 0;
for(int i = 1; i < 7; i++)
{
if(a[i] > a[max])
max = i;
else if(a[i] < a[min])
min = i;
}
a[max] = 0;
a[min] = 0;
}
BC77 有序序列插入一个数
#include
int main()
{
int m = 0, num = 0, j = 0;
scanf("%d", &m);
int *arr = (int *)malloc((m+1) * sizeof(int));
for(int i = 0; i < m; i++)
scanf("%d", &arr[i]);
scanf("%d", &num);
for(j = m-1; arr[j] > num && j >= 0; j--)
arr[j+1] = arr[j];
arr[j+1] = num;
for(int k = 0; k < m+1; k++)
printf("%d ", arr[k]);
free(arr);
return 0;
}
BC78 筛选法求素数
#include
int main()
{
int num = 0, flag = 0, cut = 0;
scanf("%d", &num);
for(int i = 2; i <= num; i++)
{
for(int j = 2; j < i; j++)
{
flag = 0;
if(i % j == 0)
{
flag = 1;
cut++;
break;
}
}
if(flag == 0)
{
printf("%d ", i);
}
}
printf("\n%d\n", cut);
return 0;
}
BC79 图像相似度
#include
double Get_similar(int a, int b)
{
int *p;
int *q;
int i;
int count = 0;
p = (int*)malloc((a*b)*sizeof(int));
q = (int*)malloc((a*b)*sizeof(int));
if(q != NULL && p != NULL)
{
for(i = 0; i < a*b; i++)
{
scanf("%d ", &p[i]);
}
for(i = 0; i < a*b; i++)
{
scanf("%d ", &q[i]);
}
for(i = 0; i < a*b; i++)
{
if(p[i] == q[i])
{
count++;
}
}
}
free(p);
free(q);
return count*100/(double)(a*b);
}
int main()
{
int a,b;
double similar;
scanf("%d %d",&a,&b);
similar = Get_similar(a, b);
printf("%.2f", similar);
return 0;
}
BC80 登录验证
#include
#include
int main()
{
char admin[10];
char password[10];
while(scanf("%s %s", admin, password) != EOF)
{
if(strcmp(admin, "admin") == 0 && strcmp(password, "admin") == 0)
printf("Login Success!\n");
else
printf("Login Fail!\n");
}
return 0;
}
BC81 学好C++
#include
int main()
{
printf("I will learn C++ well!");
return 0;
}
BC82 (a+b-c)*d的计算问题
#include
int main()
{
int a = 0, b = 0, c = 0, d = 0;
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("%d", (a+b-c)*d);
return 0;
}
BC83 被5整除问题
#include
int main()
{
int n = 0;
scanf("%d", &n);
if(n % 5 == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
BC84 计算y的值
#include
int main()
{
int x = 0;
scanf("%d", &x);
if(x == 0)
printf("0\n");
else if(x < 0)
printf("1\n");
else
printf("-1\n");
return 0;
}
BC85 包含数字9的数
#include
int main()
{
int cnt = 0;
for (int i = 1; i <= 2019; i++)
{
int m = i;
while (m > 0)
{
if (m % 10 == 9)
{
cnt++;
break;
}
else
{
m /= 10;
}
}
}
printf("%d\n", cnt);
return 0;
}
BC86 奇偶统计
#include
int main()
{
int n = 0;
int x = 0, y = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
if(i % 2 == 0)
y++;
else
x++;
}
printf("%d %d", x, y);
return 0;
}
BC87 统计成绩
#include
int main()
{
int n = 0, max = 0, min = 0;
float sum = 0;
scanf("%d", &n);
float *arr = (float *)malloc(n * sizeof(float));
if(arr != NULL)
{
for(int i = 0; i < n; i++)
{
scanf("%f ", &arr[i]);
sum += arr[i];
if(arr[i] > arr[max])
max = i;
if(arr[i] < arr[min])
min = i;
}
}
printf("%.2f %.2f %.2f", arr[max], arr[min], sum / n);
free(arr);
return 0;
}
BC88 有序序列插入一个数
#include
int main()
{
int m = 0, num = 0, j = 0;
scanf("%d", &m);
int *arr = (int *)malloc((m+1) * sizeof(int));
for(int i = 0; i < m; i++)
scanf("%d", &arr[i]);
scanf("%d", &num);
for(j = m-1; arr[j] > num && j >= 0; j--)
arr[j+1] = arr[j];
arr[j+1] = num;
for(int k = 0; k < m+1; k++)
printf("%d ", arr[k]);
free(arr);
return 0;
}
BC89 密码验证
#include
#include
int main()
{
char password[20];
char repassword[20];
while(scanf("%s %s", password, repassword) != EOF)
{
if(strcmp(password, repassword) == 0)
printf("same\n");
else
printf("different\n");
}
return 0;
}
BC90 矩阵计算
#include
int main()
{
int N, M, sum = 0;
scanf("%d %d", &N, &M);
int *arr = (int *)malloc(N*M*sizeof(int));
for(int i = 0; i < N*M; i++)
{
scanf("%d ", &arr[i]);
if(arr[i] > 0)
sum += arr[i];
}
printf("%d", sum);
return 0;
}
BC91 成绩输入输出问题
#include
#define N 10
int main()
{
int a[N] = {0};
for(int i = 0; i < 10; i++)
{
scanf("%d ", &a[i]);
printf("%d ", a[i]);
}
return 0;
}
BC92 逆序输出
#include
#define N 10
int main()
{
int a[N] = {0};
for(int i = 0; i < N; i++)
{
scanf("%d ", &a[i]);
}
for(int j = N - 1; j >= 0; j--)
printf("%d ", a[j]);
return 0;
}
BC93 统计数据正负个数
#include
int main()
{
int pos = 0, nav = 0;
int n = 10;
int num = 0;
while(n--)
{
scanf("%d ", &num);
if(num > 0)
pos++;
if(num < 0)
nav++;
}
printf("positive:%d\n", pos);
printf("negative:%d\n", nav);
return 0;
}
BC94 N个数之和
#include
int main()
{
int N = 0, num = 0, sum = 0;
scanf("%d", &N);
while(N--)
{
scanf("%d ", &num);
sum += num;
}
printf("%d\n", sum);
return 0;
}
BC95 最高分与最低分之差
#include
int main()
{
int N = 0, num = 0, max = 0, min = 100;
scanf("%d", &N);
while(N--)
{
scanf("%d ", &num);
if(num > max) max = num;
if(num < min) min = num;
}
printf("%d\n", max - min);
return 0;
}
BC96 有序序列判断
#include
int main()
{
int n = 0;
int arr, num;
int flag1 = 0;
int flag2 = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &arr);
if (i > 0)
{
if (arr > num)
{
flag1 = 1;
}
else if (arr < num)
{
flag2 = 1;
}
}
num = arr;
}
(flag1 + flag2 > 1) ? printf("unsorted\n") : printf("sorted\n");
return 0;
}
BC97 有序序列插入一个整数
#include
int main()
{
int m = 0, num = 0, j = 0;
scanf("%d", &m);
int *arr = (int *)malloc((m+1) * sizeof(int));
for(int i = 0; i < m; i++)
scanf("%d ", &arr[i]);
scanf("%d", &num);
for(j = m-1; arr[j] > num && j >= 0; j--)
arr[j+1] = arr[j];
arr[j+1] = num;
for(int k = 0; k < m+1; k++)
printf("%d ", arr[k]);
free(arr);
return 0;
}
BC98 序列中删除指定数字
#include
int main()
{
int m = 0, num = 0, j = 0;
scanf("%d", &m);
int *arr = (int *)malloc(m * sizeof(int));
for(int i = 0; i < m; i++)
scanf("%d ", &arr[i]);
scanf("%d", &num);
for(j = 0; j < m; j++)
{
if(num != arr[j])
printf("%d ", arr[j]);
}
printf("\n");
free(arr);
return 0;
}
BC99 序列中整数去重
#include
int main()
{
int m = 0, num = 0, flag = 0;
scanf("%d", &m);
int *arr = (int *)malloc(m * sizeof(int));
for(int i = 0; i < m; i++)
scanf("%d ", &arr[i]);
for(int j = 0; j < m; j++)
{
flag = 0;
for(int k = 0; k < j; k++)
{
if(arr[j] == arr[k]) flag = 1;
}
if(flag == 0)
printf("%d ", arr[j]);
}
printf("\n");
free(arr);
return 0;
}
BC100 有序序列合并
#include
int main()
{
int N = 0, M = 0, k = 0, flag = 0;
scanf("%d %d", &N, &M);
int *first = (int *)malloc((N+M)*sizeof(int));
int *second = (int *)malloc(M*sizeof(int));
for(int i = 0; i < N; i++)
{
scanf("%d ", &first[i]);
}
for(int j = 0; j < M; j++)
{
scanf("%d ", &second[j]);
}
for(int i = 0; i < M; i++)
{
flag = 0;
for(k = N - 1; k >= 0; k--)
{
if(first[k] > second[i])
{
first[k+1] = first[k];
if(k == 0)
flag = 1;
}
else
{
first[k+1] = second[i];
break;
}
}
if(flag == 1)
first[0] = second[i];
N++;
}
for(int x = 0; x < N; x++)
{
printf("%d ", first[x]);
}
free(first);
free(second);
return 0;
}
BC101 班级成绩输入输出
#include
int main()
{
double arr[5][5];
for(int i = 0; i < 5; i++)
{
scanf("%lf %lf %lf %lf %lf", &arr[i][0], &arr[i][1], &arr[i][2], &arr[i][3], &arr[i][4]);
}
for(int i = 0; i < 5; i++)
{
double sum = 0;
for(int j = 0; j < 5; j++)
{
printf("%.1f ", arr[i][j]);
sum += arr[i][j];
}
printf("%.1f\n", sum);
}
return 0;
}
BC102 矩阵元素定位
#include
int main()
{
int H = 0, L = 0;
scanf("%d %d", &H, &L);
int *arr = (int *)malloc(H*L*sizeof(int));
for(int i = 0; i < H*L; i++)
{
scanf("%d ", &arr[i]);
}
int sH, sL;
scanf("%d %d", &sH, &sL);
printf("%d\n", arr[(sH-1)*L+sL-1]);
free(arr);
}
BC103 序列重组矩阵
#include
int main()
{
int n = 0, m = 0;
scanf("%d %d", &n, &m);
int *arr = (int *)malloc(n*m*sizeof(int));
for(int i = 0; i < n*m; i++)
{
scanf("%d ", &arr[i]);
if(i != 0 && i % m == 0)
printf("\n");
printf("%d ", arr[i]);
}
free(arr);
return 0;
}
BC104 最高身高
#include
int main()
{
int N = 0, M = 0, max = 0;
scanf("%d %d", &N, &M);
int *arr = (int *)malloc(N*M*sizeof(int));
for(int i = 0; i < N*M; i++)
{
scanf("%d ", &arr[i]);
if(arr[i] > arr[max])
max = i;
}
printf("%d %d", max/M + 1, max + 1 - (max/M)*M);
}
BC105 矩阵相等判定
#include
int main()
{
int N = 0, M = 0, max = 0;
scanf("%d %d", &N, &M);
int *arr = (int *)malloc(N*M*sizeof(int));
int *prr = (int *)malloc(N*M*sizeof(int));
for(int i = 0; i < N*M; i++)
{
scanf("%d ", &arr[i]);
}
for(int i = 0; i < N*M; i++)
{
scanf("%d ", &prr[i]);
if(arr[i] != prr[i])
{
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
}
BC106 上三角矩阵判定
#include
int main()
{
int n = 0, flag = 0;
scanf("%d", &n);
int *arr = (int *)malloc(n*n*sizeof(int));
for(int i = 0; i < n*n; i++)
{
scanf("%d ", &arr[i]);
}
for(int x = 0; x < n; x++)
{
for(int y = 0; y < x; y++)
{
if(*(arr+x*n+y) != 0)
flag = 1;
}
}
if(flag == 1)
printf("NO\n");
else
printf("YES\n");
free(arr);
return 0;
}
BC107 矩阵转置
#include
int main()
{
int n = 0, m = 0;
scanf("%d %d", &n, &m);
int *arr = (int *)malloc(n*m*sizeof(int));
for(int i = 0; i < n*m; i++)
{
scanf("%d ", &arr[i]);
}
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
printf("%d ", *(arr+j*m+i));
}
printf("\n");
}
free(arr);
return 0;
}
BC108 矩阵交换
#include
int main()
{
int n = 0, m = 0;
scanf("%d %d", &n, &m);
int *arr = (int *)malloc(n*m*sizeof(int));
for(int i = 0; i < n*m; i++)
{
scanf("%d ", &arr[i]);
}
int num = 0;
char ch;
int h = 0, l = 0;
scanf("%d", &num);
while(num--)
{
getchar();
scanf("%c %d %d", &ch, &h, &l);
switch(ch)
{
case 'r':
for(int i = 0; i < m; i++)
{
int tmp = *(arr+(h-1)*m+i);
*(arr+(h-1)*m+i) = *(arr+(l-1)*m+i);
*(arr+(l-1)*m+i) = tmp;
}
break;
case 'c':
for(int i = 0; i < n; i++)
{
int mmp = *(arr+i*m+h-1);
*(arr+i*m+h-1) = *(arr+i*m+l-1);
*(arr+i*m+l-1) = mmp;
}
break;
default:
break;
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
printf("%d ", *(arr+i*m+j));
}
printf("\n");
}
free(arr);
return 0;
}
BC109 杨辉三角
#include
int main()
{
int n = 0;
int arr[30][30] = { 0 };
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
{
if (0 == j || i == j)
{
arr[i][j] = 1;
}
else
{
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
printf("%5d", arr[i][j]);
}
printf("\n");
}
return 0;
}
BC110 井字棋
#include
int main()
{
char arr[3][3] = {0};
int i = 0;
int j = 0;
char flag = 'c';
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
scanf("%c", &arr[i][j]);
getchar();
}
}
for(i = 0; i < 3; i++)
{
if(arr[i][0] == arr[i][1] && arr[i][1] == arr[i][2])
{
flag = arr[i][1];
break;
}
if(arr[0][i] == arr[1][i] && arr[1][i] == arr[2][i])
{
flag = arr[1][i];
break;
}
}
if(arr[0][0] == arr[1][1] && arr[1][1] == arr[2][2])
flag = arr[1][1];
if(arr[0][2] == arr[1][1] && arr[1][1] == arr[2][0])
flag = arr[1][1];
if(flag == 'K')
printf("KiKi wins!");
else if(flag == 'B')
printf("BoBo wins!");
else
printf("No winner!");
return 0;
}
BC111 小乐乐与进制转换
#include
int main()
{
int n = 0;
int m = 0;
int a[9] = {0};
int size = 0;
scanf("%d", &n);
while(n)
{
m = n % 6;
a[size++] = m;
n = n / 6;
}
for(int j = size-1; j >= 0; j--)
printf("%d", a[j]);
return 0;
}
BC112 小乐乐求和
#include
int main()
{
int n = 0;
long sum = 0;
scanf("%d", &n);
while(n)
{
sum += n;
n--;
}
printf("%ld",sum);
return 0;
}
BC113 小乐乐定闹钟
#include
int main()
{
int hour = 0, min = 0;
long after = 0;
scanf("%d:%d %d", &hour, &min, &after);
int all = hour * 60 + min + after;
printf("%02d:%02d", all/60%24, all%60);
return 0;
}
BC114 小乐乐排电梯
#include
int main()
{
int n = 0;
scanf("%d", &n);
printf("%d", (n/12)*4+2);
return 0;
}
BC115 小乐乐与欧几里得
#include
int main()
{
long long n = 0;
long long m = 0;
scanf("%lld %lld", &n, &m);
long long a = n;
long long b = m;
int t = 0;
while (t = a % b)
{
a = b;
b = t;
}
printf("%lld\n", b + m * n / b);
return 0;
}
BC116 小乐乐改数字
#include
int main()
{
int a[9];
int n, size = 0;
int sum = 0;
scanf("%d", &n);
while(n)
{
int w = n % 10;
if((w % 2) == 0)
a[size++] = 0;
else
a[size++] = 1;
n = n / 10;
}
for(int i = size - 1; i >= 0; i--)
{
sum = sum*10 + a[i];
}
printf("%d\n", sum);
return 0;
}
BC117 小乐乐走台阶
#include
int fun(int n);
int main()
{
int n = 0;
int a[35] = {0};
scanf("%d", &n);
a[0] = 0;
a[1] = 1;
a[2] = 2;
for(int i = 3; i <= n; i++)
a[i] = a[i-1] + a[i-2];
printf("%d\n", a[n]);
return 0;
}
int fun(int n)
{
if(n == 1) return 1;
if(n == 2) return 2;
return fun(n-1) + fun(n-2);
}
BC118 小乐乐与序列
#include
int main()
{
int n = 0;
int temp = 0;
scanf("%d", &n);
int arr[1000005]={0};
while(scanf("%d",&temp)!=EOF)
{
getchar();
arr[temp]++;
}
for(int i=1;i<1000005;i++)
{
if(arr[i])
{
printf("%d ",i);
}
}
return 0;
}
BC119 小乐乐与字符串
#include
int main()
{
char str[8000] = {0};
int count = 0;
scanf("%s", str);
char * p = str;
long long c = 0;
long long ch = 0;
long long chn = 0;
while(*p)
{
if(*p == 'C')
c++;
else if(*p == 'H')
ch+=c;
else if(*p == 'N')
chn += ch;
p++;
}
printf("%lld\n", chn);
return 0;
}
BC121 小乐乐学编程
#include
int main()
{
printf("Practice makes perfect!\n");
return 0;
}
BC122 小乐乐算平均分
#include
int main()
{
float a, b, c;
scanf("%f %f %f", &a, &b, &c);
printf("%.2f %.2f", (a+b+c), (a+b+c)/3);
return 0;
}
BC123 小乐乐找最大数
int main()
{
int a,b,c,d,x,y;
scanf("%d %d %d %d", &a, &b, &c, &d);
x = a > b ? a : b;
y = c > d ? c : d;
printf("%d", x > y ? x : y);
return 0;
}
BC124 小乐乐是否被叫家长
#include
int main ()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int x = a + b + c;
if(x / 3 >= 60)
{
printf("NO");
}
else
{
printf("YES");
}
return 0;
}
BC125 小乐乐转换成绩
#include
int main()
{
int score = 0;
scanf("%d", &score);
if (score >= 0 && score <= 100)
{
switch (score / 10)
{
case 10:
case 9:
printf("A\n");
break;
case 8:
printf("B\n");
break;
case 7:
printf("C\n");
break;
case 6:
printf("D\n");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
printf("E\n");
break;
}
}
else
printf("F\n");
return 0;
}
BC126 小乐乐算多少人被请家长
#include
typedef struct node
{
float Chinese;
float Math;
float English;
struct node *next;
}Node;
int main()
{
int n = 0;
Node *head = NULL;
scanf("%d", &n);
Node *tail = NULL;
for(int i = 0; i < n; i++)
{
Node *tmp = (Node *)malloc(sizeof(Node));
tmp->next = NULL;
scanf("%f %f %f", &(tmp->Chinese), &(tmp->English), &(tmp->Math));
if(head == NULL)
head = tmp;
else
tail->next = tmp;
tail = tmp;
}
Node *cur = head;
int count = 0;
while(cur)
{
if((cur->Chinese + cur->Math + cur->English) < 180.0)
count++;
cur = cur->next;
}
printf("%d\n", count);
return 0;
}
BC127 小乐乐算最高分
#include
int main()
{
int n = 0;
scanf("%d", &n);
int *arr = (int *)malloc(n * sizeof(int));
int max = 0;
for(int i = 0; i < n; i++)
{
scanf("%d ", &arr[i]);
if(arr[i] > max)
max = arr[i];
}
printf("%d\n", max);
free(arr);
return 0;
}
BC128 小乐乐计算求和
#include
int Fac(int n);
int Fac_All(int n);
int main()
{
int n = 0;
scanf("%d", &n);
int m = Fac_All(n);
printf("%d", m);
return 0;
}
int Fac(int n)
{
int sum = 1;
for(int i = n; i > 0; i--)
{
sum *= i;
}
return sum;
}
int Fac_All(int n)
{
int sum = 0;
for(int j = n; j > 0; j--)
{
sum += Fac(j);
}
return sum;
}
BC129 小乐乐计算函数
#include
int max3(int a, int b, int c)
{
return (a > b ? a : b) > c ? (a > b ? a : b) : c;
}
int main()
{
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d %d", &a, &b, &c);
float m = ((float)max3(a+b, b, c) / (max3(a, b+c, c) + max3(a, b, b+c)));
printf("%.2f\n", m);
return 0;
}
BC130 小乐乐查找数字
#include
int main()
{
int n = 0;
scanf("%d", &n);
int *arr = (int *)malloc(n * sizeof(int));
for(int i = 0; i < n; i++)
{
scanf("%d ", &arr[i]);
}
int m = 0, count = 0;
scanf("%d", &m);
for(int j = 0; j < n; j++)
{
if(arr[j] == m)
count++;
}
printf("%d", count);
free(arr);
return 0;
}
BC131 KiKi学程序设计基础
#include
int main()
{
printf("printf(\"Hello world!\\n\");\n");
printf("cout << \"Hello world!\" << endl;\n");
return 0;
}
BC132 KiKi算期末成绩
#include
int main(void)
{
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
double result = 0.2 * a + 0.1 * b + 0.2 * c + 0.5 * d;
printf("%.1f", result);
return 0;
}
BC133 KiKi说祝福语
#include
int main ()
{
int n;
scanf("%d", &n);
while(n--)
{
printf("Happy new year!Good luck!\n");
}
return 0;
}
BC134 KiKi的最高分
#include
int main()
{
int a, b, c;
scanf("%d %d %d",&a,&b,&c);
printf("%d",(a > b ? a : b) > c ? (a > b ? a : b) : c);
return 0;
}
BC135 KiKi求质数个数
#include
int main()
{
int count = 0;
int flag = 0;
for (int i = 100; i <= 999;i++)
{
flag = 1;
for (int j = 2; j < i; j++)
{
if(i % j == 0)
{
flag = 0;
break;
}
}
if(flag)
{
count++;
}
}
printf("%d", count);
return 0;
}
BC136 KiKi去重整数并排序
#include
int main()
{
int arr[1001] = {0};
int n = 0;
int tmp = 0;
scanf("%d",&n);
while(scanf("%d",&tmp)!=EOF)
{
arr[tmp]++;
};
for(int i = 0; i < 1001; i++)
{
if(arr[i] != 0)
printf("%d ", i);
}
return 0;
}
BC137 KiKi判断上三角矩阵
#include
int main()
{
int n = 0, flag = 0;
scanf("%d", &n);
int *arr = (int *)malloc(n*n*sizeof(int));
for(int i = 0; i < n*n; i++)
{
scanf("%d ", &arr[i]);
}
for(int x = 0; x < n; x++)
{
for(int y = 0; y < x; y++)
{
if(*(arr+x*n+y) != 0)
flag = 1;
}
}
if(flag == 1)
printf("NO\n");
else
printf("YES\n");
free(arr);
return 0;
}
BC138 KiKi学结构体和指针
#include
typedef struct node
{
int data;
struct node *next;
}Node;
void Creat(Node **head, int Legth);
int NodeLength(Node *head);
Node *Delete(Node *head, int da);
void printNode(Node *head);
int main()
{
Node *head = NULL;
int n = 0;
scanf("%d", &n);
Creat(&head, n);
int m = 0;
scanf("%d", &m);
head = Delete(head, m);
printf("%d\n", NodeLength(head));
printNode(head);
}
void Creat(Node **head, int Legth)
{
Node *tail = NULL;
for(int i = 0; i < Legth; i++)
{
Node *tmp = (Node *)malloc(sizeof(Node));
if(tmp != NULL)
{
scanf("%d ", &(tmp->data));
tmp->next = NULL;
if(*head == NULL)
*head = tmp;
else
tail->next = tmp;
tail = tmp;
}
}
}
int NodeLength(Node *head)
{
Node *tmp = head;
int cut = 0;
while(tmp)
{
tmp = tmp->next;
cut++;
}
return cut;
}
Node *Delete(Node *head, int da)
{
Node *pre = head;
Node *tail = head;
while(tail)
{
if(tail->data == da)
{
Node *pd = tail;
if(tail == head)
{
tail = tail->next;
head = head->next;
}
else
{
pre->next = tail->next;
tail = pre->next;
}
free(pd);
}
else
{
pre = tail;
tail = pre->next;
}
}
return head;
}
void printNode(Node *head)
{
while(head)
{
printf("%d ", head->data);
head = head->next;
}
}
BC139 KiKi定义电子日历类
#include
int main()
{
int year, month, day = 0;
scanf("%d %d %d", &year, &month, &day);
printf("%d/%d/%d", day, month, year);
}
BC140 KiKi设计类继承
#include
int main()
{
int a, b, d;
double c, pi=3.14;
scanf("%d%d",&a,&b);
scanf("%lf",&c);
scanf("%d",&d);
printf("%d\n%g\n%d\n",a*b,(pi*c*c),d*d);
return 0;
}