Uploaded by Moody Al Mazooqi

p3brainstorming

advertisement
WHAT I LEARNED:
- int& : pass by reference -> changes the value of the defined variable - size_t : prevents decrementing int till it is negative so size_t prevents it from becoming negative
- you can do math with strings (check characters and integers) --> char ch = '0'; // Let's say the code number for '0' is x
ch++; // now ch is '1' (x+1)
ch += 7; // now ch is '8' (since (x+1)+7 is x+8)
int n = ch; // n is the code number for '8' (i.e., x+8)
int m = ch - '3'; // '8' - '3'
// which is (x+8) - (x+3)
// which is 8 - 3
// so m is 5
THINGS YOU CAN DO WITH STRINGS
1. APPEND
string s = "Hello there! How are you?";
string t; // automatically initialized to the empty string
for (size_t k = 0; k != s.size(); k++)
{
if (s.at(k) != ' ') // If s.at(k) is not a blank
t += s.at(k); // append s.at(k) to t
}
cout << t; // writes Hellothere!Howareyou?
2. COPY A SUBSTRING // 012345678
string s = "duplicate"; // duplicate
cout << s.substr(5,3); // writes cat 3. CLIP OFF
string t = "fingernail";
t = t.substr(6, t.size()-6); // t is now "nail"
4. CLASSIFY (ask whether letter or digit character)
// 01234567
string s = "Maroon 5"; // Maroon 5
if (isalpha(s.at(0))) // tests as true, since 'M' is a letter
...
if (isupper(s.at(0))) // tests as true, since 'M' is an uppercase letter
...
if (islower(s.at(2))) // tests as true, since 'r' is a lowercase letter
...
if (isdigit(s.at(7))) // tests as true, since '5' is a digit character
...
if (islower(s.at(0))) // tests as false, since 'M' is not a lowercase letter
...
if (isalpha(s.at(6))) // tests as false, since ' ' is not a letter
...
if (isalpha(s.at(7))) // tests as false, since '5' is not a letter
...
if it was facing north if it is l then direct it to west function
if it is r then direct it to east function if it was facing south
if it is l then direct it to east function
if it is r then direct it to west function if it was facing west
if it is l then direct it to south function
if it is r then direct it to north function if it was facing east
if it is l then direct it to north function
if it is r then direct it to south function each function should take the number followed by the letter
ex. dir is north the input should be the direction followed by the number of steps. what is the point of determining safe distance? if determinesafedistance == false --> plan doesnt work. so basically, we determine safe distance first then we order it to obey how can we identify safe distance? basically, if it was facing north --> if turn l --> safedistancewest(r, c, stepsproposed) --> true --> move steps --> after moving steps --> if r --> safedistancenorth( new r, new c, steps proposed ) --> repeat until we reach er, ec -------------------------------------------------
int obeyPlan(int sr, int sc, int er, int ec, char dir, string plan, int& nsteps)
--> return 0 AND counts step till end of plan (add all #s?)
1. hasCorrectform == true
2. obeyable plan --> return 1 : otherwise ??
--> return 2 AND does not change nsteps 1. hascorrectform == false --> return 3 AND sets nsteps to MaxSteps the car can travel till it is not obeyable
1. not obeyable plan (hits wall or off grid) ------------------------------------------------------
so the pseducode is int obeyPlan(int sr, int sc, int er, int ec, char dir, string plan, int& nsteps)
{
if hascorrectform == true
{
if { for (int i ; i>=
s.at[i] --> letter --> for s.at[i] --> digit --> what if we want it to move between portions??
OBEYABLE else (if not obeyable) return 3;
}
return 1
if has correctform == false return 2;
if there were to characters that are digits next to each other then character 1*10 + character 2
so it becomes
if (isalpha(i))
{
for (n ; n <=plan.size() ; n++)
{
if (
--> if (plan.at(i) == R || plan.at(i) == r)
{
if (dir == 'W' || dir == 'w')
dir = 'n';
else if (dir == 'E' || dir == 'e')
dir == 's';
else if (dir == 'N' || dir == 'n')
dir == 'e';
else if (dir == 'S' || dir == 's')
dir == 'w';
}
else if (plan.at(i) == R || plan.at(i) == r)
if (dir == 'W' || dir == 'w')
dir = 's';
else if (dir == 'E' || dir == 'e')
dir == 'n';
else if (dir == 'N' || dir == 'n')
dir == 'w';
else if (dir == 'S' || dir == 's')
dir == 'e';
}
if (is.digit(char.at(i)))
{if (isdigit(char.at(i+1))
{
int n = i - 0
int m = n * 10
int o = char.at(i+1) - 0
int p = m + o
take what p i then determinesafedistance(r, c, p) //we need something that updates r and c with everystep else int w = char.at(i) - 0
}
since we get returned steps --> we can use this to change r and c
maybe put this as a part of the determinesafedistance function?
so put& after each int in fxns
now what can we do to record where the steps is,,, it wants us to return PROBLEMS I SHOULD SOLVE;
1. if determinesafedistance = -1 --> obeyplan should return 3
2. how can we modify r and c accordingly??
3. how can we know we reached er,ec
4. when are we supposed to return 1 in obeyplan?
I need to edit r and c until sr,sc = er,ec
NO FUCKING CLUE
depending on the direction, we edit r and c
so the function must be able to edit
so sr,sc if south if sr == er sc==sc break;
if dir = s
FUCKING PROBLEM AGAIN
so there is something not working with editing the sc and sr on an on there must be a way to know we have reached er, ec. OOHHHHHHHH
so the return 1 is if it obeyed the plan but it did not reach er, ec.
NOW how can we determine whether the thing reached er, ec. maybe we can define new variables?
but the thing is, we never actually left the function, so why is nsteps changed but sr,sc ints only
BEGS TO QUESTION
so means
we can make a function that keeps up with the location of the car
sooo
int currentcolumn(most)
no this does not work
basically what I want to do is delete or add to sr and sc until they are equal to er ec
no idea
ermmmmmmm
the legit only way I can think of it is to delete steps from sr and sc
now we want ot keep sr and sc updated right?
so how can we do this?
so my code is essentially right but we need to do some editing
by that we mean the return zero is not working
this portion thing is really important so we can do substrings! that start with the letter itself the substring can have one or two a plan portion can have 0 --> turn letter
1 --> digit + turn letter
2 --> 2 digits + turn letter
how can this help you reach er ec
NO FUCKING CLUE
plan portions calculate total turns N,E,W,S TEST CASES:
1- what if it does not move 2
Download