mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 09:38:42 +00:00
【实践课外】9.数组3
This commit is contained in:
parent
e20c16a589
commit
8ddf41bf24
25
【实践课外】9.数组3/7-1 删除重复字符.c
Normal file
25
【实践课外】9.数组3/7-1 删除重复字符.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int cnt[256];
|
||||
char s[100];
|
||||
|
||||
int main() {
|
||||
gets(s);
|
||||
|
||||
int len = strlen(s);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
cnt[s[i]]++;
|
||||
}
|
||||
|
||||
for (char i = 32; i <= 126; i++) {
|
||||
if (cnt[i] > 0) {
|
||||
printf("%c", 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: 154 KiB |
43
【实践课外】9.数组3/7-2 说反话-加强版.c
Normal file
43
【实践课外】9.数组3/7-2 说反话-加强版.c
Normal file
@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char s[500005];
|
||||
int cnt, start_pos[500005], len[500005];
|
||||
|
||||
int main() {
|
||||
gets(s);
|
||||
|
||||
int len_s = strlen(s);
|
||||
|
||||
for (int i = 0; i < len_s; i++) {
|
||||
if (s[i] == ' ') {
|
||||
if (i == 0 || s[i - 1] == ' ') {
|
||||
continue;
|
||||
}
|
||||
start_pos[cnt] = i - len[cnt];
|
||||
cnt++;
|
||||
len[cnt] = 0;
|
||||
} else {
|
||||
len[cnt]++;
|
||||
}
|
||||
}
|
||||
|
||||
if (len_s > 0 && s[len_s - 1] != ' ') {
|
||||
start_pos[cnt] = len_s - len[cnt];
|
||||
cnt++;
|
||||
}
|
||||
|
||||
for (int i = cnt - 1; i >= 0; i--) {
|
||||
for (int j = start_pos[i]; j < start_pos[i] + len[i]; j++) {
|
||||
printf("%c", s[j]);
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
printf(" ");
|
||||
} else {
|
||||
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: 216 KiB |
31
【实践课外】9.数组3/7-3 数组-回文串.c
Normal file
31
【实践课外】9.数组3/7-3 数组-回文串.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int n;
|
||||
char s[1005];
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
scanf("%s", s);
|
||||
|
||||
int flag = 1;
|
||||
|
||||
// check is palindrome
|
||||
for (int j = 0; j < strlen(s) / 2; j++) {
|
||||
if (s[j] != s[strlen(s) - j - 1]) {
|
||||
flag = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
printf("%s\n", s);
|
||||
}
|
||||
}
|
||||
|
||||
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: 184 KiB |
23
【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.c
Normal file
23
【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int n;
|
||||
char s[105];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
scanf("%s", s);
|
||||
|
||||
int len = strlen(s);
|
||||
|
||||
for (int j = len - 1; j >= 0; j--) {
|
||||
printf("%c", s[j]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.png
Normal file
BIN
【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 226 KiB |
47
【实践课外】9.数组3/7-5 数组-文本加密.c
Normal file
47
【实践课外】9.数组3/7-5 数组-文本加密.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char s[2][10005];
|
||||
int len0, len1;
|
||||
|
||||
int main() {
|
||||
while (s[0][len0] = getchar(), s[0][len0] != ',') {
|
||||
len0++;
|
||||
}
|
||||
|
||||
s[0][len0] = '\0';
|
||||
|
||||
while ((s[1][len1] = getchar()) != EOF && s[1][len1] != '\n') {
|
||||
len1++;
|
||||
}
|
||||
|
||||
s[1][len1] = '\0';
|
||||
|
||||
for (int i = 0; s[0][i] != '\0'; i++) {
|
||||
if ('A' <= s[0][i] && s[0][i] <= 'Z') {
|
||||
s[0][i] = 'a' + s[0][i] - 'A';
|
||||
|
||||
s[0][i] -= 2;
|
||||
|
||||
if (s[0][i] < 'a') {
|
||||
s[0][i] += 26;
|
||||
}
|
||||
} else if ('a' <= s[0][i] && s[0][i] <= 'z') {
|
||||
s[0][i] = 'A' + s[0][i] - 'a';
|
||||
|
||||
s[0][i] -= 2;
|
||||
|
||||
if (s[0][i] < 'A') {
|
||||
s[0][i] += 26;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(s[0], s[1]) == 0) {
|
||||
printf("Yes\n");
|
||||
} else {
|
||||
printf("No\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】9.数组3/7-5 数组-文本加密.png
Normal file
BIN
【实践课外】9.数组3/7-5 数组-文本加密.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 230 KiB |
33
【实践课外】9.数组3/7-6 数组-动车上.c
Normal file
33
【实践课外】9.数组3/7-6 数组-动车上.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int k;
|
||||
char s[105];
|
||||
|
||||
int main() {
|
||||
scanf("%d\n%s", &k, s);
|
||||
|
||||
int len = strlen(s);
|
||||
|
||||
for (int i = 0, cnt = 0; i < len; i += k, cnt++) {
|
||||
if (i + k - 1 < len) {
|
||||
if (cnt % 2 == 1) {
|
||||
for (int j = i + k - 1; j >= i; j--) {
|
||||
printf("%c", s[j]);
|
||||
}
|
||||
} else {
|
||||
for (int j = i; j < i + k; j++) {
|
||||
printf("%c", s[j]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int j = i; j < len; j++) {
|
||||
printf("%c", s[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】9.数组3/7-6 数组-动车上.png
Normal file
BIN
【实践课外】9.数组3/7-6 数组-动车上.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 359 KiB |
Loading…
Reference in New Issue
Block a user