Skip to content

Instantly share code, notes, and snippets.

@magicleon94
Created August 10, 2017 12:39
Show Gist options
  • Save magicleon94/11757dc21a92c92f1178a8b9bd129667 to your computer and use it in GitHub Desktop.
Save magicleon94/11757dc21a92c92f1178a8b9bd129667 to your computer and use it in GitHub Desktop.
/* Simple program that detects if a string is an anagram of the other
* Author: Antonello Galipò
*/
#include <iostream>
#include <string>
#include <algorithm>
using std::sort;
using std::cout;
using std::endl;
using std::string;
int main(int argc, char **argv)
{
if (argc < 3)
{
cout << "Not enough input arguments" << endl;
cout << "Usage: " << argv[0] << " \"string 1\" \"string 2\" " << endl;
return -1;
}
string string1 = argv[1];
string string2 = argv[2];
cout << "You have inserted: "
<< endl
<< string1
<< endl
<< string2
<< endl;
if (!(string1 == string2))
{
sort(string1.begin(), string1.end());
sort(string2.begin(), string2.end());;
if (string1 == string2)
{
cout << "Anagram!" << endl;
return 0;
}
}
cout << "Not anagram!" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment