You are on page 1of 4

Tất cả các bài nếu không làm trình bày code quá xấu -> Trừ 0.

25đ
Bài 1:

int findK1(int *arr, int n, int k) (0.25đ) {


int i;
for (i = 0; i < n; i++)
if (*(arr+i) == k)
return 1;
return 0;
} (0.25đ)
int findK2(int arr[], int n, int k) (0.25đ) {
int i;
for (i = 0; i < n; i++)
if (arr[i] == k)
reutrn 1;
return 0;
} (0.25đ)
int main() {
int n;
scanf("%d", &n);
int *arr = (int*) malloc(n*sizeof(int)); (0.5đ)
int i;
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
int k;
scanf("%d", &k);
if (findK1(arr, n, k)) (0.5đ)
printf("Yes");
else
printf("No");
}

Bài 2:
int main() {
int n;
scanf("%d", &n);
int arr[100];
int i, j;
for (i = 0; i < n; i++)
scanf("%d", &arr[i]); (0.5đ)
for (i = 0; i < n - 1; i++)
for (j = i + 1; j < n; j++)
if (arr[i] < arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp; (1.5đ)
}
for (i = 0; i < n; i++)
printf("%d", arr[i]) (0.5đ)
}
Nếu khai báo mảng sử dụng biến n → trừ 0.5đ
Bài 3:

int tinhDoDai(char *str) {


int doDai = 0;
while (str[doDai] != '\0')
doDai += 1; (1.5đ)
return doDai;
}

Nếu viết hàm không return mà in luôn kết quả → trừ 0.5đ

int main() {
char str[100];
gets(str); (0.5)
printf("%d", tinhDoDai(str));
}

Nếu khai báo mảng sử dụng biến → trừ 0.5đ


Bài 4:

struct ThoiGian{
int gio;
int phut;
int giay;
}; (0.5đ)
Thiếu dấu ; → trừ 0.25đ

void nhapThoiGian(struct ThoiGian *tg) {


printf("Nhap gio:");
scanf("%d", &tg->gio);
printf("Nhap gio:");
scanf("%d", &tg->phut);
printf("Nhap gio:");
scanf("%d", &tg->giay);
} (1đ)

void inThoiGian(struct ThoiGian tg) {


printf("%02d:%02d:%02d", tg.gio, tg.phut, tg.giay);
}
Thiếu %02d → trừ 0.25đ
int tinhSoGiay(struct ThoiGian tg) {
return tg.gio*3600 + tg.phut*60 + tg.giay;
} (0.5đ)
Thiếu trả về hoặc in luôn kết quả → trừ 0.25đ

struct ThoiGian tinhThoiGian(int soGiay) {


struct ThoiGian ans;
ans.gio = soGiay/3600;
soGiay %=3600;
ans.phut = soGiay/60;
soGiay %=60;
ans.giay = soGiay;
return ans;
} (0.5đ)
Thiếu trả về hoặc in luôn kết quả → trừ 0.25đ

int soSanh(struct ThoiGian tg1, struct ThoiGian tg2) {


int time1 = tinhSoGiay(tg1);
int time2 = tinhSoGiay(tg2);
if (time1 > time2)
return 1;
else if (time1 < time2)
return -1;
else
return 0;
} (0.5đ)
Không sử dụng hàm tinhSoGiay đã viết → trừ 0.25đ

Bài 5

typedef struct Node{


int data;
struct Node* next;
} Node;

Node* head = NULL;


Node* tail = NULL;

Node* newNode(int data){


Node* temp = (Node*) malloc(sizeof(Node));
temp->data = data;
temp->next = NULL;
return temp;
}

int is Empty(){
if(head == NULL || tail == NULL) return 0;
else{
Node* index = head;
int size = 1;
while(index->next != NULL){
index = index->next;
size++;
}
return size;
}
}

void addNode(int data){


// If list is empty
if(head == NULL){
head = newNode(data);
tail = head;
}else{ // Normal case
Node* temp = newNode(data);
temp->next = head;
head = temp;
}
}

void printLast(int data){


// If list is empty
if(tail == NULL){
tail = newNode(data);
head = tail;
}else{ // Normal case
Node* temp = newNode(data);
tail->next = temp;
tail = temp;
}
}

You might also like