結果

問題 No.2737 Compound Word
ユーザー Shuban Pal
提出日時 2024-04-20 11:39:52
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,560 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 29,696 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 07:02:41
合計ジャッジ時間 1,045 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 1 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>

int main() {
    int N;
    scanf("%d", &N);
    
    char strings[N][101]; // Array to store the strings
    for (int i = 0; i < N; i++) {
        scanf("%s", strings[i]);
    }

    int count = 0; // Variable to count the number of distinct concatenated strings

    // Iterate over each pair of adjacent strings and check if the concatenated string is distinct
    for (int i = 1; i < N; i++) {
        char concatenated[201]; // Array to store the concatenated string
        strcpy(concatenated, strings[i]);
        strcat(concatenated, strings[i-1]);

        // Check if the concatenated string is distinct from the previous concatenated string
        int distinct = 1;
        for (int k = 0; k < i; k++) {
            if (strcmp(concatenated, strings[k]) == 0) {
                distinct = 0;
                break;
            }
        }

        // If the concatenated string is distinct, increment the count
        if (distinct) {
            count++;
        }

        // Concatenate the strings in the reverse order and check if it's distinct
        strcpy(concatenated, strings[i-1]);
        strcat(concatenated, strings[i]);
        distinct = 1;
        for (int k = 0; k < i; k++) {
            if (strcmp(concatenated, strings[k]) == 0) {
                distinct = 0;
                break;
            }
        }

        // If the concatenated string is distinct, increment the count
        if (distinct) {
            count++;
        }
    }

    printf("%d\n", count);

    return 0;
}
0