fork(1) download
  1. /*
  2. Южный федеральный университет, ИКТИБ, кафедра МОП ЭВМ
  3. КТбо1-6 Гамалеев Владислав Евгеньевич
  4. Задача A. Кассовый аппарат
  5. 09.04.2020
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. int isSmall(char c)
  13. {
  14. return (c >= 'a' && c <= 'z');
  15. }
  16. int main(void)
  17. {
  18. freopen("input.txt", "r", stdin);
  19. freopen("output.txt", "w", stdout);
  20. char s[501], t[501];
  21. gets(s);
  22. gets(t);
  23.  
  24. int *cnt_a = (int*)calloc(26,sizeof(int));
  25. int *cnt_A = (int*)calloc(26,sizeof(int));
  26. int *in_t = (int*)calloc(26,sizeof(int));
  27. int *in_T = (int*)calloc(26,sizeof(int));
  28. for (int i = 0; t[i]; ++i)
  29. {
  30. if (isSmall(t[i]))
  31. {
  32. cnt_a[t[i]-'a']++;
  33. in_t[t[i]-'a'] = 1;
  34. if (cnt_a[t[i]-'a'] > 2)
  35. {
  36. printf("NO");
  37. return 0;
  38. }
  39. }
  40. else
  41. {
  42. cnt_A[t[i]-'A']++;
  43. in_T[t[i]-'A'] = 1;
  44. if (cnt_A[t[i]-'A'] > 2)
  45. {
  46. printf("NO");
  47. return 0;
  48. }
  49. }
  50.  
  51. }
  52.  
  53. for (int i = 0; s[i]; ++i)
  54. {
  55. if (isSmall(s[i])) cnt_a[s[i]-'a']++;
  56. else cnt_A[s[i]-'A']++;
  57. }
  58.  
  59. for (int i = 0; t[i]; ++i)
  60. {
  61. if (isSmall(t[i]) && cnt_a[t[i]-'a'] < 2)
  62. {
  63. printf("NO");
  64. return 0;
  65. }
  66. else if (!isSmall(t[i]) && cnt_A[t[i]-'A'] < 2)
  67. {
  68. printf("NO");
  69. return 0;
  70. }
  71. }
  72.  
  73. int *cnt_b = (int*)calloc(26,sizeof(int));
  74. int *cnt_B = (int*)calloc(26,sizeof(int));
  75. for (int i = 0; t[i]; ++i)
  76. {
  77. printf("%c", t[i]);
  78. if (isSmall(t[i])) cnt_b[t[i]-'a']++;
  79. else cnt_B[t[i]-'A']++;
  80. }
  81.  
  82. for (int i = 0; s[i]; ++i)
  83. {
  84. if (isSmall(s[i]) && (cnt_b[s[i]-'a'] < 2 && cnt_a[s[i]-'a'] >= 2 && in_t[s[i]-'a']))
  85. {
  86. printf("%c", s[i]);
  87. cnt_b[s[i]-'a']++;
  88. }
  89. else if (!isSmall(s[i]) && (cnt_B[s[i]-'A'] < 2 && cnt_A[s[i]-'A'] >= 2 && in_T[s[i]-'A']))
  90. {
  91. printf("%c", s[i]);
  92. cnt_B[s[i]-'A']++;
  93. }
  94. }
  95. return 0;
  96. }
Success #stdin #stdout 0s 4484KB
stdin
Standard input is empty
stdout
Standard output is empty