Varianta 73 / Subiectul 3 / Problema 3 |
#include<fstream.h> ifstream f("sir.in"); int cautare(int n, int x[1000], int v) { int i,j,m; i=1; j=n; if(x[1]>v) return 1; if(x[n]<v) return n+1; while(i<=j) { m=(i+j)/2; if(x[m]>v) j=m-1; else i=m+1; } return i; } void main() { int x[1000],n,k,p,i; f>>x[1];n=1; cout<<endl; while(f>>k) { p=cautare(n,x,k); for(i=n;i>=p;i--) x[i+1]=x[i]; n++; x[p]=k; } for(i=1;i<=n;i++) cout<<x[i]<<" "; } |