Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), ":")
		h, _ := strconv.Atoi(input[0])
		m, _ := strconv.Atoi(input[1])
		H, M := (30*h+(m/2))*2, (6*m)*2
		if m&1 == 1 {
			H++
		}
		a := H - M
		if a < 0 {
			a = -a
		}
		a2 := 720 - a
		if a2 < a {
			a = a2
		}
		if a < 60 {
			fmt.Println("alert")
		} else if a >= 180 && a <= 360 {
			fmt.Println("safe")
		} else {
			fmt.Println("warning")
		}
	}
}

C++: #include <iostream>
#include <cmath>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		int h, m;
		char c;
		cin >> h >> c >> m;
		double hour_hand = h * 30.0 + m / 2.0;
		double minute_hand = m * 6.0;
		double min_diff = min(fabs(hour_hand - minute_hand), 360 - fabs(hour_hand - minute_hand));
		if(min_diff < 30)
		{
			cout << "alert" << endl;
		}
		else if(min_diff < 90)
		{
			cout << "warning" << endl;
		}
		else
		{
			cout << "safe" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;

int main(){
    int n;
    scanf("%d\n",&n);
    for(int ix=0;ix<n;ix++){
        int h,m;
        scanf("%d:%d\n",&h,&m);
        int tan=(60*h+m)%720,tyo=(12*m)%720,dist=min(abs(tan-tyo),720-abs(tan-tyo));
        if(dist<60) printf("alert\n");
        else if(180<=dist) printf("safe\n");
        else printf("warning\n");
    }
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n; cin >> n;
    rep(i,n){
        int h,m;
        scanf("%d:%d",&h,&m);
        h=h*60+m;
        m*=720/60;
        int dt=min(abs(h-m),60*12-abs(h-m));
        // cout << dt << endl;
        string ans;
        if(dt<60*1) ans = "alert";
        else if(dt>=60*3) ans = "safe";
        else ans = "warning";
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <math.h>
int main(){
	//Input
	int N;
	std::cin >> N;

	int H, M;
	while(N--){
		scanf("%d:%d",&H,&M);
		//Processing
		//ツ角ツ度ツづーツ仰づ淞づゥ
		double aH = (60 * H + M) / 2, aM = 6 * M, a;
		//std::cout << aH << "," << aM << std::endl;
		a = std::min(fabs(aH-aM), 360-fabs(aH-aM));

		//ツ甘ォツ個ッツつウツづーツ板サツ津ィ
		std::string res;
		if(a >= 0 && a < 30){
			res = "alert";
		}
		else if(a >= 90 && a <= 180){
			res = "safe";
		}
		else{
			res = "warning";
		}

		std::cout << res << std::endl;
	}
}

C++: #include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void)
{
	int n;
	cin >> n;

	long double h, m;
	while (n--){
		scanf("%Lf:%Lf", &h, &m);
		long double hh = 360 * (h / 12);
		long double mm = 360 * (m / 60);
		long double diff = abs(hh - mm + 1);
		// cout << diff << endl;
		if (0 <= diff && diff < 30){
			cout << "alert" << endl;
		}
		else if (90 <= diff && diff <= 180){
			cout << "safe" << endl;
		}
		else {
			cout << "warning" << endl;
		}
	}

	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    rep(_,n){
        char a,b,g,c,d; cin>>a>>b>>g>>c>>d;
        double h=(a-'0')*10+(b-'0');
        double m=(c-'0')*10+(d-'0');
        double hoge=h*30;
        h=m/2.0+hoge;
        m*=6;
        double cal=min((ld)abs((ld)h-(ld)m),(ld)360-(ld)abs((ld)h-(ld)m));
        if(cal<=30)cout<<"alert"<<endl;
        else if(cal<=180)cout<<"safe"<<endl;
        else cout<<"warning"<<endl;
    }
}

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

string func(int s, int l){
	double h = s*30.0 + l/2.0, m = l*6;
     
    int ang = abs(h - m);
    if(ang > 180) ang = 360 - ang;
    if(0 <= ang && ang < 30) {
      return "alert";
    }
    else if(90 <= ang && ang <= 180) {
      return "safe";
    }
    else return "warning";
}
 
int main() {
	int n, s, l; cin >> n;
	while(n--) {
		cin >> s >> c >> l;
		cout << func(s, l) << endl;
	}
  	return 0;
}

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

int main(){
  int n,h,m;
  string s;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> s;
    int st = s[0] == '0'?1:0;
    h = (atoi)(s.substr(st,s[0]=='0'?1:2).c_str());
    st = s[3] == '0'?4:3;
    m = (atoi)(s.substr(st,s[3]=='0'?1:2).c_str());
    h *= 30;
    m*=6;
    cout << h << " " << m << endl;
    if(0<= abs(h-m)&& abs(h-m) <= 30)cout << "alert" << endl;
    else if(90 <= abs(h-m) && abs(h-m) <= 180)cout << "safe" << endl;
    else cout << "warning" << endl;  


  }

  return 0;
}

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

#define DEBUG(x) // cerr << #x << " = " << x << endl

const long double EPS = 1e-8;

long double deg_long(int hh, int mm) {
    hh %= 12;
    long double deg = (1.0 * 360) * hh / 12;
    deg += (1.0 * 360 / 12) * mm / 60;
    return deg;
}

long double deg_short(int mm) {
    return 1.0 * 360 * mm / 60;
}

int main() {
    int N; scanf("%d", &N);
    while(N--) {
        int hh, mm; scanf("%d:%d", &hh, &mm);
        long double diff = abs(deg_long(hh, mm) - deg_short(mm));
        DEBUG(diff);
        if (diff < 30 - EPS) puts("alert");
        else if(90 - EPS < diff) puts("safe");
        else puts("warning");
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
  int T;
  cin>>T;
  while(T--){
  int h,m;
  scanf("%d:%d",&h,&m);
  double A=360*(h/12.0)+30*(m/60.0);
  double B=360*(m/60.0);
  

  double r=min(abs(A-B),360-abs(A-B));
  
  if(r<30)cout<<"alert"<<endl;
  else if(r<90)cout<<"warning"<<endl;
  else cout<<"safe"<<endl;
  
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n,h,m;
int a,b,c,d;
char ch;
int main(){
  cin>>n;
  while(n--){
    cin>>h>>ch>>m;
    if(h>=12)h-=12;
    a=h*30+(m/12)*6;
    b=m*6;
    
   
    c=max(a,b)-min(a,b);
    if(c>180)c=180-(c-180);

    //cout << a<< ' '<<b<<' '<<c<<endl;
    
    if(0<=c&&c<30){
      cout<<"alert"<<endl;
    }else if(90<=c&&c<=180){
      cout<<"safe"<<endl;
    }else{
      cout<<"warning"<<endl;
    }
     
  }
  return 0;
}