Created
March 22, 2012 08:07
-
-
Save metalmine/2156979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // a4.cpp | |
| /* | |
| * Assignment 4 | |
| * CMPT 125 Spring 2012, SFU Surrey, (a4) | |
| * | |
| * Name: xiaohan ji | |
| * Student #: 301169456 | |
| * SFU email: pji@sfu.ca | |
| * | |
| * | |
| * For this assignment I got help from the following people and | |
| * resources: | |
| * | |
| * Peter Gao | |
| * Gary Williams | |
| * | |
| */ | |
| #include "std_lib_cmpt125.h" | |
| /*void BubbleSort(vector<int> &num) //to check if there's a missing number, or if the numbers are too big or too small. Also, Bubbles. | |
| { | |
| int i, j, flag = 1; // OoOOoO00oOOoOo0oO0oO0O0oO0oO0oO0Oo0oOOoOoOo | |
| int temp; // OoOOoO00oOOoOo0oO0oO0O0oO0oO0oO0Oo0oOOoOoOo | |
| int numLength = num.size(); // OoOOoO00oOOoOo0oO0oO0O0oO0oO0oO0Oo0oOOoOoOo | |
| for(i = 1; (i <= numLength) && flag; i++) // OoOOoO00oOOoOo0oO0oO0O0oO0oO0oO0Oo0oOOoOoOo buboooozzz~ | |
| { | |
| flag = 0; | |
| for (j=0; j < (numLength -1); j++) | |
| { | |
| if (num[j+1] > num[j]) | |
| { | |
| temp = num[j]; | |
| num[j] = num[j+1]; | |
| num[j+1] = temp; | |
| flag = 1; | |
| } | |
| } | |
| } | |
| } | |
| */ | |
| bool is_permutation(const vector<int>& v) | |
| { | |
| vector<int> ValCheck; | |
| ValCheck.assign(v.begin(), v.end()); | |
| sort(ValCheck.begin(),ValCheck.end()); | |
| for(int i=0;i<ValCheck.size(); i++) | |
| { | |
| if(ValCheck[i]!=i+1) | |
| { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| void is_permutation_test() | |
| { | |
| vector<int> testvect; | |
| testvect.push_back(1); | |
| testvect.push_back(5); | |
| testvect.push_back(3); | |
| testvect.push_back(4); | |
| testvect.push_back(2); | |
| if(is_permutation(testvect)){ | |
| cout << "derp\n"; | |
| } | |
| else cout << "herp\n"; | |
| vector<int> testvect2; | |
| testvect2.push_back(7); | |
| testvect2.push_back(5); | |
| testvect2.push_back(3); | |
| testvect2.push_back(4); | |
| testvect2.push_back(2); | |
| if(!is_permutation(testvect2)){ | |
| cout << "derpette\n"; | |
| } | |
| else cout << "herpette\n"; | |
| } | |
| vector<int> make_perm(int n) | |
| { | |
| vector<int> potatoe; | |
| for(int i=0;i<n;i++) | |
| { | |
| potatoe.push_back(i+1); | |
| } | |
| return potatoe; | |
| } | |
| void phlip_pancakes(vector<int>& stack,int phlips) | |
| { | |
| for(int i=0,j=phlips-1;i<j;i++,j--) | |
| { | |
| int pan=stack[i]; | |
| stack[i]=stack[j]; | |
| stack[j]=pan; | |
| } | |
| } | |
| void phlip_all_the_pancakes(vector<int>& v) | |
| { | |
| phlip_pancakes(v,v.size()); | |
| } | |
| int score(const vector<int>& v) | |
| { | |
| assert(is_permutation(v)); | |
| vector<int> lemons; | |
| lemons.assign(v.begin(), v.end()); | |
| int count_lemons=0; | |
| while(lemons[0]!=1) | |
| { | |
| phlip_pancakes(lemons,lemons[0]); | |
| count_lemons++; | |
| } | |
| return count_lemons; | |
| } | |
| void print(const vector<int>& v) | |
| { | |
| cout << "n ="<<v.size()<<": "<<score(v)<<"= {"; | |
| for(int i=0;i<v.size();i++) | |
| { | |
| if(i>0) | |
| { | |
| cout<<","; | |
| } | |
| cout<<v[i]; | |
| } | |
| cout<<"}"; | |
| } | |
| void println(const vector<int>& v) | |
| { | |
| print(v); | |
| cout<<"\n"; | |
| } | |
| /*void french_fries(vector<int>& v,int box,vector<int>& longest_fry,int& tastiest_fry) TRYING TO FINISH. TOO FULL | |
| { | |
| if() | |
| { | |
| } | |
| }*/ | |
| /*vector<int> brute_force(int n) | |
| { | |
| int tastiest_fry=-1; | |
| vector<int> longest_fry; | |
| vector<int> poutine; | |
| french_fries(poutine,n,longest_fry,tastiest_fry); | |
| return longest_fry; | |
| } | |
| void test_brute_force(int n) | |
| { | |
| } | |
| */ | |
| void test_score() | |
| { | |
| vector<int> testvect; | |
| testvect.push_back(3); | |
| testvect.push_back(1); | |
| testvect.push_back(4); | |
| testvect.push_back(5); | |
| testvect.push_back(2); | |
| println(testvect); | |
| } | |
| int main() { | |
| is_permutation_test(); | |
| randomize(); | |
| test_score(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment