Compare commits
No commits in common. "481de18bbdddb28fb69f67acced7d021cf658ad5" and "b7beda1ebed6252bc378db0a18811eac0ae8e634" have entirely different histories.
481de18bbd
...
b7beda1ebe
@ -21,6 +21,7 @@ static bool is_leap(int year)
|
|||||||
|
|
||||||
static bool date_is_valid(int d, int m, int y)
|
static bool date_is_valid(int d, int m, int y)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
if (m < 1 || m > 12)
|
if (m < 1 || m > 12)
|
||||||
return false;
|
return false;
|
||||||
if (d < 1 || d > 31)
|
if (d < 1 || d > 31)
|
||||||
|
4
ex01/src/RPN.cpp
Normal file
4
ex01/src/RPN.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include <stack>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
@ -16,10 +16,10 @@ int calculate(std::stack<int>& nums, std::stack<char>& operators)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
int b = nums.top();
|
|
||||||
nums.pop();
|
|
||||||
int a = nums.top();
|
int a = nums.top();
|
||||||
nums.pop();
|
nums.pop();
|
||||||
|
int b = nums.top();
|
||||||
|
nums.pop();
|
||||||
|
|
||||||
switch (operators.top()) {
|
switch (operators.top()) {
|
||||||
case '+':
|
case '+':
|
||||||
@ -60,19 +60,17 @@ int main(int ac, char** av)
|
|||||||
if (std::isdigit(av[1][i]))
|
if (std::isdigit(av[1][i]))
|
||||||
nums.push(av[1][i] - '0');
|
nums.push(av[1][i] - '0');
|
||||||
else if (std::strchr("/+-*", av[1][i]) != NULL)
|
else if (std::strchr("/+-*", av[1][i]) != NULL)
|
||||||
{
|
|
||||||
operators.push(av[1][i]);
|
operators.push(av[1][i]);
|
||||||
if (calculate(nums, operators))
|
|
||||||
{
|
|
||||||
std::cout << "error: division by 0" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "error: '" << av[1][i] << "' unknown char" << std::endl;
|
std::cout << "error: '" << av[1][i] << "' unknown char" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (calculate(nums, operators))
|
||||||
|
{
|
||||||
|
std::cout << "error: division by 0" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (nums.size() != 1)
|
if (nums.size() != 1)
|
||||||
{
|
{
|
||||||
@ -81,7 +79,7 @@ int main(int ac, char** av)
|
|||||||
}
|
}
|
||||||
if (operators.size() != 0)
|
if (operators.size() != 0)
|
||||||
{
|
{
|
||||||
std::cout << "error: too many operators" << std::endl;
|
std::cout << "error: too manu operators" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << nums.top();
|
std::cout << nums.top();
|
||||||
|
Loading…
Reference in New Issue
Block a user