From f379367eb4b77e63f956e7e63ad78161a957f8ff Mon Sep 17 00:00:00 2001 From: yenru0 Date: Tue, 9 Jul 2024 03:50:02 +0900 Subject: [PATCH] complete 31825.c --- zeta_C/completed/31825.c | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 zeta_C/completed/31825.c diff --git a/zeta_C/completed/31825.c b/zeta_C/completed/31825.c new file mode 100644 index 0000000..00b2d87 --- /dev/null +++ b/zeta_C/completed/31825.c @@ -0,0 +1,60 @@ +#include +#include + +typedef struct Alphabets { + char *string; + int len; +} Alphabets; + +char shift(char x) { + if (x == 90) return 65; + else + return x + 1; +} + +void querry_shift(Alphabets *alphas, int left, int right) { + for (int i = left - 1; i < right; i++) { + *(alphas->string + i) = shift(*(alphas->string + i)); + } +} + +int querry_string(Alphabets *alphas, int left, int right) { + int cnt = 0; + char head = 0, now; + for (int i = left - 1; i < right; i++) { + now = *(alphas->string + i); + if (head != now) { + head = now; + cnt++; + } + } + return cnt; +} + +int querry(Alphabets *alphas, int left, int right, int type) { + if (type == 2) { + querry_shift(alphas, left, right); + return -1; + } else { + return querry_string(alphas, left, right); + } +} + +int main() { + int N, Q, left, right, type, ret; + scanf("%d %d", &N, &Q); + Alphabets alphas; + alphas.len = N; + alphas.string = (char *) malloc(alphas.len * sizeof(char)); + scanf("%s", alphas.string); + for (int i = 0; i < Q; i++) { + scanf("%d %d %d", &type, &left, &right); + ret = querry(&alphas, left, right, type); + if (ret < 0) { + continue; + } else { + printf("%d\n", ret); + } + } + free(alphas.string); +} \ No newline at end of file