Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	x := make([]int, 100)
	y := make([]int, 100)
	r := make([]int, 100)
	for scanner.Scan() {
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		for i := 0; i < a; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmpx, _ := strconv.Atoi(input[0])
			tmpy, _ := strconv.Atoi(input[1])
			tmpr, _ := strconv.Atoi(input[2])
			x[i], y[i], r[i] = tmpx, tmpy, tmpr
		}
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			c, _ := strconv.Atoi(input[0])
			d, _ := strconv.Atoi(input[1])
			e, _ := strconv.Atoi(input[2])
			f, _ := strconv.Atoi(input[3])
			ok := false
			for j := 0; j < a; j++ {
				if (c-x[j])*(c-x[j])+(d-y[j])*(d-y[j]) >= r[j]*r[j] || (e-x[j])*(e-x[j])+(f-y[j])*(f-y[j]) >= r[j]*r[j] {
					if (e-c)*(x[j]-c)+(f-d)*(y[j]-d) < 0 {
						if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d) <= r[j]*r[j] {
							ok = true
						}
					} else {
						if (e-c)*(x[j]-c)+(f-d)*(y[j]-d)>(e-c)*(e-c)+(f-d)*(f-d) {
							if (x[j]-e)*(x[j]-e)+(y[j]-f)*(y[j]-f)<=r[j]*r[j] {
								ok = true
							}
						} else {
							if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d)-((e-c)*(x[j]-c)+(f-d)*(y[j]-d))*((e-c)*(x[j]-c)+(f-d)*(y[j]-d))/((e-c)*(e-c)+(f-d)*(f-d))<=r[j]*r[j] {
								ok = true
							}
						}
					}

				}
			}
			if ok {
				fmt.Println("Safe")
			} else {
				fmt.Println("Danger")
			}
		}
	}
}

C++: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;

double distpp(double x1, double y1, double x2, double y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

double distpl(double xp, double yp,
              double x1, double y1,
              double x2, double y2){
    return abs((y1-y2)*(xp-x1)-(x1-x2)*(yp-y1))
           /distpp(x1, y1, x2, y2);
}

int main(){
    int n, m, i, j;
    while( cin >> n, n ){
        vector<double> wx(n),wy(n),r(n);
        for(i=0;i<n;i++){
            cin>>wx[i]>>wy[i]>>r[i];
        }
        cin >> m;
        vector<double> tx(m),ty(m),sx(m),sy(m);
        for(i=0;i<m;i++){
            cin>>tx[i]>>ty[i]>>sx[i]>>sy[i];
        }
        for(i=0;i<m;i++){
            bool safe = false;
            for(j=0;j<n;j++){
                double d1 = distpp(wx[j],wy[j],tx[i],ty[i]),
                       d2 = distpp(wx[j],wy[j],sx[i],sy[i]);
                if( (d1-r[j])*(d2-r[j]) < 0 ){
                    safe = true; break;
                }
                if( d1 < r[j] ) continue;
                if( distpl(wx[j],wy[j],tx[i],ty[i],sx[i],sy[i]) <= r[j] &&
                    ((sx[i]-tx[j])*(sx[i]-wx[j])+(sy[i]-ty[i])*(sy[i]-wy[j]))*
                    ((sx[i]-tx[j])*(tx[i]-wx[j])+(sy[i]-ty[i])*(ty[i]-wy[j])) < 0 ){
                    safe = true; break;
                }
            }
            if( safe ){
                cout << "Safe" << endl;
            }else{
                cout << "Danger" << endl;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> P;

#define EPS (1e-10)

double dot(P a,P b){
	return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a,P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a) < EPS) return abs(c-a);
	if(dot(a-b,c-b) < EPS) return abs(c-b);
	return abs(cross(b-a,c-a)) / abs(b-a);
}

bool intersected(P a,P b,P o,double r){
	double ao = abs(a-o);
	double bo = abs(b-o);
	if( (ao<r && bo>r || ao>r && bo<r) ||
		  (ao>r && bo>r && distance_ls_p(a,b,o) <= r) )
		return true;

	return false;
}

int main(void){
	int n,m;

	while(cin>>n && n){
		P o[n];
		double r[n];

		for(int i=0;i<n;i++){
			cin>>o[i].real()>>o[i].imag()>>r[i];
		}

		cin>>m;
		while(m--){
			P taro,oni;
			cin>>taro.real()>>taro.imag()>>oni.real()>>oni.imag();

			bool flg = true;
			for(int i=0;i<n;i++){
				if(intersected(taro,oni,o[i],r[i])){
					flg = false;
					break;
				}
			}

			if(flg) cout<<"Danger\n";
			else cout<<"Safe\n";
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};

const double EPS = 1e-9;

double dot(point a,point b){
    return real(conj(a)*b);
}

double cross(point a,point b){
    return imag(conj(a)*b);
}

// 直線と点との距離
// みけんしょう
double dist_line_and_point(point a1,point a2,point b){
    return abs(cross(a2-a1,b-a1)) / abs(a2-a1);
}

// 線分と点との距離
// みけんしょう
double dist_linesegment_and_point(point a1,point a2,point b){
    if(dot(a2-a1,b-a1) < EPS) return abs(b-a1);
    if(dot(a1-a2,b-a2) < EPS) return abs(b-a2);
    return dist_line_and_point(a1,a2,b);
}


// 円と線分の交差判定
bool is_cross_linesegment_and_circle(point c,double r,point a1,point a2){
    return (dist_linesegment_and_point(a1,a2,c) < r+EPS and
             (r < abs(c-a1) + EPS or r < abs(c-a2) + EPS));
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<pair<point,double> > cs;
        for(int i=0;i<n;i++){
            point p;double c;
            cin >> p.real() >> p.imag() >> c;
            cs.push_back(make_pair(p,c));
        }
        int m;
        cin >> m;
        for(int i=0;i<m;i++){
            point a,b;
            cin >> a.real() >> a.imag() >> b.real() >> b.imag();
            bool safe = false;
            for(int j=0;j<n;j++){
                if(is_cross_linesegment_and_circle(cs[j].first,cs[j].second,a,b)){
                    safe = true;
                }
            }
            if(safe){
                cout << "Safe" << endl;
            }else{
                cout << "Danger" << endl;
            }
        }
    }
    return 0;
}