Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "string.h"
  3.  
  4. #define MAX_LEN 1000
  5.  
  6.  
  7. int main()
  8. {
  9.     freopen("input.txt", "r", stdin);
  10.     freopen("output.txt", "w", stdout);
  11.  
  12.     char s1[MAX_LEN];
  13.     char s2[MAX_LEN];
  14.     char buf[MAX_LEN];
  15.     int buf_p = 0;
  16.  
  17.     scanf("%s", s1);
  18.     scanf("%s", s2);
  19.  
  20.     for (int i = 0; i < strlen(s2); ++i) {
  21.         int count = 0;
  22.         for (int j = 0; j < strlen(s2); ++j) {
  23.             if (s2[i] == s2[j]) {
  24.                 ++count;
  25.             }
  26.             if (count > 2) {
  27.                 printf("NO");
  28.                 return 0;
  29.             }
  30.         }
  31.         int good = 0;
  32.         if (count == 2) good = 1;
  33.         for (int j = 0; j < strlen(s2); ++j) {
  34.             if (s1[j] == s2[i]) {
  35.                 good = 1;
  36.                 buf[buf_p] = s1[j];
  37.                 ++buf_p;
  38.                 break;
  39.             }
  40.         }
  41.         if (good != 1) {
  42.             printf("NO");
  43.             return 0;
  44.         }
  45.     }
  46.  
  47.     printf("%s%s", s2, buf);
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement