POJ 2159 類比

來源:互聯網
上載者:User

這一題的題意太晦澀了,含義是指:將任意字母替換為任意一個字母,只要不出現多個字母替換成同一個就可以,即為一一映射。因此,我們只需要判斷兩個字元含有的不同的字母數量以及對應出現的次數都相同就行了。

//11410806c00h00g2159Accepted356K32MSG++1015B2013-03-29 15:59:15#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespace std;int map[26];char a[105];char b[105];int res1[26];int res2[26];int cmp(int a,int b){return a<b;}int main(){while(scanf("%s%s",a,b)!=EOF){    int len1=strlen(a);    int len2=strlen(b);    memset(map,0,sizeof(map));    for(int i=0;i<len1;i++)        map[a[i]-'A']++;    int l1=0,l2=0;for(int i=0;i<26;i++)        if(map[i]!=0) res1[l1++]=map[i];        memset(map,0,sizeof(map));    for(int i=0;i<len2;i++)        map[b[i]-'A']++;    for(int i=0;i<26;i++)        if(map[i]!=0) res2[l2++]=map[i];            if(l1!=l2) printf("NO\n");    else{    sort(res1,res1+l1,cmp);    sort(res2,res2+l1,cmp);    bool flag=false;    for(int i=0;i<l1;i++)        if(res1[i]!=res2[i]){    flag=true;    break;}if(flag)  printf("NO\n");else  printf("YES\n");}}//system("pause");    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.