文章目录
- 1. 题目链接
- 2. 题目代码
- 3. 题目总结
- 4. 代码分析
1. 题目链接
Amusing Joke
2. 题目代码
#include<iostream>
#include<string>
using namespace std;
int letterOfInt[30];
int letterAtDoorOfInt[30];
int main(){
string guestName;
string hostName;
string letterAtDoor;
cin >> guestName >> hostName >> letterAtDoor;
for(int subscript = 0; subscript < guestName.length(); subscript ++){
letterOfInt[guestName[subscript] - 'A'] ++;
}
for(int subscript = 0; subscript < hostName.length(); subscript ++){
letterOfInt[hostName[subscript] - 'A'] ++;
}
for(int subscript = 0; subscript < letterAtDoor.length(); subscript ++){
letterAtDoorOfInt[letterAtDoor[subscript] - 'A'] ++;
}
bool isOutput = false;
for(int subscript = 0; subscript < 26; subscript ++){
if(letterOfInt[subscript] != letterAtDoorOfInt[subscript]){
cout << "NO";
isOutput = true;
break;
}
}
if(!isOutput){
cout << "YES";
}
return 0;
}
3. 题目总结
用时:18min
4. 代码分析
参考代码来源:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
string s,s1,s2,snew;
cin>>s1>>s2>>s;
int a=s1.length();
int b=s2.length();
int c=s.length();
if ((a+b)!=c)
cout<<"NO"<<endl;
else{
snew=s1+s2;
sort(snew.begin(),snew.end());
sort(s.begin(),s.end());
if (s==snew)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
我的代码耗时:154ms
内存占用:0KB
参考代码比我的代码解题思路更巧妙