mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 18:06:58 +08:00
upload some new code
This commit is contained in:
57
FZOI/计算器的改良.cpp
Normal file
57
FZOI/计算器的改良.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
char c, a;
|
||||
int f = 1, now = 1, k, b, x;
|
||||
bool r;
|
||||
int main()
|
||||
{
|
||||
while (cin >> c)
|
||||
{
|
||||
if (c == '-')
|
||||
{
|
||||
b += now * f * x;
|
||||
x = 0;
|
||||
f = -1;
|
||||
r = 0;
|
||||
}
|
||||
if (c == '+')
|
||||
{
|
||||
b += now * f * x;
|
||||
x = 0;
|
||||
f = 1;
|
||||
r = 0;
|
||||
}
|
||||
if (c == '=')
|
||||
{
|
||||
b += now * f * x;
|
||||
x = 0;
|
||||
f = 1;
|
||||
now = -1;
|
||||
r = 0;
|
||||
}
|
||||
if (c >= 'a' && c <= 'z')
|
||||
{
|
||||
if (r)
|
||||
{
|
||||
k += now * f * x;
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
k += now * f;
|
||||
a = c;
|
||||
r = 0;
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
x = x * 10 + c - '0';
|
||||
r = 1;
|
||||
}
|
||||
}
|
||||
b += now * f * x;
|
||||
double ans = double(-b * 1.0 / k);
|
||||
if (ans == -0.0)
|
||||
ans = 0;
|
||||
printf("%c=%.3lf", a, ans);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user