```cpp
#include<iostream>
using namespace std;
int main() {
int arr[3][4] = { {1,2,3,4},
{5,6,7,8},
{9,8,7,6} };
int sum[3] = {0}, i, j, a, k(1),q;
for (i = 0; i <= 2; ++i) {
for (j = 0; j <= 3; ++j) {
sum[i] += arr[i][j];
}
}
for (a = sum[0]; k <= 3; k++) {
if (sum[k] > a) { a = sum[k]; q = k; }
}
for (j = 0; j <= 3; j++) {
k = arr[0][j];
arr[0][j] = arr[q][j];
arr[q][j] = k;
}
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 3; ++j) {
cout << arr[i][j];
}
cout << endl;
}
return 0;
}
```cpp
#include<iostream>
using namespace std;
int main() {
int arr[3][3] = {
{1,2,3},
{3,4,5},
{6,7,8} };
int sum1(0), sum2(0), sum3(0);
int(*p)[3] = arr;
for (int i = 0; i <= 2; ++i) {
for (int j = 0; j <= i; ++j) {
sum1 += *(*(p + i) +j);
}
for (int j = 2; j >= i; --j) {
sum2 += *(*(p + i) + j);
}
sum3 += *(*(p + i) + i); }
cout << "下三角所有元素的和为:" << sum1 << endl;
cout << "上三角所有元素的和为:"<<sum2 << endl;
cout << "对角线所有元素的和为:" << sum3 << endl;
return 0;
}
``
#include<iostream>
#include<string>
using namespace std;
int main() {
string carray1, carray2;
cout << "请输入一段英文:" << endl;
cin >> carray1;
int len1= carray1.size();
for (int i = 0; i <= len1; i++) {
if (carray1[i] <= 57 && carray1[i] >= 48) { carray2 += carray1[i]; }
if (carray1[i] >= 65 && carray1[i] <= 90) { carray1[i] += 32; carray2+=carray1[i]; }
if (carray1[i] >= 97 && carray1[i] <= 122) { carray2 += carray1[i]; }
}
int len2 = carray2.size();
int is_palindrome=1;
for (int i = 0; i <= len2; i++) {
if (carray2[i] != carray2[len2 - 1 - i]) { is_palindrome = 0; break; }
}
if (is_palindrome ==0) {
cout << "it is not a palindrome" << endl;
}
else cout << "it is a palindrome" << endl;
return 0;
}
第三个问题,建立两个string,一个输入,一个保存数字和字母,再通过判断即可得出。
第四个问题想了许久感觉还是有点不太正确,我周末再想想#include<iostream>
#include<vector>
#include<cstdlib>
#include <time.h>
using namespace std;
int main() {
int m,n;
cin >> n;
srand(0);
m = rand() % n;
vector<int>vi;
cout << m;
for (int i = 0; i < n; ++i) {
vi.push_back(i);//这里创建的一个容器,添加n个数
for (int s=0; vi.size() != 1;) {
s = (s + m ) % vi.size();
vi.erase(vi.begin() + (s - 1));
}
cout << *vi.begin() + 1;
}
}