Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- #include <fstream>
- #include <ctime>
- struct parType {
- int prvi;
- int drugi;
- bool vazeci;
- };
- using namespace std;
- int main() {
- srand(time(0));
- int n;
- do {
- cin>>n;
- }
- while(!(n>10000 && n<99999));
- ofstream kreiraj("datoteka.dat");
- kreiraj.close();
- fstream bindat("datoteka.dat",ios::binary | ios::out);
- parType *par = new parType[n];
- for(int i=0;i<n;i++) {
- par[i].vazeci=true;
- }
- for(int i=0;i<n;i++) {
- par[i].prvi = (rand()%21) - 10;
- par[i].drugi = (rand()%21) - 10;
- }
- bindat.close();
- for(int i=0;i<n;i++) {
- for(int j=i+1;j<n;j++) {
- int abspoprvoj = abs(par[i].prvi-par[j].prvi);
- int abspodrugoj = abs(par[i].drugi-par[j].drugi);
- if(abspoprvoj + abspodrugoj > 15)
- par[j].vazeci = false;
- }
- }
- // zapisati u datoteku nakon kaj smo proglasili nevazece
- for(int i=0;i<n;i++) {
- bindat.write((char*)&par[i],sizeof(par[i]));
- }
- int x=0,y=0;
- for(int i=0;i<n;i++) {
- if(par[i].vazeci) {
- x+=par[i].prvi;
- y+=par[i].drugi;
- }
- }
- cout << "(" << x << ", " << y << ")" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement