代码均为自做
题目一
给一个真分数的分子分母,输出约分后的分子分母。
#include <iostream>
using namespace std;
int getComApprox(int a, int b) {
int tmp = a;
while (b % a != 0) {
tmp = b % a;
b = a;
a = tmp;
}
return a;
}
int main()
{
int a, b;
cin >> a >> b;
int comApprox = getComApprox(a, b);
cout << a / comApprox << " " << b / comApprox << endl;
return 0;
}
题目二
八皇后
在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列或同一斜线上,问有多少种摆法。
输出:92
#include <iostream>
#include <cmath>
using namespace std;
bool check(int *place, int cnt) {
// 检查cnt号皇后的位置是否可行
for (int i = 0; i