2025年河南工業大學2025新生周賽(1)
A 誠信參賽
如果你答案錯誤,請檢查:1. 是否是英語輸入狀態下的標點符號;2. 逗號后面有個空格。
寫這類題時,建議直接復制題目需要輸出的內容粘貼到代碼里。
#include <stdio.h>
int main(void) {
printf("sheng si kan dan, cheng xin xun lian!");
return 0;
}
B 計算罰時
#include <stdio.h>
int main(void) {
int a, b;
scanf("%d %d", &a, &b);
printf("%d", a + b * 20);
return 0;
}
C 踱步
按照題目要求模擬過程即可。
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
int lengthSum = 0;
int x = 0, y = 0;
for (int i = 0; i < n; ++i) {
int direction, length;
scanf("%d %d", &direction, &length);
lengthSum += length;
if (direction == 1) {
x += length;
} else if (direction == 2) {
x -= length;
} else if (direction == 3) {
y -= length;
} else {
y += length;
}
}
printf("%d %d\n", x, y);
printf("%d\n", lengthSum);
return 0;
}
D 長跑評級
用秒表示成績,方便比較。例如 3'45'' 等于 225 秒。
#include <stdio.h>
int main(void) {
int minute, second;
int failCount = 0;
scanf("%d", &minute);
while (minute != -1) {
scanf("%d", &second);
int totalSeconds = minute * 60 + second;
if (totalSeconds <= 207) {
printf("Outstanding\n");
} else if (totalSeconds <= 222) {
printf("Good\n");
} else if (totalSeconds <= 272) {
printf("Pass\n");
} else {
printf("Fail\n");
++failCount;
}
scanf("%d", &minute);
}
printf("%d", failCount);
return 0;
}
E 找坐標
嵌套 for 循環,遍歷每一行和每一列。如果找到 k,立刻輸出然后結束程序。
#include <stdio.h>
int main(void) {
int n, k;
scanf("%d %d", &n, &k);
/* r 代表行,c 代表列 */
for (int r = 1; r <= n; ++r) {
for (int c = 1; c <= n; ++c) {
int num;
scanf("%d", &num);
if (num == k) {
printf("%d %d", r, c);
return 0;
}
}
}
return 0;
}
F 連續五天早八
判斷是否有 5 個連續的 1 即可。
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
int count = 0;
for (int i = 0; i < n; ++i) {
int haveClass;
scanf("%d", &haveClass);
if (haveClass) {
++count;
} else {
count = 0;
}
if (count == 5) {
printf("Yes");
return 0;
}
}
printf("No");
return 0;
}
G 求序列和
n 最大可以取 16,用 int 可能會溢出,因此用 long long。
這題不能用 double,因為 double 的尾數位只有 52 個二進制位,最多只能精確表示 15 或 16 個十進制有效數字。
深入了解可以搜索 IEEE754 標準相關解讀。
#include <stdio.h>
int main(void) {
int a, n;
long long sum = 0;
long long term = 0;
scanf("%d %d", &a, &n);
for (int i = 0; i < n; i++) {
term = term * 10 + a; // 構造每一項
sum += term; // 累加到總和
}
printf("%lld", sum);
return 0;
}
H ReLU 函數
分段函數,用 if 判斷 x 與 0 的大小關系。
- 如果 x ≤ 0,f(x) = 0。
- 如果 x > 0,f(x) = x。
#include <stdio.h>
int main(void) {
int x;
scanf("%d", &x);
if (x <= 0) {
printf("0");
} else {
printf("%d", x);
}
return 0;
}

浙公網安備 33010602011771號