37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
#include<bits/stdc++.h>
|
||
|
||
using namespace std;
|
||
char a[110], b[110];
|
||
int A[26], B[26];
|
||
|
||
int main() {
|
||
cout << "数组A在内存中所占用的存储空间:" << sizeof(A) << endl;
|
||
cout << "数组的第一个元素的长度:" << sizeof(A[0]) << endl;
|
||
cout << "数组的长度:" << sizeof(A) / sizeof(A[0]) << endl;
|
||
|
||
//不断的读入a和b,在C语言中,一般使用char[]来描述字符串,不使用string,在C++中才增加了string类型。
|
||
while (cin >> a >> b) {
|
||
//获取字符串长度
|
||
int n1 = strlen(a);
|
||
int n2 = strlen(b);
|
||
|
||
//以0初始化两个数组
|
||
memset(A, 0, sizeof(A));
|
||
memset(B, 0, sizeof(B));
|
||
|
||
for (int i = 0; i < n1; i++)
|
||
A[a[i] - 'A']++; //字符操作,减去A,获取到0-25 ,表示A-Z的索引号,++表示A有几个
|
||
for (int i = 0; i < n2; i++)
|
||
B[b[i] - 'A']++;
|
||
|
||
//排序A B两个数组
|
||
sort(A, A + 26); //对数组A的0~n-1元素进行升序排序,只要写sort(A,A+n)即可
|
||
sort(B, B + 26);
|
||
|
||
//对比数组的方法,注意这个是!
|
||
if (!memcmp(A, B, sizeof(A)))
|
||
cout << "YES" << endl;
|
||
else
|
||
cout << "NO" << endl;
|
||
}
|
||
} |