This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症 ~~~
//水仙花数
for (int i = 100; i < 999; i++) {
int a = i / 100;
int b = i / 10 % 10;
int c = i % 10;
if (pow(a, 3) + pow(b, 3) + pow(c, 3) == (100 * a + b * 10 + c)) {
cout << i << endl;
}
}
return 0;
}

View File

@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
//ios::sync_with_stdio(false); //读入输出优化的强迫症
int a, b, c;
cin >> a >> b >> c;
bool found = false;
for (int i = 10; i < 100; i++) {
if (i % 3 == a && i % 5 == b && i % 7 == c) {
found = true;
cout << i << endl;
}
}
if (!found) {
cout << "No answer" << endl;
}
return 0;
}

View File

@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
//倒三角形
ios::sync_with_stdio(false); //读入输出优化的强迫症
int n;
cin >> n;
int i, j;
for (i = 1; i <= n; i++) {
//打印空格
for (j = 1; j <= (i - 1); j++) {
cout << " ";
}
//打印#
for (j = 1; j <= (2 * (n - i + 1) - 1); j++) {
cout << "#";
}
cout << endl;
}
return 0;
}

View File

@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症
int n, m;
int num = 0;
//设置输出为小数点后5位
cout << fixed << setprecision(5);
while (true) {
cin >> n >> m;
num++;
if (n == 0 && m == 0) break;
double sum = 0.0;
for (int i = n; i <= m; i++) {
sum += 1 / pow(i, 2);
}
cout << "Case "<<num<<":"<<sum << endl;
}
return 0;
}

View File

@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症
int a, b, c;
while (true) {
cin >> a >> b >> c;
//设置输出为小数点后c位
cout << fixed << setprecision(c);
if (a == 0 && b == 0 && c == 0) break;
double d = 1.0 * a / b;
cout << d << endl;
}
return 0;
}

View File

@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
bool NoChongFu(int a) {
int i_a, i_b, i_c;
i_a = a / 100;
i_b = a / 10 % 10;
i_c = a % 10;
if (i_a == i_c || i_a == i_c || i_b == i_c) return false;
return true;
}
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症
for (int i = 100; i <= 999; i++) {
if (!NoChongFu(i)) continue;
for (int j = 100; j <= 999; j++) {
if (j == i) continue;
if (!NoChongFu(j)) continue;
for (int k = 100; k <= 999; k++) {
if (k == i) continue;
if (k == j) continue;
if (!NoChongFu(k)) continue;
if (i * 6 == j * 3 && j * 3 == k * 2) {
cout << i << " " << j << " " << k << endl;
}
}
}
}
return 0;
}

View File

@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;
const char *rev = "A 3 HILJM O 2TUVWXY51SE Z 8 ";
const char *msg[] = {"not a palindrome",
"a regular palindrome",
"a mirrored string",
"a mirrored palindrome"};
char r(char ch) {
if (isalpha(ch)) return rev[ch - 'A'];//如果是字符,那么计算出它所在的索引号,比如是A,那么索引号是0
else return rev[ch - '0' + 25]; //如果是数字,那么-'0'就是0,+25就是数字对应的索引号
}
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症
char s[30];
while (scanf("%s", s) == 1) {
int len = strlen(s);
int p = 1, m = 1;
for (int i = 0; i < (len + 1) / 2; i++) {
//折半去看
if (s[i] != s[len - 1 - i]) p = 0;
if (r(s[i]) != s[len - 1 - i]) m = 0;
}
//这个msg的数组索引用的好,有点二进制的意思~
printf("%s-- is %s.\n\n", s, msg[m * 2 + p]);
}
return 0;
}

View File

@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;
#define maxn 1010
int main(void) {
int n, i, j, k = 0;
int a[maxn], b[maxn];
while (scanf("%d", &n) == 1 && n)//n=0时输入结束
{
printf("Game %d:\n", ++k);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
while (1)//可改为for(;;)
{
int A = 0, B = 0, count = 0;
for (i = 0; i < n; i++) {
scanf("%d", &b[i]);
if (a[i] == b[i]) A++;
if (b[i] == 0) count++;//统计输入0的个数
}
if (count == n) break;//如果四位数皆为零,则输入结束
for (j = 0; j <= 9; j++) {
int a1 = 0, a2 = 0;//统计数字j在答案序列和猜测序列中各出现多少次数
for (i = 0; i < n; i++) {
if (a[i] == j) a1++;//统计a[i]、b[i]中j的个数
if (b[i] == j) a2++;
}
if (a1 < a2) B = B + a1;//记统计的最小的个数 即为序列拥有相同元素的个数
else B = B + a2;
}
printf(" (%d,%d)\n", A, B - A);//B减去相同位置的个数A,即为元素相同,但位置不同的个数
}
}
}

View File

@@ -0,0 +1,18 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症
int c, q = 1;
//在windows平台,stdin输入流的EOF标志是 ctrl + z,然后回车就结束了!在黑窗口下试试,
// Clion中需要进入调试模式,然后ctrl+d 即可退出
//参考:https://www.zhihu.com/question/41952758
while ((c = getchar()) != EOF) {
if (c == '"') {
printf("%s", q ? "``" : "''");
q = !q;
} else printf("%c", c);
}
return 0;
}