diff --git a/【实践课外】9.数组3/7-1 删除重复字符.c b/【实践课外】9.数组3/7-1 删除重复字符.c new file mode 100644 index 0000000..be2347f --- /dev/null +++ b/【实践课外】9.数组3/7-1 删除重复字符.c @@ -0,0 +1,25 @@ +#include +#include + +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; +} diff --git a/【实践课外】9.数组3/7-1 删除重复字符.png b/【实践课外】9.数组3/7-1 删除重复字符.png new file mode 100644 index 0000000..839efd6 Binary files /dev/null and b/【实践课外】9.数组3/7-1 删除重复字符.png differ diff --git a/【实践课外】9.数组3/7-2 说反话-加强版.c b/【实践课外】9.数组3/7-2 说反话-加强版.c new file mode 100644 index 0000000..4c16e02 --- /dev/null +++ b/【实践课外】9.数组3/7-2 说反话-加强版.c @@ -0,0 +1,43 @@ +#include +#include + +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; +} diff --git a/【实践课外】9.数组3/7-2 说反话-加强版.png b/【实践课外】9.数组3/7-2 说反话-加强版.png new file mode 100644 index 0000000..4441eb1 Binary files /dev/null and b/【实践课外】9.数组3/7-2 说反话-加强版.png differ diff --git a/【实践课外】9.数组3/7-3 数组-回文串.c b/【实践课外】9.数组3/7-3 数组-回文串.c new file mode 100644 index 0000000..9b384af --- /dev/null +++ b/【实践课外】9.数组3/7-3 数组-回文串.c @@ -0,0 +1,31 @@ +#include +#include + +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; +} diff --git a/【实践课外】9.数组3/7-3 数组-回文串.png b/【实践课外】9.数组3/7-3 数组-回文串.png new file mode 100644 index 0000000..f56c233 Binary files /dev/null and b/【实践课外】9.数组3/7-3 数组-回文串.png differ diff --git a/【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.c b/【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.c new file mode 100644 index 0000000..c115e0e --- /dev/null +++ b/【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.c @@ -0,0 +1,23 @@ +#include +#include + +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; +} diff --git a/【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.png b/【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.png new file mode 100644 index 0000000..920c58d Binary files /dev/null and b/【实践课外】9.数组3/7-4 数组-无聊的菇菇一族.png differ diff --git a/【实践课外】9.数组3/7-5 数组-文本加密.c b/【实践课外】9.数组3/7-5 数组-文本加密.c new file mode 100644 index 0000000..e7b025b --- /dev/null +++ b/【实践课外】9.数组3/7-5 数组-文本加密.c @@ -0,0 +1,47 @@ +#include +#include + +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; +} diff --git a/【实践课外】9.数组3/7-5 数组-文本加密.png b/【实践课外】9.数组3/7-5 数组-文本加密.png new file mode 100644 index 0000000..a7889f3 Binary files /dev/null and b/【实践课外】9.数组3/7-5 数组-文本加密.png differ diff --git a/【实践课外】9.数组3/7-6 数组-动车上.c b/【实践课外】9.数组3/7-6 数组-动车上.c new file mode 100644 index 0000000..0a73e5a --- /dev/null +++ b/【实践课外】9.数组3/7-6 数组-动车上.c @@ -0,0 +1,33 @@ +#include +#include + +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; +} diff --git a/【实践课外】9.数组3/7-6 数组-动车上.png b/【实践课外】9.数组3/7-6 数组-动车上.png new file mode 100644 index 0000000..90d75a8 Binary files /dev/null and b/【实践课外】9.数组3/7-6 数组-动车上.png differ