Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Anagrams
//Title of this code #include <iostream> #include <map> #include <string> using namespace std; bool areAnagrams(const string& s1, const string& s2) { if (s1.length() != s2.length()) return false; map<char, int> m; for (int i = 0; i < s1.length(); ++i) { if (m.find(s1[i]) == m.end()) m[s1[i]] = 1; else ++m[s1[i]]; if (m.find(s2[i]) == m.end()) m[s2[i]] = -1; else --m[s2[i]]; } typename map<char, int>::iterator it; for (it = m.begin(); it != m.end(); ++it) if (it->second > 0) return false; return true; } int main() { std::cout << areAnagrams("abac","baca"); }
run
|
edit
|
history
|
help
0
cynb
Peg Grammar Parser Grasshopper Language
akshitha
Search a 2D Matrix
NonparaH
code
Przesylka
stack
ThreadContext
base and derr con