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>
using namespace std;
const double EPS=1e-10;
double wx[100],wy[100],r[100],tx,ty,sx,sy;
int n,m;
main()
{
	while(cin>>n,n)
	{
		for(int i=0;i<n;i++)cin>>wx[i]>>wy[i]>>r[i];
		cin>>m;
		for(;m--;)
		{
			cin>>tx>>ty>>sx>>sy;
			bool ok=false;
			for(int i=0;i<n;i++)
			{
				if(hypot(wx[i]-sx,wy[i]-sy)<r[i]+EPS&&
					hypot(wx[i]-tx,wy[i]-ty)<r[i]+EPS)continue;
				double t=((wx[i]-sx)*(tx-sx)+(wy[i]-sy)*(ty-sy))/((tx-sx)*(tx-sx)+(ty-sy)*(ty-sy));
				if(t<0)t=0;
				if(t>1)t=1;
				double x=sx+t*(tx-sx),y=sy+t*(ty-sy);
				double dis=hypot(wx[i]-x,wy[i]-y);
				if(dis<r[i]+EPS)
				{
					ok=true;
					break;
				}
			}
			cout<<(ok?"Safe":"Danger")<<endl;
		}
	}
}

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));

			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;

	cin >> 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 <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
typedef pair<int,int> p;
int tx,ty,sx,sy;
double r,rx,ry;
bool cir(double x,double y){
	return (x-rx)*(x-rx)+(y-ry)*(y-ry)<r*r;
}
int main()
{
    int n,m;
	while(cin>>n&&n){
		pair<int,p> wall[100];//<r,<x,y>>
		for(int i=0;i<n;i++)cin>>wall[i].second.first>>wall[i].second.second>>wall[i].first;
		cin>>m;
		for(int i=0;i<m;i++){
			string ans="Danger";
			cin>>tx>>ty>>sx>>sy;
			double a,b,c;
			if(tx!=sx&&ty!=sy){
				a=(double)(ty-sy)/(tx-sx);
				b=(double)-1;
				c=ty-(double)a*tx;
			}else if(tx==sx){
				a=1;
				b=0;
				c=-tx;
			}else if(ty==sy){
				a=0;
				b=1;
				c=-ty;
			}
			double bo=sqrt(a*a+b*b);
			double d=(a*a+b*b)/(a*b);
			for(int j=0;j<n;j++){
				r=(double)wall[j].first;
				rx=(double)wall[j].second.first;
				ry=(double)wall[j].second.second;
				double shi=abs(a*rx+b*ry+c);
				double res=shi/bo;
				//printf("a:%.3f b:%.3f c:%.3f shi:%.3f bo:%.3f res:%.3f\n",a,b,c,shi,bo,res);
				if(r<res)continue;
				double px,py;//?????????????????????????????¨?????????
				if((a!=0)&&(b!=0)){
					px=(b/a*rx-ry-c/b)/d;
					py=-a/b*px-c/b;
				}else if(a!=0){//y????????????
					px=-c;
					py=ry;
				}else if(b!=0){//x????????????
					py=-c;
					px=rx;
				}
				if(cir((double)sx,(double)sy)&&cir((double)tx,(double)ty)){
					continue;
				}else if(cir((double)sx,(double)sy)!=cir((double)tx,(double)ty)||
					((double)min(sx,tx)<px&&px<(double)max(sx,tx))||((double)min(sy,ty)<py&&py<(double)max(sy,ty))){
					ans="Safe";
					break;
				}
			}
			cout<<ans<<endl;
		}
	}
    return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<algorithm>
const double EPS=1e-10;

typedef struct Vec{double x,y;}Vec;
typedef struct Cer{double r;Vec cp;}Cer;

double dot(Vec a,Vec b){return a.x*b.x+a.y*b.y;}
double det(Vec a,Vec b){return a.x*b.y-a.y*b.x;}
double D(Vec a){return hypot(a.x,a.y);}
Vec F(Vec a,Vec b){Vec p={a.x-b.x,a.y-b.y};return p;}

double ch(Vec a,Vec b,Vec c)
{
	if(dot(F(b,a),F(c,a))<EPS)return D(F(b,a));
	if(dot(F(a,b),F(c,b))<EPS)return D(F(c,b));
	return fabs(det(F(b,a),F(c,a)))/D(F(b,a));
}

int N,M,i,j,f;
double m,d;
Cer W[100];

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<N;i++)
			scanf("%lf%lf%lf",&W[i].cp.x,&W[i].cp.y,&W[i].r);
		scanf("%d",&M);
		for(i=0;i<M;i++)
		{
			f=0;
			Vec t,s;
			scanf("%lf%lf%lf%lf",&t.x,&t.y,&s.x,&s.y);
			for(j=0;j<N;j++)
			{
				if(D(F(s,W[j].cp))<=W[j].r&&D(F(t,W[j].cp))<=W[j].r)continue;
				if(ch(t,s,W[j].cp)<=W[j].r)break;
			}
			puts(j==N?"Danger":"Safe");
		}
	}
	return 0;
}