I can't solve make a sort of strings

closed account (j2EUpDi1)
#include<bits/stdc++.h>

using namespace std;

int main(){
string s,t;
cin>>s>>t;
sort(s.begin(), s.end());


if (s==t)
{
cout<<"YES";

}
else cout<<"NO";

}
input zfghs shgfz
output yes
Don't use <bits/> - it's not standard c++.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <algorithm>

int main() {
	std::string s, t;

	std::cin >> s >> t;
	std::sort(s.begin(), s.end());

	if (s == t)
		std::cout << "YES\n";
	else
		std::cout << "NO\n";
}


gives the expected output of:

zfghs shgfz
NO

zfghs fghsz
YES

XY Problem wrote:
You try to achieve Y. You have written X, thinking it is the solution. It does not quite work. You ask help with X. However, X is not the way to solve Y. Please, explain the Y to us first
Last edited on
I think I'm with @ne555 here. @nurrun1, please state your ORIGINAL problem, not your flawed route to solving it.
Topic archived. No new replies allowed.