#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;
}
把我整吐了,这题。