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>
#include <utility>
using namespace std;

#define EPS 1e-8
#define sqr(x) ((x)*(x))
#define fi first
#define se second

class circle {
	public:
		int x, y, r;
		circle(int x, int y, int r) {
			this->x = x;
			this->y = y;
			this->r = r;
		}

		bool is_cross(int x1, int y1, int x2, int y2) {
			pair<int,int> range;
			int x0 = x, y0 = y;
			if(x1 == x2 && y1 == y2) {
				return false;
			}
			if(x1 == x2) {
				swap(x1, y1);
				swap(x2, y2);
				swap(x0, y0);
			}

			range.fi = min(x1, x2);
			range.se = max(x1, x2);

			double a, b;
			a = (double)(y2 - y1) / (x2 - x1);
			b = y1 - a * x1;

			double d;
			d = sqr(x0 - a * (b - y0)) - (1 + sqr(a)) * (sqr(x0) + sqr(b - y0) - sqr(r)) + EPS;

			if(d < 0)
				return false;

			double z, zz;
			z  = (x0 - a * (b - y0) - sqrt(d)) / (1 + sqr(a));
			zz = (x0 - a * (b - y0) + sqrt(d)) / (1 + sqr(a));

			if((range.fi <= z && z <= range.se) || (range.fi <= zz && zz <= range.se))
				return true;
			return false;
		}
};

int main(void) {
	int n, m;
	vector<circle> v;

	while(cin >> n, n) {
		for(int i = 0; i < n; i++) {
			int x, y, r;
			cin >> x >> y >> r;
			v.push_back(circle(x,y,r));
		}
		cin >> m;
		for(int i = 0; i < m; i++) {
			int x1, y1, x2, y2;
			bool flag = false;
			cin >> x1 >> y1 >> x2 >> y2;
			for(int j = 0; j < v.size(); j++) {
				if(v[j].is_cross(x1, y1, x2, y2))
					flag = true;
			}
			if(flag)
				cout << "Safe" << endl;
			else
				cout << "Danger" << endl;
		}
	}

	return 0;
}

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

complex<double> w[100];
int r[100];
complex<double> t,s;

bool inter(int a,double  x,double y){
  return sqrt( (w[a].real()-x)*(w[a].real()-x) + (w[a].imag()-y)*(w[a].imag()-y) ) <= r[a] + 1e-10;
}

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

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

double dis_s_p(complex<double> a,complex<double> b,complex<double> c){
  if( dot(b-a,c-a) < 1e-10 ) return abs(c-a);
  if( dot(a-b,c-b) < 1e-10 ) return abs(c-b);
  return abs( cross(b-a,c-a) ) / abs(b-a);
}

int main(){
  int n,m;

  while(1){
    cin >> n;
    if(!n)break;

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

    cin >> m;
    for(int i=0;i<m;i++){
      cin >> t.real() >> t.imag() >> s.real() >> s.imag();

      bool f = true;
      for(int j=0;j<n;j++){
	bool a = inter(j,t.real(),t.imag()),b = inter(j,s.real(),s.imag());
	if(a != b)f = false;
	else if(!a && !b){
	  if(dis_s_p(t,s,w[j]) <= r[j] + 1e-10)f = false;
	}
	if(!f)break;
      }

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool isecSP(P a1, P a2, P b) {
  return !ccw(a1, a2, b);
}
P proj(P a1, P a2, P p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}
D distSP(P a1, P a2, P p) {
  P r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}
D distSC(P a1, P a2, P c, D r) {
  D dSqr1 = norm(c-a1), dSqr2 = norm(c-a2);
  if (dSqr1 < r*r ^ dSqr2 < r*r) return 0;
  if (dSqr1 < r*r & dSqr2 < r*r) return r - sqrt(max(dSqr1, dSqr2));
  return max(distSP(a1, a2, c) - r, 0.0);
}
int n,m;
double x[111],y[111],ax,bx,ay,by,r[111];
int main(){
   while(cin>>n,n){
    rep(i,n)cin>>x[i]>>y[i]>>r[i];
    cin>>m;
    while(m--){
      int f=0;
      cin>>ax>>ay>>bx>>by;
      rep(i,n)if(!distSC(P(ax,ay),P(bx,by),P(x[i],y[i]),r[i]))f++;
      cout<<(f?"Safe":"Danger")<<endl;
    }
   }
}