Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <vector>
- #include <iostream>
- #include <string>
- #include <time.h>
- using namespace std;
- typedef map<int, string> phonemap;
- void createPhoneMap(phonemap &mapIn);//create the map for phone Keyboard
- void PrintAllString(string phoneIn,phonemap mapIn, int size); //print out all the combinations
- void PrintMap(phonemap mapIn); //print out the data in mapIn
- void recurseLoop()
- {
- }
- phonemap MyMap; //global variable
- string phonenum;//global string contains user input phone number
- int main()
- {
- int size;
- cout<<"Please input the phone number: ";
- cin>>phonenum;
- size = phonenum.size();
- cout<<endl;
- createPhoneMap(MyMap);
- PrintMap(MyMap);
- cout<<endl;
- PrintAllString(phonenum, MyMap, size);
- system("pause");
- return 0;
- }
- void createPhoneMap(phonemap &mapIn)
- {
- for(int x = 0; x<10; x++)
- {
- if(x == 0 || x == 1)
- {
- string input = "";
- input.push_back(x + 42);
- mapIn.insert(phonemap::value_type(x, input));
- }
- else if(x > 1 && x < 9)
- {
- string input = "";
- for(int y=0; y<3; y++)
- {
- input.push_back((x - 2) * 3 + 65 + y);
- }
- mapIn.insert(phonemap::value_type(x, input));
- }
- else //x == 9
- {
- mapIn.insert(phonemap::value_type(x, "VWXYZ"));
- }
- }
- return;
- }
- void PrintAllString(string phoneIn,phonemap mapIn, int size)
- {
- phonemap::iterator finder;
- vector<string> sout(size);
- //remove any non-digit char from the number
- for(int a=0; a<size; a++)
- {
- if(!isdigit(phoneIn.at(a)))
- {
- phoneIn.erase(a, 1);
- size--;
- a--;
- }
- }
- for(int x=0; x<size; x++)
- {
- finder = mapIn.find(phoneIn.at(x) - 48);
- if(finder != mapIn.end())
- {
- sout[x] = finder->second;
- //cout << finder->second << endl;
- }
- else
- {
- cout << "Not found" << endl;
- }
- }
- recurseLoop();
- //working part for numbers of length 3
- /*for(int i = 0; i < sout[0].size(); i++)
- {
- for(int j = 0; j < sout[1].size(); j++)
- {
- for(int k = 0; k < sout[2].size(); k++)
- {
- cout << sout[0][i] << sout[1][j] << sout[2][k] << endl;
- }
- }
- }*/
- return;
- }
- void PrintMap(phonemap mapIn)
- {
- cout << "The phone keyboard is: " << endl;
- for(phonemap::iterator i = mapIn.begin(); i != mapIn.end(); i++)
- {
- cout << "<" << i->first << "," << i->second << ">" << endl;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement