提交 f0b95a70 编写于 作者: ToTensor's avatar ToTensor

send topic success

上级 40c57a83
......@@ -2,58 +2,130 @@
<p>设有n种不同面值的硬币&#xff0c;第i种硬币的币值是Vi(其中V1&#61;1),重量是Wi,i&#61;1,2&#xff0c;...n且现在购买某种总币值为y的商品&#xff0c;需要用这些硬币付款&#xff0c;如果每种钱币使用的个数不限&#xff0c;那么如何选择付款的方法使得付出钱币的总重量最轻&#xff1f;使用动态规划设计策略设计一个求解该问题的算法。假设问题的输入实例是&#xff1a;</p><p style="margin-left:.38in">V1&#61;1&#xff0c; V2&#61;4&#xff0c; V3&#61;6&#xff0c; V4&#61;8</p><p style="margin-left:.38in">W1&#61;1&#xff0c; W2&#61;2&#xff0c;W3&#61;4&#xff0c;W4&#61;6</p><p style="margin-left:.38in">Y&#61;12</p><p>要求输出优化函数表和标记函数表、以及硬币支付方式。</p>
以下程序实现了这一功能,请你填补空白处的内容:
```cpp
#include <stdio.h>
void strcpy(int *a, int *b, int Y)
{
for (int i = 0; i <= Y; i++)
*(a + i) = *(b + i);
}
void solve()
{
int n;
scanf("%d", &n);
int type[n], weight[n], Y, i, j, k;
for (i = 0; i < n; i++)
scanf("%d", &type[i]);
for (i = 0; i < n; i++)
scanf("%d", &weight[i]);
scanf("%d", &Y);
int Min[Y + 1], Min_Path[Y + 1], path[n][Y + 1];
for (i = 0; i <= Y; i++)
Min[i] = 9999;
Min[0] = 0;
printf("\n");
for (j = 0; j < n; j++)
{
___________________
for (k = 1; k <= Y; k++)
printf("%-3d", Min[k]);
printf("\n");
strcpy(path[j], Min_Path, Y);
}
printf("\n");
for (i = 0; i < n; i++)
{
for (j = 1; j <= Y; j++)
printf("%-3d", path[i][j]);
printf("\n");
}
int y = Y;
printf("\n支付方式:");
while (y)
{
printf("%d ", Min_Path[y]);
y -= Min_Path[y];
}
printf("\n总重量:%d\n", Min[Y]);
}
int main()
{
solve();
return 1;
}
```
## template
```cpp
#include<stdio.h>
void strcpy(int *a, int *b, int Y){
for(int i=0;i<=Y;i++) *(a+i) = *(b+i);
#include <stdio.h>
void strcpy(int *a, int *b, int Y)
{
for (int i = 0; i <= Y; i++)
*(a + i) = *(b + i);
}
void solve(){
int n; scanf("%d",&n);
int type[n], weight[n], Y, i, j, k;
for(i=0;i<n;i++) scanf("%d",&type[i]);
for(i=0;i<n;i++) scanf("%d",&weight[i]);
scanf("%d",&Y);
int Min[Y+1], Min_Path[Y+1], path[n][Y+1];
for(i=0;i<=Y;i++) Min[i] = 9999;
Min[0] = 0;
printf("\n");
for(j=0;j<n;j++){
for(i=type[j]; i<=Y; i++)
if(Min[i] > Min[i-type[j]]+weight[j]){
Min_Path[i] = type[j];
Min[i] = Min[i-type[j]]+weight[j];
}
for(k=1;k<=Y;k++) printf("%-3d",Min[k]);
printf("\n");
strcpy(path[j],Min_Path,Y);
}
printf("\n");
for(i=0;i<n;i++){
for(j=1;j<=Y;j++)
printf("%-3d",path[i][j]);
printf("\n");
}
int y=Y;
printf("\n支付方式:");
while (y){
printf("%d ",Min_Path[y]);
y -= Min_Path[y];
}
printf("\n总重量:%d\n",Min[Y]);
void solve()
{
int n;
scanf("%d", &n);
int type[n], weight[n], Y, i, j, k;
for (i = 0; i < n; i++)
scanf("%d", &type[i]);
for (i = 0; i < n; i++)
scanf("%d", &weight[i]);
scanf("%d", &Y);
int Min[Y + 1], Min_Path[Y + 1], path[n][Y + 1];
for (i = 0; i <= Y; i++)
Min[i] = 9999;
Min[0] = 0;
printf("\n");
for (j = 0; j < n; j++)
{
for (i = type[j]; i <= Y; i++)
if (Min[i] > Min[i - type[j]] + weight[j])
{
Min_Path[i] = type[j];
Min[i] = Min[i - type[j]] + weight[j];
}
for (k = 1; k <= Y; k++)
printf("%-3d", Min[k]);
printf("\n");
strcpy(path[j], Min_Path, Y);
}
printf("\n");
for (i = 0; i < n; i++)
{
for (j = 1; j <= Y; j++)
printf("%-3d", path[i][j]);
printf("\n");
}
int y = Y;
printf("\n支付方式:");
while (y)
{
printf("%d ", Min_Path[y]);
y -= Min_Path[y];
}
printf("\n总重量:%d\n", Min[Y]);
}
int main(){
solve();
return 1;
int main()
{
solve();
return 1;
}
```
## 答案
```cpp
for (i = type[j]; i <= Y; i++)
if (Min[i] > Min[i - type[j]] + weight[j])
{
Min_Path[i] = type[j];
Min[i] = Min[i - type[j]] + weight[j];
}
```
## 选项
......@@ -61,17 +133,32 @@ int main(){
### A
```cpp
for (i = type[j]; i <= Y; i++)
if (Min[i] < Min[i - type[j]] + weight[j])
{
Min_Path[i] = type[j];
Min[i] = Min[i - type[j]] + weight[j];
}
```
### B
```cpp
for (i = type[j]; i <= Y; i++)
if (Min[i] > Min[i - type[j]] + weight[j])
{
Min_Path[i] = type[j];
Min[i] = Min[i - type[j]];
}
```
### C
```cpp
for (i = type[j]; i <= Y; i++)
if (Min[i] < Min[i - type[j]] + weight[j])
{
Min_Path[i] = type[j];
Min[i] = Min[i - type[j]];
}
```
\ No newline at end of file
# 计算出现次数最多的整数及其出现次数
<p>【问题描述】
输入一组无序的整数&#xff0c;编程输出其中出现次数最多的整数及其出现次数。
【输入形式】
先从标准输入读入整数的个数&#xff08;大于等于1&#xff0c;小于等于100&#xff09;&#xff0c;然后在下一行输入这些整数&#xff0c;各整数之间以一个空格分隔。
【输出形式】
在标准输出上输出出现次数最多的整数及其出现次数&#xff0c;两者以一个空格分隔&#xff1b;若出现次数最多的整数有多个&#xff0c;则按照整数升序分行输出。
【样例输入】
10
0 -50 0 632 5813 -50 9 -50 0 632
【样例输出】
-50 3
0 3
【样例说明】
输入一组无序的整数&#xff0c;编程输出其中出现次数最多的整数及其出现次数。</br>
【输入形式】</br>
先从标准输入读入整数的个数&#xff08;大于等于1&#xff0c;小于等于100&#xff09;&#xff0c;然后在下一行输入这些整数&#xff0c;各整数之间以一个空格分隔。</br>
【输出形式】</br>
在标准输出上输出出现次数最多的整数及其出现次数&#xff0c;两者以一个空格分隔&#xff1b;若出现次数最多的整数有多个&#xff0c;则按照整数升序分行输出。</br>
【样例输入】</br>
10</br>
0 -50 0 632 5813 -50 9 -50 0 632</br>
【样例输出】</br>
-50 3</br>
0 3</br>
【样例说明】</br>
输入了10个整数&#xff0c;其中出现次数最多的是-50和0&#xff0c;都是出现3次。</p>
以下程序实现了这一功能,请你填补空白处的内容:
```cpp
#include <stdio.h>
int main()
{
int a[50], b[50], c[50], n, i, j, t, max;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (i = 1; i < n; i++)
for (j = 0; j < n - 1; j++)
{
if (a[j] > a[j + 1])
{
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
j = 0;
t = -1;
for (i = 0; i < n - 1; i++)
{
____________________
}
b[j] = n - 1 - t;
c[j] = n - 1;
max = b[0];
for (i = 1; i <= j; i++)
{
if (max < b[i])
{
max = b[i];
}
}
for (i = 0; i <= j; i++)
if (b[i] == max)
{
t = c[i];
printf("%d %d\n", a[t], b[i]);
}
return 0;
}
```
## template
```cpp
#include <stdio.h>
int main()
{
int a[50],b[50],c[50],n,i,j,t,max;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<n;i++)
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
j=0;
t=-1;
for(i=0;i<n-1;i++)
{
if(a[i]!=a[i+1])
{
b[j]=i-t;
c[j]=i;
t=i;
j++;
}
}
b[j]=n-1-t;
c[j]=n-1;
max=b[0];
for(i=1;i<=j;i++)
{
if(max<b[i])
{
max=b[i];
}
}
for(i=0;i<=j;i++)
if(b[i]==max)
{
t=c[i];
printf("%d %d\n",a[t],b[i]);
}
return 0;
int a[50], b[50], c[50], n, i, j, t, max;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (i = 1; i < n; i++)
for (j = 0; j < n - 1; j++)
{
if (a[j] > a[j + 1])
{
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
j = 0;
t = -1;
for (i = 0; i < n - 1; i++)
{
if (a[i] != a[i + 1])
{
b[j] = i - t;
c[j] = i;
t = i;
j++;
}
}
b[j] = n - 1 - t;
c[j] = n - 1;
max = b[0];
for (i = 1; i <= j; i++)
{
if (max < b[i])
{
max = b[i];
}
}
for (i = 0; i <= j; i++)
if (b[i] == max)
{
t = c[i];
printf("%d %d\n", a[t], b[i]);
}
return 0;
}
```
## 答案
```cpp
if (a[i] != a[i + 1])
{
b[j] = i - t;
c[j] = i;
t = i;
j++;
}
```
## 选项
......@@ -80,17 +134,35 @@ int main()
### A
```cpp
if (a[i] != a[i + 1])
{
b[j] = i + t;
c[j] = i - 1;
t = i;
j++;
}
```
### B
```cpp
if (a[i] != a[i + 1])
{
b[j] = i + t;
c[j] = i + 1;
t = i;
j++;
}
```
### C
```cpp
if (a[i] != a[i + 1])
{
b[j] = i + t;
c[j] = i;
t = i;
j++;
}
```
\ No newline at end of file
# 六角填数
<p>![图片说明](https://img-ask.csdn.net/upload/202006/14/1592104139_240178.png)
六角填数
题目描述
![图片说明](https://img-ask.csdn.net/upload/202006/14/1592104139_240178.png)
**题目描述**
如下图所示六角形中,有12个点,依次填入1~12的数字,使得每条直线上的数字之和都相同。其中,已经替你填好了点1,2,3的数字,请你计算其他位置所代表的数字是多少?
输入
**输入**
输入仅一行,以空格隔开,分别表示已经填好的点1,2,3的数字。
输出
**输出**
输出仅一行,以空格隔开,分别表示所有位置所代表的数字。
样例输入:
**样例输入:**
```json
1 8 2
样例输出:
1 8 2 9 7 11 10 12 3 5 6 4</p>
```
**样例输出:**
```json
1 8 2 9 7 11 10 12 3 5 6 4
```
以下程序实现了这一功能,请你填补空白处的内容:
```cpp
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define eps 10e-10
#define N 15
int a[N];
bool vis[N];
void dfs(int x)
{
if (x == 1 || x == 2 || x == 3)
{
dfs(x + 1);
return;
}
if (x > 12)
{
int t[6];
t[0] = a[1] + a[3] + a[6] + a[8];
t[1] = a[1] + a[4] + a[7] + a[11];
t[2] = a[2] + a[3] + a[4] + a[5];
t[3] = a[2] + a[6] + a[9] + a[12];
t[4] = a[8] + a[9] + a[10] + a[11];
t[5] = a[12] + a[10] + a[7] + a[5];
for (int i = 1; i < 6; ++i)
{
if (t[i] != t[i - 1])
return;
}
for (int i = 1; i <= 12; i++)
cout << a[i] << " ";
return;
}
for (int i = 1; i < 13; ++i)
{
________________
}
}
int main()
{
memset(vis, 0, sizeof(vis));
cin >> a[1];
vis[a[1]] = 1;
cin >> a[2];
vis[a[2]] = 1;
cin >> a[3];
vis[a[3]] = 1;
dfs(1);
return 0;
}
```
## template
......@@ -25,51 +94,66 @@ using namespace std;
#define N 15
int a[N];
bool vis[N];
void dfs(int x){
if(x == 1 || x == 2 || x == 3){
dfs(x+1);
return ;
}
if(x > 12){
int t[6];
t[0] = a[1] + a[3] + a[6] + a[8];
t[1] = a[1] + a[4] + a[7] + a[11];
t[2] = a[2] + a[3] + a[4] + a[5];
t[3] = a[2] + a[6] + a[9] + a[12];
t[4] = a[8] + a[9] + a[10] + a[11];
t[5] = a[12] + a[10] + a[7] + a[5];
for(int i = 1; i < 6; ++i){
if(t[i] != t[i-1])return ;
}
for (int i = 1; i <= 12; i++) cout << a[i] << " ";
return ;
}
for(int i = 1;i < 13; ++i){
if(!vis[i]){
vis[i] = 1;
a[x] = i;
dfs(x+1);
vis[i] = 0;
}
}
void dfs(int x)
{
if (x == 1 || x == 2 || x == 3)
{
dfs(x + 1);
return;
}
if (x > 12)
{
int t[6];
t[0] = a[1] + a[3] + a[6] + a[8];
t[1] = a[1] + a[4] + a[7] + a[11];
t[2] = a[2] + a[3] + a[4] + a[5];
t[3] = a[2] + a[6] + a[9] + a[12];
t[4] = a[8] + a[9] + a[10] + a[11];
t[5] = a[12] + a[10] + a[7] + a[5];
for (int i = 1; i < 6; ++i)
{
if (t[i] != t[i - 1])
return;
}
for (int i = 1; i <= 12; i++)
cout << a[i] << " ";
return;
}
for (int i = 1; i < 13; ++i)
{
if (!vis[i])
{
vis[i] = 1;
a[x] = i;
dfs(x + 1);
vis[i] = 0;
}
}
}
int main(){
memset(vis,0,sizeof(vis));
cin >> a[1];
vis[a[1]] = 1;
cin >> a[2];
vis[a[2]] = 1;
cin >> a[3];
vis[a[3]] = 1;
dfs(1);
return 0;
int main()
{
memset(vis, 0, sizeof(vis));
cin >> a[1];
vis[a[1]] = 1;
cin >> a[2];
vis[a[2]] = 1;
cin >> a[3];
vis[a[3]] = 1;
dfs(1);
return 0;
}
```
## 答案
```cpp
if (!vis[i])
{
vis[i] = 1;
a[x] = i;
dfs(x + 1);
vis[i] = 0;
}
```
## 选项
......@@ -77,17 +161,35 @@ int main(){
### A
```cpp
if (!vis[i])
{
vis[i] = 1;
a[x] = i;
dfs(x - 1);
vis[i] = 0;
}
```
### B
```cpp
if (!vis[i])
{
vis[i] = 0;
a[x] = i;
dfs(x + 1);
vis[i] = 1;
}
```
### C
```cpp
if (!vis[i])
{
vis[i] = 0;
a[x] = i + 1;
dfs(x + 1);
vis[i] = 1;
}
```
\ No newline at end of file
# 阶乘和数
一个正整数如果等于组成它的各位数字的阶乘之和,该整数称为阶乘和数。
例如,145=1!+4!+5!,则145是一个三位阶乘和数。
请输出所有阶乘数(不会超过十万)
以下程序实现了这一功能,请你填补空白处的内容:
```cpp
#include <stdio.h>
int b[10] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
int main()
{
int x, sum = 0, a;
for (int j = 1; j <= 100000; j++)
{
sum = 0;
a = j;
while (j != 0)
{
______________
}
j = a;
if (sum == a)
{
printf("%d ", j);
}
}
return 0;
}
```
## template
```cpp
#include <stdio.h>
int b[10] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
int main(){
    int x, sum = 0, a;
    for(int j = 1; j <= 100000; j++){
        sum = 0; 
        a = j;
        while(j != 0){
            x = j % 10;
            j /= 10;
            sum += b[x];
        }
        j = a;
        if(sum == a){
            printf("%d ", j);
        }
    }
    return 0;
} 
int main()
{
int x, sum = 0, a;
for (int j = 1; j <= 100000; j++)
{
sum = 0;
a = j;
while (j != 0)
{
x = j % 10;
j /= 10;
sum += b[x];
}
j = a;
if (sum == a)
{
printf("%d ", j);
}
}
return 0;
}
```
## 答案
```cpp
x = j % 10;
j /= 10;
sum += b[x];
```
## 选项
......@@ -39,17 +73,23 @@ int main(){
### A
```cpp
x = j / 10;
j %= 10;
sum += b[x];
```
### B
```cpp
x = j % 10;
j %= 10;
sum += b[x];
```
### C
```cpp
x = j / 10;
j /= 10;
sum += b[x];
```
\ No newline at end of file
......@@ -2,6 +2,52 @@
<p>在主函数中随机生成一有n个元素的一维数组(元素的取值范围载10-90之间),调用排序函数对该数组进行排序,并输出排序结果。</p>
以下程序实现了这一功能,请你填补空白处的内容:
```cpp
#include <stdio.h>
#include <random>
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
void InsertSort(int a[], int n)
{
for (int i = 1; i < n; i++)
{
if (a[i] < a[i - 1])
{
int j = i - 1;
int x = a[i];
________________
}
}
}
int main()
{
cout << "请输入产生多个随机数:";
int ranNum[100], num = 0;
srand((unsigned)time(NULL));
cin >> num;
cout << "随机数组:";
for (int i = 0; i < num; i++)
{
ranNum[i] = 10 + (rand() % 80);
cout << " " << ranNum[i];
}
cout << endl;
InsertSort(ranNum, num);
cout << "排序后整数序列:";
for (int j = num - 1; j >= 0; j--)
{
cout << ranNum[j] << " ";
}
cout << endl;
system("pause");
return 0;
}
```
## template
```cpp
......@@ -13,47 +59,57 @@
using namespace std;
void InsertSort(int a[], int n)
{
for (int i = 1; i<n; i++) {
if (a[i] < a[i - 1]) {
int j = i - 1;
int x = a[i];
a[i] = a[i - 1];
while (x < a[j]) {
for (int i = 1; i < n; i++)
{
if (a[i] < a[i - 1])
{
int j = i - 1;
int x = a[i];
a[i] = a[i - 1];
while (x < a[j])
{
a[j + 1] = a[j];
j--;
j--;
}
a[j + 1] = x;
}
}
a[j + 1] = x;
}
}
}
int main()
{
cout << "请输入产生多个随机数:";
int ranNum[100],num = 0;
srand((unsigned)time(NULL));
cin >> num;
cout << "随机数组:";
for (int i = 0; i < num; i++)
{
ranNum[i] = 10 + (rand() % 80);
cout << " " << ranNum[i];
}
cout << endl;
InsertSort(ranNum, num);
cout << "排序后整数序列:";
for (int j = num-1; j >= 0; j--) {
cout << ranNum[j] << " ";
}
cout << endl;
system("pause");
return 0;
cout << "请输入产生多个随机数:";
int ranNum[100], num = 0;
srand((unsigned)time(NULL));
cin >> num;
cout << "随机数组:";
for (int i = 0; i < num; i++)
{
ranNum[i] = 10 + (rand() % 80);
cout << " " << ranNum[i];
}
cout << endl;
InsertSort(ranNum, num);
cout << "排序后整数序列:";
for (int j = num - 1; j >= 0; j--)
{
cout << ranNum[j] << " ";
}
cout << endl;
system("pause");
return 0;
}
```
## 答案
```cpp
a[i] = a[i - 1];
while (x < a[j])
{
a[j + 1] = a[j];
j--;
}
a[j + 1] = x;
```
## 选项
......@@ -61,17 +117,35 @@ int main()
### A
```cpp
a[i] = a[i - 1];
while (x < a[j])
{
a[j + 1] = a[j];
j++;
}
a[j + 1] = x;
```
### B
```cpp
a[i] = a[i - 1];
while (x < a[j])
{
a[j - 1] = a[j];
j--;
}
a[j - 1] = x;
```
### C
```cpp
a[i] = a[i - 1];
while (x < a[j])
{
a[j - 1] = a[j];
j++;
}
a[j + 1] = x;
```
\ No newline at end of file
# 结合两个字符串
写一个结合两个字符串的方法,从第一个字符串中取出一个字符,然后从第二个字符串中取出一个字符,以此类推。一旦一个字符串没有字符,它就应该继续使用另一个字符串
输入:两个字符串,如s1="day"和s2="time"
输出:一个结果字符串,对于上面的输入情况,它将是“dtaiyme”。
以下程序实现了这一功能,请你填补空白处的内容:
```cpp
#include <iostream>
#include <string>
using namespace std;
string StrCon(const string& a, const string& b)
{
string c;
int n = a.size(), m = b.size();
if (0 == n) return a;
if (0 == m) return b;
int i, j;
for (i = 0, j = 0; i < n && j < m; ++i, ++j)
{
c += a[i];
c += b[i];
}
__________________
return c;
}
int main()
{
string s = "day", t = "time";
cout << StrCon(s, t) << endl;
system("pause");
return 0;
}
```
## template
```cpp
......@@ -40,7 +72,10 @@ int main()
## 答案
```cpp
while (i < n)
c += a[i++];
while (j < m)
c += b[j++];
```
## 选项
......@@ -48,17 +83,26 @@ int main()
### A
```cpp
while (i > n)
c += a[i++];
while (j < m)
c += b[j++];
```
### B
```cpp
while (i > n)
c += a[i++];
while (j > m)
c += b[j++];
```
### C
```cpp
while (i < n)
c += a[i++];
while (j > m)
c += b[j++];
```
\ No newline at end of file
......@@ -4,6 +4,30 @@
例如给定序列&#xff1a; 99 35 83 38 &#xff0c; 处理完成后得到&#xff1a;38 83 99 35
给定序列&#xff1a; 6 7 3 4 &#xff0c;处理完成后得到&#xff1a;3 4 6 7</p>
以下程序实现了这一功能,请你填补空白处的内容:
```cpp
#include <stdio.h>
#include <math.h>
int main()
{
int i, j, n, a[10005], t;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
if (i % 2 == 1)
{
__________________
}
}
for (i = n - 1; i >= 0; i--)
{
printf("%d ", a[i]);
}
}
```
## template
```cpp
......@@ -11,28 +35,37 @@
#include <math.h>
int main()
{
int i,j,n,a[10005],t;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(i%2==1){
if((a[i]%3==0)||(a[i]%5==0)||(a[i-1]%3==0)||(a[i-1]%5==0)){
t=a[i];
a[i]=a[i-1];
a[i-1]=t;
}
}
}
for(i=n-1;i>=0;i--){
printf("%d ",a[i]);
}
int i, j, n, a[10005], t;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
if (i % 2 == 1)
{
if ((a[i] % 3 == 0) || (a[i] % 5 == 0) || (a[i - 1] % 3 == 0) || (a[i - 1] % 5 == 0))
{
t = a[i];
a[i] = a[i - 1];
a[i - 1] = t;
}
}
}
for (i = n - 1; i >= 0; i--)
{
printf("%d ", a[i]);
}
}
```
## 答案
```cpp
if ((a[i] % 3 == 0) || (a[i] % 5 == 0) || (a[i - 1] % 3 == 0) || (a[i - 1] % 5 == 0))
{
t = a[i];
a[i] = a[i - 1];
a[i - 1] = t;
}
```
## 选项
......@@ -40,17 +73,32 @@ int main()
### A
```cpp
if ((a[i] % 3 == 0) || (a[i] % 5 == 0))
{
t = a[i];
a[i] = a[i - 1];
a[i - 1] = t;
}
```
### B
```cpp
if (((a[i - 1] % 3 == 0) || (a[i - 1] % 5 == 0))
{
t = a[i];
a[i] = a[i - 1];
a[i - 1] = t;
}
```
### C
```cpp
if ((a[i] % 3 == 0) && (a[i] % 5 == 0) && (a[i - 1] % 3 == 0) && (a[i - 1] % 5 == 0))
{
t = a[i];
a[i] = a[i - 1];
a[i - 1] = t;
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册