Submission

Status:

[PPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Chawin

Problemset: สตริงซ้ำซ้ำ

Language: c

Time: 0.002 second

Submitted On: 2025-10-07 21:44:03

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

int main(){
    char str1[21], str2[21];
    scanf("%s %s", &str1, &str2);

    // int cnt1[123] = {}, cnt2[123] = {};

    // for(int i = 0; i < strlen(str1); i++){
    //     int ascii = str1[i];
    //     cnt1[ascii]++;
    // }

    // for(int i = 0; i < strlen(str2); i++){
    //     int ascii = str2[i];
    //     cnt2[ascii]++;
    // }
 
    // for(int i = 65; i <= 122; i++){
    //     if((cnt1[i] > 0) && (cnt2[i] > 0)){
    //         for(int j = 0; j < cnt1[i]; j++){
    //             printf("%c ", i);
    //             cnt1[i]--;
    //             cnt2[i]--;
    //         }
    //     }
    // }
    
    int found[123] = {0};
    for(int i = 0; i < strlen(str1); i++){
        for(int j = 0; j < strlen(str2); j++){
            if(str1[i] == str2[j] && !found[(unsigned char)str1[i]]){
                printf("%c ", str1[i]);
                found[str1[i]] = 1;
                break; 
            }
        }
    }

    return 0;
}