2020-12-10

第一题

#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, e, f, g, h, i;
	cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
	int A[3][3] = { a, b, c, d, e, f, g, h, i };
	int B[3] = { 0,0,0 }, temp[3];
	for (int m = 0; m <= 2; m++) {
		for (int n = 0; n <= 2; n++) {
			B[m] += A[m][n];
		}
	}
	int max = 0;
	for (int q = 0; q <= 2; q++) {
		if (max < B[q])
			max = B[q];
	}
	for (int t = 0; t <= 2; t++) {
		if (B[t] ==max) {
			for (int m = 0; m <= 2; m++) {
				temp[m] = A[0][m];
				A[0][m] = A[t][m];
				A[t][m] = temp[m];
			}
		}
	};
	for (int i = 0; i <= 2; i++) {
		for (int j = 0; j <= 2; j++) {
			cout << A[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

第二题

#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, e, f, g, h, i;
	cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
	int A[3][3] = {a,b,c,d,e,f,g,h,i}, sum1 = 0, sum2 = 0, sum3 = 0;
	for (int j = 0; j <= 2; j++) {
		int* p = &A[j][j];
		sum3 += *p;
		for (int m = j; m <= 2 ; m++) {
			int* p1 = &A[j][m];
			sum1 += *p1;
		}
		for (int n = 0; n <= j; n++) {
			int* p2 = &A[j][n];
			sum2 += *p2;
		}
	}
	cout << sum1 <<" "<< sum2 <<" "<< sum3 << endl;
	return 0;
}

第三题

#include <iostream>
#include <string>
using namespace std;
const int SZ = 100;
int main()
{
	int i;
	string carray;
	string carray1;
	int is_palindrome = 1;
	cout << "Please input a string .." << endl;

	getline(cin, carray);
	int len1 = carray.size();
	for (i = 0; i < len1; ++i)
	{
		if ((carray[i] <= 122) && (carray[i] >= 97))
		{
			carray[i] -= 32;
			carray1 += carray[i];
		}
		else if ((carray[i] <= 90) && (carray[i] >= 65))
			carray1 += carray[i];

	}
	int len = carray1.size();
	for (int i = 0; i < len / 2; i++)
	{
		if (carray1[i] != carray1[len - 1 - i])
		{
			is_palindrome = 0;
			break;
		}
	}
	if (is_palindrome)
		cout << "The string is a palindrome" << endl;
	else
		cout << "The string is not a palindrome" << endl;
	return 0;
}

第四题

#include<iostream>
#include<vector>
#include<time.h>
using namespace std;
int main()
{
	srand(time(0));
	int n,  i = 0, a, b, c;
	cout << "请输入人数";
	cin >> n;
	vector<bool>vi(n, 1);
	int m = rand() % (n + 1);
	cout <<"随机数为"<< m << endl;
	for (a = 0; a < n - 1; ++a)
	{
		for (b = 1; b < m; ++i)
		{
			if (i >= n)
				i = i % n;
			if (vi[i] == 1)
				++b;
		}
		if (i >= n)
			i = i % n;
		while (vi[i] == 0)
		{
			++i;
			if (i >= n)
				i = i % n;
		}
		if (vi[i] == 1)
			vi[i] = 0;
	}
	for (c = 0; c < n; ++c)
	{
		if (vi[c] == 1)
			cout <<"剩下的序号为"<< c + 1 << endl;
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值