mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 15:48:42 +00:00
【实践课内】9.数组3
This commit is contained in:
parent
1d65b207f1
commit
e20c16a589
18
【实践课内】9.数组3/7-1 字符串逆序.c
Normal file
18
【实践课内】9.数组3/7-1 字符串逆序.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char s[100];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
gets(s);
|
||||||
|
|
||||||
|
int len = strlen(s);
|
||||||
|
|
||||||
|
for (int i = len - 1; i >= 0; i--) {
|
||||||
|
printf("%c", s[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
【实践课内】9.数组3/7-1 字符串逆序.png
Normal file
BIN
【实践课内】9.数组3/7-1 字符串逆序.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 138 KiB |
23
【实践课内】9.数组3/7-2 字符串替换.c
Normal file
23
【实践课内】9.数组3/7-2 字符串替换.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
const char REPLACE_MAP[] = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
|
||||||
|
|
||||||
|
char s[100];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
gets(s);
|
||||||
|
|
||||||
|
int len = strlen(s);
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (s[i] >= 'A' && s[i] <= 'Z') {
|
||||||
|
printf("%c", REPLACE_MAP[s[i] - 'A']);
|
||||||
|
} else {
|
||||||
|
printf("%c", s[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
【实践课内】9.数组3/7-2 字符串替换.png
Normal file
BIN
【实践课内】9.数组3/7-2 字符串替换.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 KiB |
21
【实践课内】9.数组3/7-3 统计字符出现次数.c
Normal file
21
【实践课内】9.数组3/7-3 统计字符出现次数.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char c, s[100];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
gets(s);
|
||||||
|
scanf("%c", &c);
|
||||||
|
|
||||||
|
int len = strlen(s);
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (s[i] == c) {
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%d\n", cnt);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
【实践课内】9.数组3/7-3 统计字符出现次数.png
Normal file
BIN
【实践课内】9.数组3/7-3 统计字符出现次数.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 152 KiB |
18
【实践课内】9.数组3/7-4 IP地址转换.c
Normal file
18
【实践课内】9.数组3/7-4 IP地址转换.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char s[100];
|
||||||
|
int ip[4];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
scanf("%s", s);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
ip[i] = ip[i] * 2 + s[i * 8 + j] - '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
【实践课内】9.数组3/7-4 IP地址转换.png
Normal file
BIN
【实践课内】9.数组3/7-4 IP地址转换.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 164 KiB |
Loading…
Reference in New Issue
Block a user