uva 1339

来源:互联网 发布:windows下安装sublime 编辑:程序博客网 时间:2024/05/05 01:40

简单题, 计算出两个字符串中各个字母出现的频率,排序后对比一下即可

#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <string>#include <cstring> #include <vector>#include <set>#include <queue>#include <map>using namespace std;const int MAXN = 100 + 10;typedef long long LL;int main(){char oldstr[MAXN],newstr[MAXN];int  oldcnt[26],newcnt[26];while( scanf("%s",newstr)!=EOF ){scanf("%s",oldstr);memset(oldcnt,0,sizeof(oldcnt));memset(newcnt,0,sizeof(newcnt));if( strlen(newstr)!=strlen(oldstr) ){cout << "NO" << endl;continue;}for(int i=0; i<strlen(newstr); i++){oldcnt[(oldstr[i]-'A')]++;newcnt[(newstr[i]-'A')]++;}sort(oldcnt,oldcnt+26);sort(newcnt,newcnt+26);int i;for(i=0; i<26; i++){if( oldcnt[i]!=newcnt[i] ) break;}if( i<26 ){cout << "NO" ;}else{cout << "YES";}cout << endl;} return 0;}


0 0
原创粉丝点击