HRBust《程序设计基础》网络测试(一)

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;
}

 

 实在想吐槽学校的的评测系统太垃圾;

行末换行竟然会PE;

实在难以让人接受

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ou_fan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值