You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}
}