4
: 8210
__________________ .. :
__________________ ..
2011 .
. 3
. 3
. 3
. 4
. 6
. 6
.. 7
. 7
. 10
. 11
( ) 12
.
.
, , . .
, , . .
. :
;
;
;
;
;
;
, : P(x,y,z)=x7y2z+3x2z-6y2-3z9 Q(x,y,z)=-7x2z+6y2+5. R(x,y,z)=x7y2z-4x2z-3z9+5.
.
(. 1).
. 1. .
.
// :
1/2/4;
;
;
;
;
;
;
.
. 2. .
.3. .
.4. .
:
|
|
3;
;
;
;
.
.5. .
.
.
elem -
pol
.
, x - , y, z.
" " ().
xAyBzC+n. A*1000+B*100+C*10+n ( A, B C 9).
.
Mpars
unsigned int Mpars[500];
node *Bfirst, *Blast;
node *BRes; // .
node *Afirst, *Alast;
node *ARes; // .
struct node {
int elem;
unsigned int pol;
node *next;
};
Spisok
class Spisok
{
private:
int N_monom;
public:
Spisok() {phead = new (node); (*phead).next=NULL;} //.
~Spisok() { delete phead; } //.
void Initial(node **first, node **last);
int Empty(node *first);
void Add(node **last,int elem, unsigned int pol);
void Show(node *first);
int Poisk_Eqv (node *first,unsigned int pol,node **last);
int Poisk_Less (node *first,int el,node **last);
void Izm (node *Res, int el,unsigned int pol);
void DelAll(node *first, node **last);
void AddLess (node **Res, int el,unsigned int pol);
int Next (node *first,int el,node **last);
void Del1 ();
};
Spisok
class Spisok
{
private:
node *phead; // .
node *pend;
node *cursosr;
node *Res; // .
int N_monom;
public:
Spisok() {phead = new (node); (*phead).next=NULL;} //
~Spisok() { delete phead; } //.
void Initial(node **first, node **last);
int Empty(node *first);
void Add(node **last,int elem, unsigned int pol);
void Show(node *first);
int Poisk_Eqv (node *first,unsigned int pol,node **last);
int Poisk_Less (node *first,int el,node **last);
void Izm (node *Res, int el,unsigned int pol);
void DelAll(node *first, node **last);
void AddLess (node **Res, int el,unsigned int pol);
int Next (node *first,int el,node **last);
void Del1 ();
};
.
"1."
, .
|
|
. , . , :
P='x7y2z1+3x2z1-6y2-3z9 '
Q='-7x2z1+6y2+5'
. .
. . , : , .
, . , P(x,y,z) :
P(x,y,z)='x7y2z1-4x2z1-3x9+5'
1. stdin ()
2.
3. , .
4. , : P Q. , P .
:
. P Q , , . (P). , Q P, Q P; Q . P Q, P . P Q , : P Q. , P . . , .
. . . , Dispose(q).
, , , , : : , , , . .
1. ., . C++: . . .: ̻, 1999. 816 .: .
2. . C++:. . .: . , 2007. 800 .
|
|
3. .., .
( )
Stdafx.h
#ifndef ST_REAL_H
#define ST_REAL_H
#pragma once
#include <stdlib.h >
#include <conio.h>
#include <stdarg.h>
#include <math.h>
#include <windows.h>
#include <process.h>
#include <string.h>
#include <stdio.h>
#include <fstream> // .
#include <iostream> // cin, cout, cerr clog,
#include <iomanip> // / .
using namespace std;
using namespace System;
using std::cin;
using std::cout;
int parse();
void inttoname(int nom,unsigned int pol,char buffer[]);
int Svernut(char s[]);
void AntiPars(int Anom,unsigned int Mpars[]);
void CreatSpis(int Anom);
int getfile();
struct node {
int elem;
unsigned int pol;
node *next;
};
void Proizvodnay(node *first);
class Spisok
{
private:
node *phead; // .
node *pend;
node *cursosr;
node *Res; // .
int N_monom;
public:
Spisok() {phead = new (node); (*phead).next=NULL;} //
~Spisok() { delete phead; } //.
void Initial(node **first, node **last);
int Empty(node *first);
void Add(node **last,int elem, unsigned int pol);
void Show(node *first);
int Poisk_Eqv (node *first,unsigned int pol,node **last);
int Poisk_Less (node *first,int el,node **last);
void Izm (node *Res, int el,unsigned int pol);
void DelAll(node *first, node **last);
void AddLess (node **Res, int el,unsigned int pol);
int Next (node *first,int el,node **last);
void Del1 ();
};
#endif
Spis06.cpp
#include "stdafx.h"
Spisok A,B;
unsigned int Mpars[500];
//unsigned int Mpars1[500];
node *Bfirst, *Blast;
node *BRes; // .
node *Afirst, *Alast;
node *ARes; // .
void Spisok::Del1 ()
// , Res.
{
node *q,*q1,*q2;
// .
q = (*ARes).next;
if (q!=NULL)//
{
(*ARes).elem = (*q).elem;
(*ARes).pol = (*q).pol;
(*ARes).next = (*q).next; // ""
delete q;
}
else
{
q1 = Afirst;
q2 = (*q1).next;
while (q2!=ARes)
{
q1 = q2;
q2 = (*q2).next;
}
(*q1).next = NULL;
q2 = NULL;
delete ARes;
}
}
void Spisok::Initial(node **first, node **last)
{
*first=new node;
(*first)->next=NULL;
*last=*first;
N_monom=0;
}
int Spisok::Empty(node *first)
{
if (first->next==NULL)
return 1;
else
return 0;
}
void Spisok::Add(node **last,int elem,unsigned int pol)
{
node *tmp=new node;
tmp->elem=elem;
tmp->pol=pol;
tmp->next=NULL;
(*last)->next=tmp;
*last=tmp;
N_monom++;
}
void Spisok::Izm (node *Res, int el,unsigned int pol)
// el
{
// cout << endl<<"izmres="<< Res->elem<< Res->pol;
cout << endl;
Res->elem = el;
Res->pol = pol;
// (*Res).pol = pol;
}
void Spisok::DelAll(node *first, node **last)
{
node *tmp;
while(first->next!=NULL)
|
|
{
tmp=first->next;
first->next=tmp->next;
delete tmp;
}
*last=first;
}
void Spisok::Show(node *first)
{
node *tmp=first->next;
cout <<endl;
while(tmp!=NULL)
{
cout << tmp->elem << " "<< tmp->pol << ", ";
tmp=tmp->next;
}
cout <<endl;
}
int Spisok::Poisk_Eqv (node *first,unsigned int pol,node **last)
// el ,
// *first. Res 1 last
// , el,
// Res 0.
{
unsigned int r;
int rez=0;
node *tmp=first->next;
while(tmp!=NULL)
{
r=tmp->pol;
if(pol==r)
{
// cout << r << " ";
rez=1;
break;
}
tmp=tmp->next;
}
*last=tmp;
return(rez);
}
int Spisok::Poisk_Less (node *first,int sv,node **last)
// el ,
// *first. Res 1 last
// , el,
// Res 0.
{
int rez=0;
int r;
node *tmp=first->next;
while(tmp!=NULL)
{
r=tmp->pol;
if(sv>r)
{
/// cout << r << " ";
rez=1;
break;
}
tmp=tmp->next;
}
*last=tmp;
return(rez);
}
void Spisok::AddLess (node **Res, int el,unsigned int pol)
// el
// , *Res.
{
node *q;
//
q = new (node);
(*q).elem = (**Res).elem;
(*q).pol = (**Res).pol;
(*q).next = (**Res).next;
//
(**Res).elem = el;
(**Res).pol = pol;
(**Res).next = q;
N_monom++;
}
int Spisok::Next (node *first,int el,node **last)
// el ,
//phead. Res
// , el,
// Res NULL.
{
int r;
node *tmp=first->next;
if (tmp==NULL) return (1);
r=tmp->elem;
*last=tmp;
return(0);
}
void Show(node *first)
{
node *tmp=first->next;
int el;
unsigned int pol;
char buf[256];
while(tmp!=NULL)
{
el =tmp->elem;
pol =tmp->pol;
inttoname(el,pol, buf);
tmp=tmp->next;
}
}
void CreatSpisA(int Anom)
{
int dig=0;
unsigned int sv=0;
int dig0=0;
for(int i=0;i<(Anom/2);i++)
{
dig0=0;
dig=Mpars[i*2];//
sv=Mpars[i*2+1];
A.Poisk_Eqv (Afirst, sv,&ARes);
if(ARes!=NULL)
{
dig0=ARes->elem; // -
dig0=dig0+dig;
/// cout << endl<<"poisk pol = "<< ARes->pol<< endl;
if(dig0!=0)
{
A.Izm (ARes, dig0, sv); //
continue;
}
if(dig0==0) //
{
A.Del1 ();
continue;
}
}
if(A.Poisk_Less (Afirst, sv,&ARes)== 1) {
A.AddLess (&ARes, dig, sv);
}
else {
A.Add(&Alast,dig,sv);
}
}
cout << endl<<"== A" << endl;
Show(Afirst);
}
void CreatSpisB(int Anom)
{
int dig=0;
unsigned int sv=0;
int dig0=0;
for(int i=0;i<(Anom/2);i++)
{
dig0=0;
dig=Mpars[i*2];//
sv=Mpars[i*2+1];
B.Poisk_Eqv (Bfirst, sv,&BRes);
if(BRes!=NULL)
{
dig0=BRes->elem; // -
dig0=dig0+dig;
if(dig0!=0)
{
B.Izm (BRes, dig0, sv); //
continue;
}
if(dig0==0) //
{
B.Del1 ();
continue;
}
}
if(B.Poisk_Less (Bfirst, sv,&BRes)== 1) {
B.AddLess (&BRes, dig, sv);
}
else {
B.Add(&Blast,dig,sv);
}
}
cout << endl<<"== B" << endl;
Show(Bfirst);
}
void Proizvodnay(node *first)
{
node *tmp=first->next;
int el;
unsigned int pol;
char buf[256];
int x,y,z,i;
cout <<endl;
while(tmp!=NULL)
{
el =tmp->elem;
pol =tmp->pol;
x=pol/1000;
y=(pol%1000)/100;
z=((pol%1000)%100)/10;
if(x>1)
{
el=el*x;
x=x-1;
}
pol=x*1000+y*100+z*10;
if(x!=0) B.Add(&Blast,el,pol);
//
tmp=tmp->next;
}
cout<<endl<< ""<<endl;
|
|
Show(Bfirst);
}
void Proizvodnay1(node *Afirst,node *Bfirst,int Anom)
{
node *Atmp=Afirst->next;
int el=5;
int el1;
int rel;
unsigned int pol, pol1, rpol;
char buf[256];
int x,y,z,i;
int x1,y1,z1;
int rx,ry,rz;
int dig=0;
int imonom=0;
unsigned int MMult[500];
int Mi=0;
Mi=0;
imonom=0;
while(Atmp!=NULL)
{
node *Btmp=Bfirst->next;
el =Atmp->elem;
pol =Atmp->pol;
x=pol/1000;
y=(pol%1000)/100;
z=((pol%1000)%100)/10;
// x
pol=pol*x;
y=0;
z=0;
if (x>1) x=x-1;
// x
//
pol=x*1000+y*100+z*10;
if(x!=0) B.Add(&Blast,el,pol);
//
Atmp=Atmp->next;
} //
AntiPars(imonom, Mpars);
//
cout << endl << " "<< endl;
Show(Bfirst); //
getch();
cout<<endl<< ""<<endl;
Show(Bfirst);
}
void Mult(node *Afirst,node *Bfirst,int Anom)
{
node *Atmp=Afirst->next;
int el=5;
int el1;
int rel;
unsigned int pol, pol1, rpol;
char buf[256];
int x,y,z,i;
int x1,y1,z1;
int rx,ry,rz;
int dig=0;
int imonom=0;
unsigned int MMult[500];
int Mi=0;
Mi=0;
imonom=0;
while(Atmp!=NULL)
{
node *Btmp=Bfirst->next;
el =Atmp->elem;
pol =Atmp->pol;
x=pol/1000;
y=(pol%1000)/100;
z=((pol%1000)%100)/10;
while(Btmp!=NULL)
{
el1 =Btmp->elem;
pol =Btmp->pol;
x1=pol/1000;
y1=(pol%1000)/100;
z1=((pol%1000)%100)/10;
//
rel=el*el1;
// x y z
rx=x+x1;
ry=y+y1;
rz=z+z1;
//
Mpars[imonom]=rel;//
Mpars[imonom+1]=rx*1000+ry*100+rz*10;
imonom=imonom+2;
Btmp=Btmp->next;
} //
Atmp=Atmp->next;
} //
AntiPars(imonom, Mpars);
//
A.DelAll(Afirst,&Alast); //
CreatSpisA(imonom); //
cout << endl << " "<< endl;
Show(Afirst); //
getch();
}
int main()
{
A.Initial(&Afirst,&Alast);
B.Initial(&Bfirst,&Blast);
char otv;
int nom;
unsigned int svertka;
char buf[300];
int dig;
int Anom=0;
unsigned int sv;
FILE *in;
do
{
cout // << endl << "1. " << endl
// << "2. " << endl
//<< "3. " << endl
///<< "4. " << endl
//<< "5. " << endl
//<< "6. " << endl
<< "1. " << endl
//<< "8. " << endl
//<< "9. " << endl
<< "0. " << endl;
cout << '>';
cin >> otv;
switch(otv)
{
case '88': //+++
break;
case '2': //
//Anom= getfile(); break;
case '3'://+++
// AntiPars(Anom,Mpars); //
break;
case '4'://+++
// CreatSpis(Anom); //
break;
case '5'://+++
//Show(Afirst); //
break;
case '6'://+++ //
break;
case '1'://+++
cout<<endl<< "--1-";
cout<<endl<< "--2-";
cout<<endl<< "--3-";
cout<<endl<< "--4-"<< endl;
cin >> otv;
//
if(otv=='1') //
{
A.DelAll(Afirst,&Alast); //
Anom= getfile();
CreatSpisA(Anom); //
B.DelAll(Bfirst,&Blast); //
Anom= getfile();
CreatSpisB(Anom); //
CreatSpisA(Anom); //
getch();
}
if(otv=='2') //
{
A.DelAll(Afirst,&Alast); //
Anom= getfile();
CreatSpisA(Anom); //
B.DelAll(Bfirst,&Blast); //
Anom= getfile();
CreatSpisB(Anom); //
AntiPars(Anom, Mpars);
//
for(int i=0;i<Anom/2;i++)
{
Mpars[i*2]=(Mpars[i*2])*(-1);//
//dig=Mpars[i*2];
//sv=Mpars[i*2+1];
//inttoname(dig,sv, buf);
}
AntiPars(Anom, Mpars);
CreatSpisA(Anom); //
getch();
}
if(otv=='3') //
{
A.DelAll(Afirst,&Alast); //
Anom= getfile();
CreatSpisA(Anom); //
B.DelAll(Bfirst,&Blast); //
Proizvodnay1(Afirst,Bfirst, Anom);
_getch();
}
if(otv=='4') //
{
A.DelAll(Afirst,&Alast); //
Anom= getfile();
CreatSpisA(Anom); //
B.DelAll(Bfirst,&Blast); //
Anom= getfile();
CreatSpisB(Anom); //
Mult(Afirst,Bfirst,Anom);
_getch();
}
break;
case '0'://
A.DelAll(Afirst,&Alast);
break;
default:
cout << endl << "" << endl;
break;
}
}while(otv!='0');
}
Pars6.cpp
#include "stdafx.h"
extern unsigned int Mpars[500];
void AntiPars(int Anom, unsigned int Mpars[])
//
// xyz
{
int i=0;
int dig;
unsigned int sv;
char buf[256];
printf("\n");
for(int i=0;i<Anom/2;i++)
{
dig=Mpars[i*2];//
sv=Mpars[i*2+1];
inttoname(dig,sv, buf);
}
printf("\n");
}
void inttoname(int elem,unsigned int pol,char buffer[])
//
// . . -
{
int j=0;
int x,y,z,i;
i=pol%1000;
x=pol/1000;
y=(pol%1000)/100;
z=((pol%1000)%100)/10;
j = sprintf(buffer," "); // C4996
if(elem!=1) j += sprintf(buffer+j,"%+d",elem); // C4996
if(elem==1) j += sprintf(buffer+j,"+"); // C4996
if(elem==-1) j += sprintf(buffer+j,"-"); // C4996
if(x>1) j += sprintf(buffer+j,"x%d",x); // C4996
if(y>1) j += sprintf(buffer+j,"y%d",y); // C4996
if(z>1) j += sprintf(buffer+j,"z%d",z); // C4996
if(x==1) j += sprintf(buffer+j,"x"); // C4996
if(y==1) j += sprintf(buffer+j,"y"); // C4996
if(z==1) j += sprintf(buffer+j,"z"); // C4996
printf("%s",buffer);
}
int getfile()
{
FILE *in;
char name[200];
char buf[300];
int inom=0;
cout << endl<< " "<< endl<< "=";
cin >> name;
// printf("\n %s \n",name);
if((in = fopen(name, "r")) == NULL) // C4996
{
printf("\n %s\n",name);
_getch();
exit(0);
}
else
{
// printf("\n %s\n",name);
fgets(buf,200,in);
fclose(in);
inom= Svernut (buf);
}
return(inom);
}
//============================================================
/*
.
, x - , y, z.
" " ().
xAyBzC+n. A*1000+B*100+C*10+n ( A, B C 9).
.
, x3y xy7z6, 310 176.
, :
P(x,y,z)=x7y2z+3x2z-6y2-3z9
Q(x,y,z)=-7x2z+6y2+5.
R(x,y,z)=x7y2z-4x2z-3z9+5.
-
- Mpars
-
*/
int Svernut(char buf[])
{
// int x,y,z;
int i,j,k,l;
char c;
unsigned int sv=0; // 0 to 4,294,967,295
//char buf[128];
char nom[50];
char monom[50];
int pr=0; //
int dig=0;
int imonom=0;
i=0;
cout << endl<< "== : "<< endl;
cout << buf;
for(;;)
{
j=0;
if(i>strlen(buf)) break;
c=buf[i];
if(isdigit(c))
{
monom[j]='+';
j++;
}
if(pr==0)
{
if(c=='+'|| c=='-')
{
monom[j]=c;
j++;
i++;
pr=1;
}
if(isdigit(c))
{
monom[j]='+';
j++;
pr=1;
}
} //
for(;;)
{
pr=0;
monom[j]=0x00;
c=buf[i];
if(i>strlen(buf)) break;
if(c=='+'|| c=='-') break;
monom[j]=c;
j++;
i++;
monom[j]=0x00;
} //
//
k=0;
for(;;)
{
if(k>=j) break;
c=monom[k];
if(c=='x'|| c=='y'|| c=='z') break;
nom[k]=c;
k++;
}
nom[k]=0x00;
// printf("\n nom=%s",nom); //
//
for(;;)
{
if(k>=j) break;
c=monom[k];
l=1;
if(k+1<j) // -
{
if(isdigit(monom[k+1]))
{
l=monom[k+1]-'0';
}
}
if(c=='x')
{
sv=sv+l*1000;
if (l>1) k++; //
}
if(c=='y')
{
sv=sv+l*100;
if (l>1) k++; //
}
if(c=='z')
{
sv=sv+l*10;
if (l>1) k++; //
}
k++;
}
nom[k]=0x00;
dig=atoi(nom);
if(strlen(nom)==1) //
{
if(nom[0]=='-') dig=-1;
if(nom[0]=='+')dig=1;
}
if(dig==0) dig=1;
///printf("\n =%s %d",nom,dig); // strtoi
if(sv==0) sv=1; //
///printf("\n sv=%d",sv); //
Mpars[imonom]=dig;//
Mpars[imonom+1]=sv;
imonom=imonom+2;
sv=0; //
j=0;
} //
return(imonom);//
}