Advertisement
icatalin

probleme 1.4.2015

Apr 1st, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. /*
  2. se citesc n fractii dintr-un fisier. afisati fractiile reductibile ordonate crescator.
  3. ex:
  4. n=4
  5. 3,6 2,8 3,7 2,20
  6. se vor afisa:
  7. 2/20 2/8 3/6
  8. */
  9.  
  10. #include <iostream>
  11. #include <fstream>
  12.  
  13. using namespace std;
  14.  
  15. ifstream f("date.in");
  16.  
  17. struct fractie
  18. {
  19. int a1,a2;
  20. }v[100];
  21.  
  22. int cmmdc(int a,int b)
  23. {
  24. int r;
  25. while(a!=b)
  26. if(a>b) a=a-b;
  27. else b=b-a;
  28. return b;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. int n,x,y,k=0;
  35. int i,j;
  36. f>>n;
  37. for (i=1;i<=n;i++)
  38. {
  39.  
  40. f>>x>>y;
  41. if (cmmdc(x,y)!=1)
  42. {v[++k].a1=x;
  43. v[++k].a2=y;}
  44. }
  45.  
  46. for (i=1;i<=k-1;i++)
  47. for (j=i+1;j<=k;j++)
  48. if ((v[i].a1*v[j].a2)>(v[j].a1*v[i].a2))
  49. swap (v[i],v[j]);
  50.  
  51. for (i=1;i<=k;i++)
  52. cout<<v[i].a1<<"/"<<v[i].a2;
  53.  
  54.  
  55.  
  56. return 0;
  57. }
  58.  
  59. /*
  60.  
  61. 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.
  62. a) afisati laturile dreptunghiului cu arie max
  63. b) afisati ariile dreptunghiului cu perimetrul minim
  64.  
  65. */
  66.  
  67. #include <iostream>
  68. #include <fstream>
  69.  
  70. using namespace std;
  71.  
  72. ifstream f("date.in");
  73.  
  74. struct dreptunghi
  75. {
  76. int L,l; // l - lungime L - latime
  77. }v[100];
  78.  
  79.  
  80.  
  81. int main()
  82. {
  83. int n,i,a[100],max=-9000,lun,lat,b[100],min=9999,lun2,lat2;
  84. cout<<"n= ";cin>>n;
  85.  
  86. for (i=1;i<=n;i++)
  87. cin>>v[i].l>>v[i].L;
  88. for (i=1;i<=n;i++)
  89. {a[i]=v[i].l*v[i].L;
  90. b[i]=2*v[i].l+2*v[i].L;
  91. if (a[i]>max)
  92. {max=a[i];
  93. lun=v[i].l;
  94. lat=v[i].L;
  95. }
  96. if (b[i]<min)
  97. {
  98. min=b[i];
  99. lun2=v[i].l;
  100. lat2=v[i].L;
  101. }
  102.  
  103. }
  104.  
  105. cout<<"Laturile dreptunghiului cu aria cea mai mare: "<<lun<<" "<<lat<<'\n';
  106. cout<<"Laturile dreptunghiului cu perimetrul cel mai mic: "<<lun2<<" "<<lat2<<'\n';
  107.  
  108.  
  109. return 0;
  110. }
  111.  
  112.  
  113. //Se verifica daca un triunghi e cuprins in alt triunghi. Nu merge???
  114. #include <iostream>
  115. #include <fstream>
  116.  
  117. using namespace std;
  118.  
  119. ifstream f("date.in");
  120. ofstream g("date.out");
  121.  
  122. struct punct
  123. {
  124.  
  125. int x,y;
  126. }A,B,C,P;
  127.  
  128. int n,k;
  129. double arie(int x1,int y1, int x2,int y2, int x3,int y3)
  130. {
  131. return 0.5*(x1*y2+x2*y3+x3*y1-y2*x3-y3*x1-y1*x2);
  132. }
  133.  
  134. int main()
  135. {
  136. f>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y;
  137. f>>n;
  138. int i;
  139. float a=arie(A.x,A.y,B.x,B.y,C.x,C.y);
  140. for (i=1;i<=n;i++)
  141. {
  142. f>>P.x>>P.y;
  143. 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)\
  144. k++;
  145. }
  146. g<<k;
  147. return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement