(90 , 'A '), (80 , 'B '), (90 , 'C '), (80 , 'D ')
排序后:
(80 , 'B '), (80 , 'D '), (90 , 'C '), (90 , 'A ')
2分
登录后查看选项
11
下面代码使用插入排序将数组按升序排列,横线处应填写()。
void insertionSort(int a [], int n) {
for (int i = 1; i < n ; i++) {
int key = a [i];
int j = i - 1;
while (j >= 0 && ) {
a [j + 1] = a [j];
j--;
}
a [j + 1] = key;
}
}
2分
登录后查看选项
12
下面代码的时间复杂度是()。
int countPairs(int a [], int n) {
int cnt = 0 ;
for (int i = 0 ; i < n ; i++) {
for (int j = i + 1; j < n ; j++) {
if (a [i] + a [j] == 100) {
cnt++;
}
}
}
return cnt ;
}
2分
登录后查看选项
13
假设文件data .txt 的内容如下:
Blue Sky
执行下面程序后,输出结果是()。
int main() {
ifstream fin("data .txt");
string a , b ;
fin >> a >> b ;
cout << b << "-" << a ;
fin .close();
return 0 ;
}
2分
登录后查看选项
14
执行下面程序后,输出结果是()。
int main() {
try {
int age = -1;
if (age < 0)
throw age ;
cout << "A ";
} catch (const char *msg) {
cout << "B ";
} catch (int value) {
cout << "C " << value ;
}
return 0 ;
}
2分
登录后查看选项
15
下面函数使用冒泡排序将数组按升序排列。为了在数组已经有序时提前结束,两处横线应分别填写()。
void bubbleSort(int a [], int n) {
for (int i = n - 1; i > 0 ; i--) {
bool changed = ;
for (int j = 0 ; j < i; j++) {
if (a [j] > a [j + 1]) {
int t = a [j];
a [j] = a [j + 1];
a [j + 1] = t ;
changed = ;
}
}
if (!changed)
break;
}
}
2分
登录后查看选项
判断题 共10道
16
执行下面程序后,变量a 的值为15。
int a = 10 ;
int *p = &a;
*p += 5 ;
2分
登录后查看选项
17
一个函数必须在调用之前既声明又定义。
2分
登录后查看选项
18
下面二维数组在内存中按行优先连续存储,因此*(*(a + 1) + 0) 的值为5。
int a [2][4] = {{1 , 2 , 3 , 4 }, {5 , 6 , 7 , 8 }};
2分
登录后查看选项
19
执行下面程序后会输出20。
void change(int x) {
x = 20 ;
}
int main() {
int x = 10 ;
change(x);
cout << x;
return 0 ;
}