Submission

Status:

[PPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: asdasd

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

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-10 23:07:08

#include <stdio.h>
#include <string.h>
int main(){
    char word1[30];
    char word2[30];
    scanf("%s" ,word1);
    scanf("%s" ,word2);
    int count_1 = strlen(word1);
    int count_2 = strlen(word2);
    int max = count_1;
    int min = count_2;
    int printed[256]={0};
    if(count_2>count_1){
        max = count_2;
        min = count_1;
    }
    for(int i = 0 ; i<min ; i++){
        if(count_1>=count_2){
            if(printed[(unsigned char)word2[i]]){
                continue;
            }
        }
        else if(count_1<count_2){
            if(printed[(unsigned char)word1[i]]){
                continue;
            }
        }
        for(int j = 0 ; j<max ; j++)
        if(count_1>=count_2){
            if(word1[j]==word2[i]){
                printf("%c ",word2[i]);
                printed[(unsigned char)word2[i]] = 1;
                break;
            }
        }
        else if(count_1<count_2){
            if(word2[j]==word1[i]){
                printf("%c ",word1[i]);
                printed[(unsigned char)word1[i]] = 1;
                break;
            }
        }
    }
}