zoukankan      html  css  js  c++  java
  • LA 3213 Ancient Cipher

    开始我理解错题意了,应该是这样理解的:

    字符串1进行映射后可以做一个置换,若置换后与字符串2相同,也是输出YES的

    比如ABCA 和 DDEF

    因此我们需要做的就是统计有多少类字母,每一类有多少个,如果相同的话,两个字符串一定是对应的

     1 //#define LOCAL
     2 #include <algorithm>
     3 #include <cstdio>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 char s1[200], s2[200];
     8 int a[30], b[30];
     9 
    10 int main(void)
    11 {
    12     #ifdef LOCAL
    13         freopen("3213in.txt", "r", stdin);
    14     #endif
    15 
    16     while(scanf("%s%s", s1, s2) == 2)
    17     {
    18         memset(a, 0, sizeof(a));
    19         memset(b, 0, sizeof(b));
    20         int i;
    21         for(i = 0; s1[i] != ''; ++i)
    22         {
    23             ++a[s1[i] - 'A'];
    24             ++b[s2[i] - 'A'];
    25         }
    26         sort(a, a + 26);
    27         sort(b, b + 26);
    28         for(i = 0; i < 26; ++i)
    29             if(a[i] != b[i])
    30                 break;
    31         if(i == 26)
    32             printf("YES
    ");
    33         else
    34             printf("NO
    ");
    35     }
    36     return 0;
    37 }
    代码君
  • 相关阅读:
    LeetCode 101. 对称二叉树
    PTA 两个有序序列的中位数(25分)
    CF1567
    亚线性筛
    LowbitMatrix(线段树)
    Matrix(组合数学)
    [模版] 数论基础模版
    Gym102001
    Gym102483A
    [模版] Miller-Rabin素性测试&Pollard-Rho分解质因数
  • 原文地址:https://www.cnblogs.com/AOQNRMGYXLMV/p/3941209.html
Copyright © 2011-2022 走看看