Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- se citesc n fractii dintr-un fisier. afisati fractiile reductibile ordonate crescator.
- ex:
- n=4
- 3,6 2,8 3,7 2,20
- se vor afisa:
- 2/20 2/8 3/6
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("date.in");
- struct fractie
- {
- int a1,a2;
- }v[100];
- int cmmdc(int a,int b)
- {
- int r;
- while(a!=b)
- if(a>b) a=a-b;
- else b=b-a;
- return b;
- }
- int main()
- {
- int n,x,y,k=0;
- int i,j;
- f>>n;
- for (i=1;i<=n;i++)
- {
- f>>x>>y;
- if (cmmdc(x,y)!=1)
- {v[++k].a1=x;
- v[++k].a2=y;}
- }
- for (i=1;i<=k-1;i++)
- for (j=i+1;j<=k;j++)
- if ((v[i].a1*v[j].a2)>(v[j].a1*v[i].a2))
- swap (v[i],v[j]);
- for (i=1;i<=k;i++)
- cout<<v[i].a1<<"/"<<v[i].a2;
- return 0;
- }
- /*
- 2. definiti un tip de date pentru memorarea lungimii si latimii unui dreptunghi. cititi un numar natural n, apoi n perechi de numere intregi, reprezentand n dreptunghiuri.
- a) afisati laturile dreptunghiului cu arie max
- b) afisati ariile dreptunghiului cu perimetrul minim
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("date.in");
- struct dreptunghi
- {
- int L,l; // l - lungime L - latime
- }v[100];
- int main()
- {
- int n,i,a[100],max=-9000,lun,lat,b[100],min=9999,lun2,lat2;
- cout<<"n= ";cin>>n;
- for (i=1;i<=n;i++)
- cin>>v[i].l>>v[i].L;
- for (i=1;i<=n;i++)
- {a[i]=v[i].l*v[i].L;
- b[i]=2*v[i].l+2*v[i].L;
- if (a[i]>max)
- {max=a[i];
- lun=v[i].l;
- lat=v[i].L;
- }
- if (b[i]<min)
- {
- min=b[i];
- lun2=v[i].l;
- lat2=v[i].L;
- }
- }
- cout<<"Laturile dreptunghiului cu aria cea mai mare: "<<lun<<" "<<lat<<'\n';
- cout<<"Laturile dreptunghiului cu perimetrul cel mai mic: "<<lun2<<" "<<lat2<<'\n';
- return 0;
- }
- //Se verifica daca un triunghi e cuprins in alt triunghi. Nu merge???
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("date.in");
- ofstream g("date.out");
- struct punct
- {
- int x,y;
- }A,B,C,P;
- int n,k;
- double arie(int x1,int y1, int x2,int y2, int x3,int y3)
- {
- return 0.5*(x1*y2+x2*y3+x3*y1-y2*x3-y3*x1-y1*x2);
- }
- int main()
- {
- f>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y;
- f>>n;
- int i;
- float a=arie(A.x,A.y,B.x,B.y,C.x,C.y);
- for (i=1;i<=n;i++)
- {
- f>>P.x>>P.y;
- if (arie(P.x,P.y,C.x,C.y,A.x,A.y)+arie (P.x,P.y,B.x,B.y,C.x,C.y)==a)\
- k++;
- }
- g<<k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement