@GatorGirl/

Facebook Internship Workshop: RadiantScholarlyKeyboardmacro

C++11

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//given two strings, determine if the strings are anograms

bool anagram(string word1, string word2)
{
	vector<string> word1Letters;
	vector<string>word2Letters;
	for(int i = 0; i < word1.length(); i ++)
	{
		word1Letters.push_back(word1.substr(i, i++));
	}
	for(int i = 0; i < word2.length(); i ++)
	{
		word2Letters.push_back(word2.substr(i, i++));
	}
	string curr;
	for (int i = 0; i < word1Letters.size(); i ++)
	{
		curr = word1Letters[i];
		for (int j = 0; j < word2Letters.size(); j ++)
		{
			if (curr == word2Letters[j])
			{
				word1Letters.erase(std::remove(word1Letters.begin(word1Letters.end(), i), word1Letters.end());
				word2Letters.erase(std::remove(word1Letters.begin(), word1Letters.end(), j), word1Letters.end()); 
				i --;
				break;
			}
			
		}
	}
	if (word1Letters.size() == 0 || word2Letters.size() == 0)
	{
		return true;
	}
	return false;
}

int main() 
{
  string word1;
  string word2;
  cin >> word1;
  cin >> word2;
  bool result = anagram(word1, word2);
  if (result)
  {
    cout << "Anagram!" << endl;

  }
  else
  {
    cout << "Nope" << endl;
  }
}

//do the strings have to be valid words?
//same length?
//language doesn't matter