zuoside__lord 于 2017.01.08 14:04 提问

acm 运行错误 但是自己找不出自己代码错误，请赐教 2C

0 1 2 3 4 5 6 7 8 9
m :4
n : 6

0 1 2 3 9 8 7 6 5 4

0 1 2 3 4 5 6 7 8 9
m:4
n:6

0 1 2 3 9 8 7 6 5 4

6个回答

qq_28259903   2017.01.08 14:14

qq_29566841   2017.01.08 15:10

qq_29566841   2017.01.08 15:34
`````` #include<iostream>
using namespace std;

int main() {
int array[10];

cout << "请输入数组值：" << endl;
int i = 0;
while (i<10)
{
cin >> array[i];
i++;
}

cout << "数组值输入完毕，如下：" << endl;
for (int i = 0; i < 10; i++) {
cout << array[i] << "  ";
}

cout << endl <<"请指定交换顺序的起始位置：" << endl;
int start;
cin >> start;

cout << "请输入需要交换的长度：" << endl;
int length;
cin >> length;

if (start + length > 9) {
length = 9;
}

for (; start < length; start++&&length--) {
int temp = array[start];
array[start] = array[length];
array[length] = temp;
}

cout << "交换后的数组为：" << endl;
for (int i = 0; i < 10; i++) {
cout << array[i] << "  ";
}

cout << endl;
system("pause");

``````
qq_29566841   2017.01.08 15:39

u011889952   2017.01.08 15:48

lwlldd   2017.01.08 15:58

#include
#include
#include
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int n,m;
int a[15];

void solve(){
sort(a+m,a+m+n,cmp);
}

int main(){

``````for(int i=0;i<10;i++){
scanf("%d",&a[i]);
}

scanf("%d %d",&m,&n);

solve();

for(int i=0;i<10;i++)
if(i==0)
printf("%d",a[i]);
else
printf(" %d",a[i]);
printf("\n");
return 0;
``````

}