Skip to content

Instantly share code, notes, and snippets.

@isRuslan
Created June 13, 2016 20:03
Show Gist options
  • Save isRuslan/89278e2fa61ee32466b4e2d7161fb484 to your computer and use it in GitHub Desktop.
Save isRuslan/89278e2fa61ee32466b4e2d7161fb484 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX_SIZE 100000
int check_string(char s1[], char s2[]);
int main() {
int n;
char *s1, *s2;
scanf("%d", &n);
s1=(char*)malloc(sizeof(char)*MAX_SIZE);
s2=(char*)malloc(sizeof(char)*MAX_SIZE);
char result[n];
for(int i = 0; i <= n; i++){
scanf("%s", s1);
scanf("%s", s2);
result[i] = check_string(s1, s2);
}
for(int i = 0; i < n; i++){
printf("%s\n", result[i] == 0 ? "NO" : "YES");
}
return 0;
}
int check_string(char s1[], char s2[])
{
int i, j;
int letters[MAX_SIZE] = {0};
for(i = 0; s1[i] != '\0'; i++){
letters[s1[i]] += 1;
}
for(j = 0; s2[j] != '\0'; j++){
if(letters[s2[j]] > 0){
return 1;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment