其他分享
首页 > 其他分享> > 【POJ】2159

【POJ】2159

作者:互联网

Code

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAX_LENGTH = 100;

char str1[MAX_LENGTH], str2[MAX_LENGTH];
int len;

inline int getLen(const char* str){
    int head = 0, tail = MAX_LENGTH;
    while(head <= tail){
        int mid = (head + tail) >> 1;
        if('A' <= *(str + mid) && *(str + mid) <='Z')head = mid + 1;
        else tail = mid - 1;
        if(*(str + mid) == '\0')tail = mid;
        if(head >= tail && *(str + mid) == '\0')return mid;
    }
    return head;
}

inline bool mapping(){
    int table1[26], table2[26];
    memset(table1, 0, sizeof(table1));
    memset(table2, 0, sizeof(table2));
    for (int i = 0; i < len; ++i){
        table1[*(str1 + i) - 'A']++;
    }
    for (int i = 0; i < len; ++i){
        table2[*(str2 + i) - 'A']++;
    }
    sort(table1, table1 + 26);
    sort(table2, table2 + 26);
    for (int i = 0; i < 26; ++i){
        if(table1[i] != table2[i])return false;
    }
    return true;
}

int main(int argc, char const *argv[]){
    scanf("%s%s", str1, str2);
    len = getLen(str1);
    if(len != getLen(str2)){
        printf("NO\n");
        return 0;
    }
    if(mapping()){printf("YES\n");return 0;}
    printf("NO\n");
    return 0;
}

Review

标签:26,table1,return,int,POJ,str,const,2159
来源: https://www.cnblogs.com/mojibake/p/15244573.html