Professional Documents
Culture Documents
String - Attempt Review
String - Attempt Review
Đã bắt đầu vào Thứ hai, 27 Tháng mười một 2023, 3:14 PM
lúc
Tình trạng Đã hoàn thành
Hoàn thành vào Thứ hai, 27 Tháng mười một 2023, 3:48 PM
lúc
Thời gian thực 34 phút 16 giây
hiện
Điểm 5,00/5,00
Điểm 10,00 của 10,00 (100%)
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 1/11
11/27/23, 3:51 PM 4. String: Attempt review
Câu hỏi 1
Chính xác
Input a string and check if the string is symmetric or not? If yes, print “The string is a palindrome.” If no, print “The string is not a palindrome”
Example:
Input Output
For example:
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 2/11
11/27/23, 3:51 PM 4. String: Attempt review
8 len = strlen(str);
9
10 int check = 1;
11 ▼ for (int i = 0; i < len / 2; i++) {
12 ▼ if (str[i] != str[len - 1 - i]) {
13 check = 0;
14 break;
15 }
16 }
17
18 if (check) printf("The string is a palindrome");
19 else printf("The string is not a palindrome");
20 return 0;
21 }
Chính xác
Điểm cho bài nộp này: 1,00/1,00.
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 3/11
11/27/23, 3:51 PM 4. String: Attempt review
Câu hỏi 2
Chính xác
Given a program with 3 input strings. Compare and print 3 strings in alphabetical order.
For example:
1 aaac aaaa
aaaa aaab
aaab aaac
2 b a c a
b
c
Reset answer
1 #include <stdio.h>
2 #include <string.h>
3
4 // Function to compare and sort two strings
5 ▼ void sortTwoStrings(char *str1, char *str2) {
6 ▼ if (strcmp(str1, str2) > 0) {
7 char temp[100];
8 strcpy(temp, str1);
9 strcpy(str1, str2);
10 strcpy(str2, temp);
11 }
12 }
13
14 // Function to compare and sort three strings
15 ▼ void sortStrings(char *str1, char *str2, char *str3) {
16 sortTwoStrings(str1, str2);
17 sortTwoStrings(str1, str3);
18 sortTwoStrings(str2, str3);
19 }
20
21 ▼ int main() {
22 char str1[100], str2[100], str3[100];
Chính xác
Điểm cho bài nộp này: 1,00/1,00.
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 5/11
11/27/23, 3:51 PM 4. String: Attempt review
Câu hỏi 3
Chính xác
For example:
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 6/11
11/27/23, 3:51 PM 4. String: Attempt review
17 printf("%s", str);
18 return 0;
19 }
Chính xác
Điểm cho bài nộp này: 1,00/1,00.
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 7/11
11/27/23, 3:51 PM 4. String: Attempt review
Câu hỏi 4
Chính xác
Given 2 strings (only lowercase letters, guaranteed testcase). The characters in the string have been sorted in ascending order following the
ASCII table. Create a new string, in which the characters are also sorted in ascending order from the two strings above.
Input Output
“ab” “abbde”
“bde”
“bde” “abcddeef”
“acdef"
For example:
Chính xác
Điểm cho bài nộp này: 1,00/1,00.
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 9/11
11/27/23, 3:51 PM 4. String: Attempt review
Câu hỏi 5
Chính xác
Given one string. Print it and find how many vowels and consonants are there in the string according to the format
“n m”
Vowels: a, e, o, i, u, A, E, O, I, U
Input Output
“abca bc” 24
“1a” 10
“1 23” 00
For example:
abcabc abcabc 2 4
abcabc abcabc 2 4 2 4
Chính xác
Điểm cho bài nộp này: 1,00/1,00.
WEBSITE
HCMUT
MyBK
BKSI
LIÊN HỆ
elearning@hcmut.edu.vn
https://e-learning.hcmut.edu.vn/mod/quiz/review.php?attempt=1733273&cmid=212130 11/11