From 1b5db63f3b4be72bbdc8207b89be2e570a8e2d30 Mon Sep 17 00:00:00 2001 From: iandioch Date: Thu, 21 Sep 2023 17:05:10 +0000 Subject: [PATCH] Add kattis prob scrollingsign in c++ --- kattis/scrollingsign/solution.cc | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 kattis/scrollingsign/solution.cc diff --git a/kattis/scrollingsign/solution.cc b/kattis/scrollingsign/solution.cc new file mode 100644 index 0000000..597b785 --- /dev/null +++ b/kattis/scrollingsign/solution.cc @@ -0,0 +1,48 @@ +#include +#include +#include + +using namespace std; + +int n, k, w; +char c[101]; +char ticker[101]; + +int overlap() { + for(int kk = k; kk > 0; --kk) { + bool ok = true; + for (int ci = 0; ci < kk; ++ci) { + int tk = ci + (k-kk); + if (ticker[tk] != c[ci]) { + ok = false; + break; + } + } + if (ok) { + return kk; + } + } + return 0; +} + +int main() { + scanf("%d", &n); + for (int ni = 0; ni < n; ++ni) { + scanf("%d %d", &k, &w); + for (int i = 0; i < k; ++i) { + ticker[i] = ' '; + } + ticker[k] = 0; + int ans = 0; + for (int wi = 0; wi < w; ++wi) { + scanf("%s", c); + //printf("ticker: %s\n", ticker); + //printf("input: %s\n", c); + //printf("overlap: %d\n", overlap()); + ans += k - overlap(); + strcpy(ticker, c); + } + printf("%d\n", ans); + } + return 0; +}