108年 地方特考 三等 資訊處理 程式語言 試卷

pdf
63.31 KB
3 頁
win7 2007
侵權投訴
加載中. ..
PDF
1
0
8
別:三等考試
科:資訊處理
目:程式語言
間:2小時 座號:
※注意:
使
代號:
34260
頁次:
3
1
一、有一函式如下,試問其平均時間複雜度為何?(25
Function A(n) {
int a = 0;
int b = 0;
for (int i = 0; i < n; i++) {
a++;
}
printf("Hello");
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
b++;
}
}
printf("World");
}
二、請指出下列程式碼不合理之處。25 分)
#include
#include
int main()
{int s ,t;
scanf("%d%d", &s,&t);
while (s < 30) {
if (s < 100 || s >50) {
t++;
}
else if (s > 60 && s<-1) {
t++;
}
else if (s > 10 && s < 100) {
t--;
}
else t++;
}
system("pause");
return 0;
}
代號:
34260
頁次:
3
2
三、試問下列程式碼的輸出為何?(25 分)
#include >
using namespace std;
class A {
public:
int testa;
A() :testa(100) {
}
virtual void f() {
cout << "apple" << endl;
}
void g() {
cout << "banana" << endl;
}
};
class B : public A
{
public:
B() :testb(300) {}
void f() {
cout << "cat" << endl;
}
void g() {
cout << "dog" << endl;
}
int testb;
};
int main()
{B b;
A *a = &b;
a->g();
a->f();
cout << a->testa << endl;
cout << b.testb << endl;
system("pause");
return 0;
}
代號:
34260
頁次:
3
3
四、試問下列程式碼的輸出為何?(25 分)
#include
#include
int main() {
int i, k1 = 0, k2 = 0, k3 = 0;
char a[] = "aA123bd45YH*#*";
for (i = 0; a[i] != ''; i++)
if ((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z'))
k1++;
else if ((a[i] >= '0') && (a[i] <= '9'))
k2++;
else k3++;
printf("%d,%d,%dn", k1, k2, k3);
system("pause");
return 0;
}
收藏 ⬇️ 下載