大一的第二次作业

#include <iostream>

using namespace std;

int main() {
	int  b=0,c=0,e=0;
	int arr[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> arr[i][j];
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (j > i) {
				int* a = &arr[i][j];
				b += *a;
			}
			if (j == i) {
				int* a = &arr[i][j];
				c += *a;
			}
			if (j < i) {
				int* a = &arr[i][j];
				e += *a;
			}
		}
	}
				for (int i = 0; i < 3; i++) {
					for (int j = 0; j < 3; j++) {
						cout << arr[i][j];
					}
					cout << endl;
				}
				cout << b << ends << c << ends << e << endl;
			return 0;
		}

还行

#include <iostream>
#include <string>
using namespace std;
int s = 0;
int main() {
	string a, b;
	cout << "请输入一串 “#!@#! ”字符" << endl;
	getline(cin, a);
	s = a.size();
	for (int i = 0; i < s; i++) {
		if ((a[i] >= 65 && a[i] <= 90) || (a[i] >= 97 && a[i] <= 122)) {
			if (a[i] >= 65 && a[i] <= 90) {
				a[i] = a[i] + 32; b = b + a[i];
			}
			else b = b + a[i];
		}
	}int d = 0; cout << b << endl;
	int c = b.size();
	for (int i = 0; i < c / 2; i++) {
		if (b[i] != b[c - 1 - i]) {
			d = 1;
			break;
		}
	}if (d == 1) {
		cout << "不是回文。" << endl;
	}
	else cout << "是回文。";


	return 0;
}

也还行,getline(cin, a);这很重要。

#include <iostream>

using namespace std;

int main() {
	int  b = 0, c = 0, e = 0;
	int arr[3][3];
	cout << "输入9个元素。"<< endl;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> arr[i][j];
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (j > i) {
				int* a = &arr[i][j];
				b += *a;
			}
			if (j == i) {
				int* a = &arr[i][j];
				c += *a;
			}
			if (j < i) {
				int* a = &arr[i][j];
				e += *a;
			}
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cout << arr[i][j];
		}
		cout << endl;
	}
	cout << b << ends << c << ends << e << endl;
	return 0;

比之前两题简单。

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
	int n , m, b = 0;
	cin >> n;
	srand (time(0));
	m = rand() % n + 1;
	vector <int>a1;
	for (int a = 0; a < n; a++) {
		a1.push_back(a + 1);
	}
	for (int i = 0; i < a1.size(); i++) {
		cout << a1[i];
	}
	for (int a = 1, o = 1; a != 0; a++) {
		if (a1[a - 1] != 0) {
			if (o % m == 0) {
				a1[a - 1] = 0;
			}	o++;
		}
		for (int a = 1, s = 0; a <= n; a++) {
			if (a1[a - 1] == 0) { s = s + 1; }
			if (s == n - 1) { b =  1; }
		}if (a == n)a = 0; 
		if (b == 1)break;
		}
		for (int i = 0; i < n; i++) {
			if (a1[i] != 0)cout << endl << a1[i];
		}
		return 0;
}

把我整吐了,这题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值