重庆大学-程序设计基础-期中模拟

1.人与神

#include<bits/stdc++.h>
using namespace std;
int main(){
	cout<<"To iterate is human, to recurse divine."<<endl;
	return 0;
}

2.计算邮费(卡精度,需要用double)

#include <bits/stdc++.h>
using namespace std;
float a, pri;
int b;
char c;

int main() {
	cin >> a >> b >> c;
	if (b == 90)
		pri = a * 6.95;
	if (b == 93)
		pri = a * 7.44;
	if (b == 97)
		pri = a * 7.93;
	if (c == 'm')
		pri *= 0.95;
	if (c == 'e')
		pri *= 0.97;
	cout << fixed << setprecision(2) << pri;
	return 0;
}

3.跟奥巴马一起画方块

#include <bits/stdc++.h>
using namespace std;
int h, l;
char m;

int main() {
	cin >> l >> m;
	h = (l + 1) / 2;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= l; j++)
			cout << m;
		cout << endl;
	}
	return 0;
}

4.输出矩阵两个对角线上的数(二维数组)

#include <bits/stdc++.h>
using namespace std;
int n, a[101][101];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			cin >> a[i][j];
	for (int i = 1; i <= n - 1; i++)
		cout << a[i][i] << " ";
	cout << a[n][n] << endl;
	for (int i = 1; i <= n - 1; i++)
		cout << a[n - i + 1][i] << " ";
	cout << a[1][n];
	return 0;
}

5.输出GPLT

#include <bits/stdc++.h>
using namespace std;
string a;
int l, ng = 0, np = 0, nl = 0, nt = 0, maxx = 0;

int main() {
	cin >> a;
	l = a.length();
	for (int i = 0; i < l; i++) {
		if (a[i] == 'G' || a[i] == 'g')
			ng++;
		else if (a[i] == 'P' || a[i] == 'p')
			np++;
		else if (a[i] == 'L' || a[i] == 'l')
			nl++;
		else if (a[i] == 'T' || a[i] == 't')
			nt++;
	}
	maxx = max(ng, np);
	maxx = max(maxx, nl);
	maxx = max(maxx, nt);
	for (int i = 1; i <= maxx; i++) {
		if (ng != 0) {
			cout << "G";
			ng--;
		}
		if (np != 0) {
			cout << "P";
			np--;
		}
		if (nl != 0) {
			cout << "L";
			nl--;
		}
		if (nt != 0) {
			cout << "T";
			nt--;
		}
		if (ng == 0 && np == 0 && nl == 0 && nt == 0)
			break;
	}
	return 0;
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值