This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 200000
int main() {
static char aa[N + 1], bb[4];
int n, m, k, i, j, d;
char tmp;
scanf("%s%s", aa, bb), n = strlen(aa), m = strlen(bb);
if (m == 1) {
for (i = 0; i < n; i++)
if (aa[i] == bb[0]) {
printf("-1\n");
return 0;
}
printf("0\n");
} else if (m == 2) {
if (bb[0] != bb[1]) {
k = 0;
for (i = -1; i < n; i++)
if ((i < 0 ? bb[1] : aa[i]) != (i + 1 == n ? bb[0] : aa[i + 1]))
k++;
printf("%d\n", k / 2);
} else {
k = 0;
for (i = -1; i < n; i++)
if (aa[i] == bb[0] && aa[i + 1] == bb[0])
k++;
d = 0;
for (i = 0; i < n; i++)
d += aa[i] == bb[0] ? 1 : -1;
printf("%d\n", d > 1 ? -1 : k);
}
} else {
if (bb[0] != bb[2]) {
if (bb[0] == bb[1]) {
for (i = 0, j = n - 1; i < j; i++, j--)
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
tmp = bb[0], bb[0] = bb[2], bb[2] = tmp;
}
k = 0;
for (i = 0; i + 2 < n; i++)
if (aa[i] == bb[0] && aa[i + 1] == bb[1] && aa[i + 2] == bb[2])
k++;
printf("%d\n", k);
}
}
return 0;
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%s%s", aa, bb), n = strlen(aa), m = strlen(bb);
| ^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |