Пример #1
0
	int Sit (char letter, int m, int state)
	{

						
		
			switch(state)
			{

				case 0 : 
					if(m == 0)
					{
						state = 2;
						 break;
					}
					else state = 0; break;
				case 1 : sec += 5; 
			

					if (m == 0) //check that it's the correct row
					{
					//	state = ST1;
						cout << " rows match" << endl;	
						state = 2;
						cout << " state 2" << endl;
						break;
					}
					else
					{
						state = 1; break;
					}
				case 2 : sec += 5; state = 3; cout<< "sto1 " << endl; break;
				case 3 : sec += 5; 
					cout << "sto2" << endl;
					if (letter == 'A' ) // if the stack needs to be popped
					{
						if (!ABC.isEmpty()) // B or C is sitting down in that row
						{						

//							state = O;
							state = 5; break;
						}
						else // no one blocking 
						{
										
//							state = S;
							state =  4; break;
						}								

					}
					else if (letter == 'F')
					{
						if (!DEF.isEmpty()) // D or E is sitting down
						{
//							state = O;
							state = 5; break;	
						}
						else // no one blocking
						{
//							state = S;
							state = 4; break;
						}
	
					}
					else if (letter == 'B') 
					{

						if (!ABC.isEmpty()) // A or C
						{
							if (ABC.top() == 'C') // stack must be popped
							{
//								state = O;
								state = 5; break;
							}
							else // stack doesn't need to be popped
							{
//								state = S;
								state = 4; break;
							}
						}
						else // no one blocking
						{
//							state = S; 
							state = 4;
							break;
						}
					}
					else if (letter == 'E')
					{

						if (!DEF.isEmpty()) // D or F 
						{
							if (DEF.top() == 'D') // pop stack
							{
//								state = O;
								state = 5; break;							
							}
							else // stack doesn't need popping
							{
//								state = S;
								state = 4; break;
							}
							
						}
						else // no one blocking
						{
//							state = S;
							state =  4; break;
						}
					}
					else //C or D
					{
//						state = S;
						state = 4;
						break;
					}

				case 4 :  

					if (letter == 'A' || letter == 'B' || letter == 'C')
					{
						ABC.push(letter);
						sec += 5;
						if (!temp.isEmpty()) // if someone had to be popped
						{
//							state = I;
							state = 6;
							break;
						}
						else
						{
//							cout << "sitting" << sec << endl;
							state =  7;
							break;
						}

					}	
					else
					{
						DEF.push(letter);
						sec += 5;
						if (!temp.isEmpty())
						{
//							state = I;
							state =  6;
							break;

						}
						else
						{					
//							cout << "sitting" << sec << endl;
							
							state =  7;
							break;
						}
					}
				case 5 : 
					

					if (letter == 'A' || letter == 'B')
					{
						if (letter == 'A')
						{						
							if (ABC.top() == 'C')
							{

								temp.push(ABC.top()); // move out C
								ABC.pop();
								sec += 5;
								if (!ABC.isEmpty()) // if B was also in
								{
									temp.push(ABC.top()); // move out A
									ABC.pop();
									sec += 5;
//									state = S;
									state =  4;
									break;	
								}
								else
								{
//									state = S; // if only C, go to sit
									state = 4;
									break;
								}
							}
						}
						else
						{
							temp.push(ABC.top()); // if letter B
							ABC.pop(); // pop off top which would be C
							sec += 5;
//							state = S;
							state =  4;
							break;
						}
					}
					else // E or F
					{
						if (letter == 'F')
						{						
							if (ABC.top() == 'D')
							{
								temp.push(DEF.top());
								DEF.pop();
								sec += 5;
								if (!DEF.isEmpty())
								{
									temp.push(DEF.top());
									DEF.pop();
									sec += 5;
//									state = S;
									state = 4;	
									break;
								}
								else
								{
//									state = S;
									state = 4;			
									break;
								}
							}
						}
						else
						{
							temp.push(DEF.top());
							DEF.pop();
							sec += 5;
							state = 4;
							break;
						}
						
						
					}

				case 6 : 
					while (!temp.isEmpty())
					{
						if (letter == 'A'|| letter == 'B' || letter == 'C')
						{
							ABC.push(temp.top());
							temp.pop();
							sec += 5;
						}
						else
						{
							DEF.push(temp.top());
							temp.pop();
							sec += 5;
						}
						
					}
//					cout << " blocked " << sec << endl;
					state = 7;
					break;
					
			}
		return state;
	}
Пример #2
0
LongInt LongInt::operator+(LongInt& int2)
{
	StackAr<int> stack1 = this->intStack;
	StackAr<int> stack2 = int2.intStack;
	StackAr<int> tempStack (1000001);
	LongInt newInt;
	int curr1;
	int curr2;
	int newDigit;
	int carry = 0;
		
	while (!stack1.isEmpty() && !stack2.isEmpty())
	{
		curr1 = stack1.top();
		stack1.pop();
		curr2 = stack2.top();
		stack2.pop();
		newDigit = curr1 + curr2 + carry;
		if (newDigit >= 10)
		{
			newDigit -= 10;
			carry = 1;
		}
		else
		{
			carry = 0;
		}
		tempStack.push(newDigit);
	}
	
	if (!stack1.isEmpty())
	{
		while (!stack1.isEmpty())
		{
			curr1 = stack1.top();
			stack1.pop();
			newDigit = curr1 + carry;
			if (newDigit >= 10)
			{
				newDigit -= 10;
				carry = 1;
			}
			else
			{
				carry = 0;
			}
			tempStack.push(newDigit);
		}
	}

	if (!stack2.isEmpty())
	{
		while (!stack2.isEmpty())
		{
			curr2 = stack2.top();
			stack2.pop();
			newDigit = curr2 + carry;
			if (newDigit >= 10)
			{
				newDigit -= 10;
				carry = 1;
			}
			else
			{
				carry = 0;
			}
			tempStack.push(newDigit);
		}
	}
	
	while (!tempStack.isEmpty())
	{
		newDigit = tempStack.top();
		tempStack.pop();
		newInt.addDigit(newDigit);
	}	
	return newInt;
}