Language: C++

#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

inline double add(double a, double b){
    return abs(a+b)<(1e-10)*(abs(a)+abs(b)) ? 0.0 : a+b;
}

struct vec{
    long double x,y;
    vec operator-(vec b){
        return (vec){add(x,-b.x),add(y,-b.y)};
    }
    vec operator+(vec b){
        return (vec){add(x,b.x),add(y,b.y)};
    }
    vec operator*(long double d){
        return (vec){x*d,y*d};
    }
    bool operator==(vec b){
        return x==b.x&&y==b.y;
    }
    bool operator!=(vec b){
        return x!=b.x||y!=b.y;
    }
    long double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    long double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    long double norm(){
        return sqrt(x*x+y*y);
    }
};
bool operator<(const vec&l, const vec&r){
    return l.x==r.x?l.y<r.y:l.x<r.x;
}

const double eps = 0.0000001;

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    long double o = ab.cross(ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(ab.dot(ac)<0){
        return 2; //C-A-B
    }else{
        if(ab.dot(ab)<ac.dot(ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

vec interSection(vec& p0,vec& p1,vec& p2,vec& p3){
    vec p23=p3-p2,p02=p2-p0,p01=p1-p0;
    double k = p23.cross(p02)/p23.cross(p01);
    return p0+p01*k;
}

int isInterSection(vec& p0,vec& p1,vec& p2,vec& p3){//??????p[0]p[1]??¨p[2]p[3]
    switch(ccw(p0,p1,p2)*ccw(p0,p1,p3)){
        case -1:
        case -4:
            break;
        case 0:
            return ~(ccw(p0,p1,p2)|ccw(p0,p1,p3))?2:-1;//?§???§??\??????????????´???
        default:
            return 0;
    }
    switch(ccw(p2,p3,p0)*ccw(p2,p3,p1)){
        case -1:
        case -4:
        case 0:
            break;
        default:
            return 0;
    }
    return 1;
}

struct Section{
    vec v1,v2;//?§??????¨??????
    vector<vec> cp;//??????(????????????????????¨?????????)
    Section(vec a, vec b){
        v1=a;v2=b;
        cp.push_back(v1);
        cp.push_back(v2);
    }
};

int main(void){
    int n;
    vector<Section> L;
    while(cin>>n,n){
        L.clear();
        L.push_back(Section((vec){.x=-100,.y=-100},(vec){.x=-100,.y=100}));
        L.push_back(Section((vec){.x=-100,.y=100},(vec){.x=100,.y=100}));
        L.push_back(Section((vec){.x=100,.y=100},(vec){.x=100,.y=-100}));
        L.push_back(Section((vec){.x=100,.y=-100},(vec){.x=-100,.y=-100}));

        for(int i=0;i<n;i++){
            vec v1,v2;
            cin >> v1.x >> v1.y >> v2.x >> v2.y;
            Section s = Section(v1,v2);
            for(auto& l:L){
                if(isInterSection(s.v1,s.v2,l.v1,l.v2)!=0){
                    vec v=interSection(s.v1,s.v2,l.v1,l.v2);
                    l.cp.push_back(v);
                    s.cp.push_back(v);
                }
            }
            L.push_back(s);
        }
        int edge=0;
        for(auto& l:L){
            sort(l.cp.begin(),l.cp.end());
            for(int i=0;i<l.cp.size()-1;){
                if((l.cp[i]-l.cp[i+1]).norm()<1e-10){
                    l.cp.erase(l.cp.begin()+i+1);
                    continue;
                }else{
                    i++;
                }
            }
            edge+=l.cp.size()-1;
        }
        vector<vec> V;
        for(auto& l:L){
            for(auto& v:l.cp) V.push_back(v);
        }
        sort(V.begin(),V.end());
        for(int i=0;i<V.size()-1;){
            if((V[i]-V[i+1]).norm()<1e-10){
                V.erase(V.begin()+i+1);
            }else{
                i++;
            }
        }
        int vertex=V.size();
        //??¢?????° = 2-???????????°+????????°
        cout << 2-vertex+edge -1 << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:121:13: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
  121 |             sort(l.cp.begin(),l.cp.end());
      |             ^~~~
      |             sqrt
a.cc:136:9: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
  136 |         sort(V.begin(),V.end());
      |         ^~~~
      |         sqrt