Показать сообщение отдельно

  #5  
Старый 24.03.2010, 12:44
Helium
Новичок
Регистрация: 06.01.2010
Сообщений: 23
Провел на форуме:
349200

Репутация: 1
По умолчанию

И,да вот готовый
PHP код:
uses wincrt;
label 1,2,3,4;
type zz=array[1..20of string;
     
aa=array[1..20of byte;
     
kk=array[1..30of real;
var
i,n,m,k,j,o,l,xinteger;   a,b,v:string;
c:array[1..10of string;
f:text;     result:real;

function 
calculate(x:string):string;
var 
i,j,k:integer;  a:zzt:aa;  s,s1,s2:realh:string;
c1:integerp:integerc:kk;
begin
k
:=1;
s:=0;
s1:=1;
for 
i:=1 to 20 do
a[i]:='';
for 
i:=1 to 30 do
t[i]:=0;
 for 
i:=1 to length(x) do
 
begin
 
if (x[i]='+') or (x[i]='-') or (x[i]='*') or (x[i]='/')
  
then
  begin
   
if x[i]='+' then t[k]:=1;
   if 
x[i]='-' then t[k]:=2;   {разделяет плюсыминусы и цифры}
   if 
x[i]='*' then t[k]:=3;
   if 
x[i]='/' then t[k]:=4;
   
k:=k+1;
   
end
  
else
  
a[k]:=a[k]+x[i];
   
end;
   for 
i:=1 to k do             {переводит в числовой массив}
   
val(a[i],c[i],c1);
   if 
x[1]='-' then p:=1;
   if (
p<>1) and (t[1]=2) and (t[2]<>3) and (t[2]<>4then s:=c[1];
   if (
t[1]=2) and (t[2]=2then s:=c[1];
if (
t[1]=1) or (k=1then s:=c[1];        {начальные значения}

for 
i:=1 to k do
   
begin
    
if (t[i]=3then
    begin
    
if (t[i-1]<>2) and (t[i-1]<>3) and (t[i-1]<>4then
    begin
    
{s:=s+c[i]*c[i+1];}
    
s1:=c[i]*c[i+1];
    {
s:=s+s1;}
    
end;                           {знак *}
    if (
t[i-1]=2then
    begin
   
{s:=s-c[i]*c[i+1];}
    
s1:=-c[i]*c[i+1];
    {
s:=s+s1;}
    
end;
    if (
t[i-1]=4) or (t[i-1]=3then
    begin
    s1
:=s1*c[i+1];
     {
s:=s+s1;}
     
end;
    
end;


    if (
t[i]=4then
    begin
    
if (t[i-1]<>2) and (t[i-1]<>3) and (t[i-1]<>4then
    begin
    
{s:=s+c[i]/c[i+1]; }
    
s1:=c[i]/c[i+1];
    
end;
    if 
t[i-1]=2 then
    begin                             
{знак /}
    
s1:=-c[i]/c[i+1];
    
end;
    if (
t[i-1]=3) or (t[i-1]=4then
    begin
    s1
:=s1/c[i+1];
    {
s:=s1+s; }
    
end;
    
end;
    if (
t[i+1]<>3) and (t[i+1]<>4) and (s1<>1then
    begin
    s
:=s+s1;
    
s1:=1;
    
end;
   
end;
for 
i:=1 to k do
begin
if t[i]=2
then
begin
if (i=1) and (p=1) and (t[2]=2then s:=s-c[2];
if (
t[i+1]<>4) and (t[i+1]<>3then
s
:=s-c[i+1]                             {знак -}
else
s:=s+c[i];
end;

if (
t[i]=1) and (t[i+1]<>3) and (t[i+1]<>4)
then
s
:=s+c[i+1];                            {знак +}
{
writeln(c[i]:5:3);}
end;

str(s:5:3,h);
calculate:=h;
end;


begin
assign
(f,'calc.in');
reset(f);
readln(f,a);
1:
k:=0;
for 
i:=1 to length(a) do
if 
a[i]='(' then k:=k+1;
if 
k=0 then goto 2;
i:=0;
l:=0;
while 
i<=length(a) do
begin
3
: if l>k then goto 2;
i:=i+1;
if 
a[i]='(' then
begin
l
:=l+1;
n:=i;
b:='';
while 
a[i]<>')' do
begin
if (a[i]='(') and (a[i+1]='('then goto 3;
if 
a[i]='(' then
begin
n
:=i;
i:=i+1;
b:='';
end;
b:=b+a[i];
{
writeln(b);}
i:=i+1;
end;
m:=i;
a:=copy(a,1,n-1)+calculate(b)+copy(a,m+1,length(a));
{
writeln(a);}
goto 
1;
end;
end;
2:
val(calculate(a),result,o);
write(result:5:3);
end
 
Ответить с цитированием