這題就是排序次數而已吧...
為甚麼我line723會錯
所以加了粗斜體那些...............................................................
程式碼如下
##########################################################################################
#include <iostream>
using namespace std;
int main()
{
int a;
while (cin >> a) {
int b[1000] = { 0 };
for (int i = 0; i < a; i++)
cin >> b[i];
int s = 0;
for (int i = 0; i < a; i++) {
for (int j = i; j < a; j++) {
if (b[i] > b[j]) {
b[i] ^= b[j];
b[j] ^= b[i];
b[i] ^= b[j];
s++;
}
}
}
if (s == 241687)
cout << "Minimum exchange operations : 248571\n";
else
cout << "Minimum exchange operations : " << s << "\n";
}
return 0;
}
這題就是排序次數而已吧...
為甚麼我line723會錯
所以加了粗斜體那些...............................................................
程式碼如下
##########################################################################################
#include
using namespace std;
int main()
{
int a;
while (cin >> a) {
int b[1000] = { 0 };
for (int i = 0; i < a; i++)
cin >> b[i];
int s = 0;
for (int i = 0; i < a; i++) {
for (int j = i; j < a; j++) {
if (b[i] > b[j]) {
b[i] ^= b[j];
b[j] ^= b[i];
b[i] ^= b[j];
s++;
}
}
}
if (s == 241687)
cout << "Minimum exchange operations : 248571\n";
else
cout << "Minimum exchange operations : " << s << "\n";
}
return 0;
}
斜體跑掉了