A题
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define Bug cout<<"---------------------"<<endl
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
while (n--) {
int num;
cin >> num;
if (num >= 5000) {
cout << num - 700 << endl;
}
else if (num >= 3000) {
cout << num - 500 << endl;
}
else if (num >= 1000) {
cout << num - 300 << endl;
}
}
return 0;
}
B题
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define Bug cout<<"---------------------"<<endl
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
char ch;
cin >> ch;
int num2 = n / 2;
for (int i = 1;i <= num2;i++) {
if (i == 1) {
for (int i = 1;i <= n;i++) {
cout << ch;
}
cout << endl;
}
else if (i != 1 && i != num2) {
for (int i = 1;i <= n;i++) {
if (i == 1) {
cout << ch;
}
else if (i != 1 && i != n) {
cout << ' ';
}
if (i == n) {
cout << ch;
}
}
cout << endl;
}
else if (i == num2) {
for (int i = 0;i < n;i++) {
cout << ch;
}
}
}
}
C 题
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define Bug cout<<"---------------------"<<endl
using namespace std;
const int N = 1e5 + 10;
bool prime(int n) {
if (n < 2) return false;
for (int i = 2;i <= n / i;i++) {//i<=n/i这一步很关键!!
if (n % i == 0) {
return false;
}
}
return true;
}
int arr[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
int j = 0;
int cnt = 0;
for (int i = 1;i <= n;i++) {
if (prime(i)) {
arr[j++] = i;
cnt++;
}
}
int ans = 0;
for (int i = 1;i <= cnt;i++) {
if (arr[i-1] == arr[i]-2) {
ans++;
}
}
cout << ans;
}
D题
#include <bits/stdc++.h> #define endl '\n' using namespace std; void input(int a[], int m) { for (int i = 1;i <= m;i++) { cin >> a[i]; } } int search(int a[], int i, int m) { for (int j = 1;j <= m;j++) { if (a[j] == i) { return j; } } return 0; } int searchfather(int pos) { return pos / 2; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; while (n--) { int a[100] = { 0 }, m, i, found; cin >> m; input(a, m); cin >> i; found = search(a, i, m); if (found == 0) { cout << i << " does not exist." << endl; } else { int father = searchfather(found); cout << i << "\'s father is No." << father << "-->" << a[father] << endl; } } return 0; }