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 <fstream>
- using namespace std;
- ifstream f("date.in");
- ofstream g("date.out");
- struct fractie
- {
- int a1,a2;
- };
- fractie v[1000],nou[1000];
- int cmmdc(int a,int b)
- {
- int r;
- r=a%b;
- while(r)
- {
- a=b;
- b=r;
- r=a%b;
- }
- return b;
- }
- int main()
- {
- int n,i,k=0,x,y,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++)
- g<<v[i].a1<<"/"<<v[i].a2<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement