Submission

Status:

[PPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: wasupum

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

Language: c

Time: 0.001 second

Submitted On: 2025-10-03 02:56:49

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

void str(char* s){
    int c, id = 0;
    while((c = getchar()) != '\n' && c != EOF){
        s[id++] = (char)c;
        s[id] = '\0';
    }
}

int main(void){
    char* s1=malloc(25*sizeof(char));
    char* s2=malloc(25*sizeof(char));
    if(!s1 || !s2)return 1;
    
    str(s1);
    str(s2);
    
    int check[130]= {0};
    
    for(int i = 0 ; i < strlen(s1) ; i ++){
        for(int j = 0 ; j < strlen(s2) ; j++){
            if(s1[i] == s2[j]){
                if(check[(int)s1[i]]!=1)
                printf("%c ",s1[i]);
            check[(int)s1[i]]=1;
            }
        }
    }
    
    free(s1);
    free(s2);
    s1 = s2 = NULL;
    return 0;
}