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 <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Point {
public:
	long double px, py;
	Point() : px(0), py(0) {};
	Point(long double px_, long double py_) : px(px_), py(py_) {};
	bool operator==(const Point& p) const { return px == p.px && py == p.py; }
	bool operator!=(const Point& p) const { return px != p.px || py != p.py; }
	bool operator<(const Point& p) const { return px < p.px ? true : (px == p.px && py < p.py); }
	bool operator>(const Point& p) const { return px > p.px ? true : (px == p.px && py > p.py); }
	bool operator<=(const Point& p) const { return !(Point(px, py) > p); }
	bool operator>=(const Point& p) const { return !(Point(px, py) < p); }
	Point operator+(const Point& p) const { return Point(px + p.px, py + p.py); }
	Point operator-(const Point& p) const { return Point(px - p.px, py - p.py); }
	Point operator/(long double d) const { return Point(px / d, py / d); }
	friend Point operator*(const Point p, long double d) { return Point(p.px * d, p.py * d); }
	friend Point operator*(long double d, const Point& p) { return p * d; }
	Point& operator+=(const Point& p1) { px += p1.px, py += p1.py; return *this; }
	Point& operator-=(const Point& p1) { px -= p1.px, py -= p1.py; return *this; }
	Point& operator*=(long double d) { px *= d, py *= d; return *this; }
	Point& operator/=(long double d) { px /= d, py /= d; return *this; }
};
class Segment {
public:
	Point p1, p2;
	Segment() : p1(Point()), p2(Point()) {};
	Segment(Point p1_, Point p2_) : p1(p1_), p2(p2_) {};
	Segment(long double p1x, long double p1y, long double p2x, long double p2y) : p1(Point(p1x, p1y)), p2(Point(p2x, p2y)) {};
	bool operator==(const Segment& s) const { return (p1 == s.p1 && p2 == s.p2) || (p1 == s.p2 && p2 == s.p1); }
	bool operator!=(const Segment& s) const { return !(Segment(p1, p2) == s); }
};
long double norm(const Point& a) { return a.px * a.px + a.py * a.py; }
long double abs(const Point& a) { return sqrtl(norm(a)); }
long double arg(const Point& a) { return atan2l(a.py, a.px); }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
long double dst(const Point& a, const Point& b) { return abs(b - a); }
long double dst(const Segment& a, const Point& b) { return dot(a.p2 - a.p1, b - a.p1) < 0.0 ? abs(b - a.p1) : (dot(a.p1 - a.p2, b - a.p2) < 0.0 ? abs(b - a.p2) : abs(crs(a.p2 - a.p1, b - a.p1) / abs(a.p2 - a.p1))); }
int n, q, r[109]; Point c[109], s, t;
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> c[i].px >> c[i].py >> r[i];
		}
		cin >> q;
		while(q--) {
			cin >> s.px >> s.py >> t.px >> t.py;
			bool flag = false;
			for (int i = 0; i < n; i++) {
				long double z1 = dst(s, c[i]), z2 = dst(t, c[i]);
				long double z3 = dst(Segment(s, t), c[i]);
				bool f1 = (z1 > r[i]), f2 = (z2 > r[i]);
				if (f1 != f2) flag = true;
				if (f1 && f2 && z3 <= r[i]) flag = true;
			}
			cout << (flag ? "Safe" : "Danger") << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
using namespace std;
struct Point{
	Point():x(0),y(0){}
	Point(int x,int y):x(x),y(y){}
	int x,y;
};
struct Circle{
	Point p;
	int r;
};
/* _a,b©ç£ÌñæðÔ·Ö */
int DistanceSquared( Point a, Point b ){
	return ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y );
}
/* ¾YASA éÇÌîñ©çA»êçÌÊuÖWªSafe©Danger©²×éÖ */
bool IsSafePlace( Circle c, Point taro, Point dem ){
	double vx1, vy1, vx2, vy2, alpha1, alpha2;
	int seki = ( (taro.x - c.p.x) * ( dem.x - taro.x ) + (taro.y - c.p.y) * (dem.y - taro.y ) );
	int D = seki * seki - DistanceSquared(taro,dem) * ( DistanceSquared(c.p,taro) - c.r * c.r );

	if( D < 0 )
		return false;

	alpha1 = ( -seki - sqrt((double)D) ) / DistanceSquared(taro, dem);
	alpha2 = ( -seki + sqrt((double)D) ) / DistanceSquared(taro, dem);

	vx1 = (taro.x - c.p.x) + alpha1 * ( dem.x - taro.x );
	vy1 = (taro.y - c.p.y) + alpha1 * ( dem.y - taro.y );
	vx2 = (taro.x - c.p.x) + alpha2 * ( dem.x - taro.x );
	vy2 = (taro.y - c.p.y) + alpha2 * ( dem.y - taro.y );

	if( taro.x == c.p.x && taro.y == c.p.y ){
		if( DistanceSquared( taro, dem ) > c.r * c.r )
			return true;
		else
			return false;
	}else if( ( ( vx1 * (taro.y - c.p.y) - vy1 * (taro.x - c.p.x) ) * ( vx1 * (dem.y  - c.p.y) - vy1 * (dem.x - c.p.x) ) > 0 ) &&
		( ( vx2 * (taro.y - c.p.y) - (taro.x - c.p.x) * vy2 ) * ( vx2 * (dem.y  - c.p.y) - (dem.x - c.p.x) * vy2 ) > 0 ) )
		return false;
	else
		return true;
}
int main(void){
	while(true){
		int n, m;
		vector<Circle> vWall;

		cin >> n;
		
		if( n == 0 )
			break;

		for(int i = 0; i < n; ++i){
			Circle tc;
			cin >> tc.p.x >> tc.p.y >> tc.r;
			vWall.push_back( tc );
		}

		cin >> m;

		for(int i = 0; i < m; ++i){
			bool safe = false;
			Point p_taro, p_daemon;
			cin >> p_taro.x >> p_taro.y >> p_daemon.x >> p_daemon.y;

			for( unsigned int j = 0; j < vWall.size(); ++j ){
				if( IsSafePlace( vWall[j], p_taro, p_daemon ) ){
					safe = true;
					cout << "Safe\n";
					break;
				}
			}
			if( !safe ){
				cout << "Danger\n";
			}
		}
	}
}