Submission
Status:
[PPPPPPPP]
Score: 100
User: Jokul
Problemset: สตริงซ้ำซ้ำ
Language: c
Time: 0.001 second
Submitted On: 2025-03-04 15:06:36
#include <stdio.h>
#include <string.h>
int main() {
char s1[20], s2[20];
int c[256] = {0}; // Array to keep track of character occurrences
// Read two strings
scanf("%s %s", s1, s2);
// Count occurrences of characters in the first string
for (int i = 0; s1[i] != '\0'; i++) {
c[(unsigned char)s1[i]]++;
}
// Check for characters in the second string
for (int i = 0; s2[i] != '\0'; i++) {
if (c[(unsigned char)s2[i]] > 0) {
printf("%c", s2[i]);
c[(unsigned char)s2[i]] = 0; // Set to 0 to avoid printing again
}
}
printf("\n"); // Print a newline at the end
return 0;
}