
/* 
 * File:   main.c
 * Author: hdblo
 *
 * Created on 26 de Maio de 2019, 12:08
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int strpos(char s[], char p[]);

int main(int argc, char** argv) {

    int a = 0;
    char linha[34];
    char csplit[1] = ";";

    while (a == 0) {

        char* g = fgets(linha, sizeof (linha), stdin);

        if (linha[0] == '0' && strlen(linha) == 2) {
            a = 1;
            break;
        }

        int p = strpos(linha, csplit);
        int t = strlen(linha);

        char temp1[p + 1];
        char temp2[t - p - 1];

        // Limpar vetores
        
        char latg[5] = "";
        char latm[4] = "";
        char lats[7] = "";
        int cont = 0;
        int x = 0;
        for (x = 0; x < p; x++) {
            temp1[x] = linha[x];
        }

        temp1[x] = '\0';

//        printf(temp1);
        
        t = strlen(temp1);
        int i = 0;

        for (x = 0; x < t; x++) {
            if (cont == 0) {
                if (temp1[x] == ' ' || x == t - 1) {
                    if (x == t - 1) {
                        latg[i] = temp1[x];
                        latg[i + 1] = '\0';
                    }
                    cont++;
                    i = 0;
                } else {
                    latg[i] = temp1[x];
                    i++;
                }
            } else if (cont == 1) {
                if (temp1[x] == ' ' || x == t - 1) {
                    if (x == t - 1) {
                        latm[i] = temp1[x];
                        latm[i + 1] = '\0';
                    }
                    cont++;
                    i = 0;
                } else {
                    latm[i] = temp1[x];
                    i++;
                }
            } else {
                lats[i] = temp1[x];
                i++;
            }
        }

        lats[i] = '\0';

//        printf("%s %s %s\n",latg,latm,lats);
        
        char latgc[4] = "";
        char latmc[3] = "";
        char latsc[6] = "";

        strncpy(latgc, latg, strlen(latg));
        strncpy(latmc, latm, strlen(latm));
        strncpy(latsc, lats, strlen(lats));

//        printf("%s %s %s\n",latgc,latmc,latsc);
        
        latgc[3] = '\0';
        latmc[2] = '\0';
        latsc[5] = '\0';

        double latitude = atof(latgc) + atof(latmc) / 60 + atof(latsc) / 36000;

//        printf("%f\n",latitude);
        
        char longg[6] = "";
        char longm[4] = "";
        char longs[7] = "";
        cont = 0;

        t = strlen(linha);

        for (int x = p; x < t - 1; x++) {
            temp2[x - p] = linha[x + 1];
        }

        temp2[sizeof (temp2)] = '\0';

        t = strlen(temp2);
        i = 0;

        for (int x = 0; x < t; x++) {
            if (cont == 0) {
                if (temp2[x] == ' ' || x == t - 1) {
                    if (x == t - 1) {
                        longg[i] = temp2[x];
                        longg[i + 1] = '\0';
                    }
                    cont++;
                    i = 0;
                } else {
                    longg[i] = temp2[x];
                    i++;
                }
            } else if (cont == 1) {
                if (temp2[x] == ' ' || x == t - 1) {
                    if (x == t - 1) {
                        longm[i] = temp2[x];
                        longm[i + 1] = '\0';
                    }
                    cont++;
                    i = 0;
                } else {
                    longm[i] = temp2[x];
                    i++;
                }
            } else {
                longs[i] = temp2[x];
                i++;
            }
        }

        longs[sizeof (longs) - 1] = '\0';

        char longgc[5] = "";
        char longmc[3] = "";
        char longsc[6] = "";

        strncpy(longgc, longg, strlen (longg));
        strncpy(longmc, longm, strlen (longm));
        strncpy(longsc, longs, strlen (longs));

        longgc[4] = '\0';
        longmc[2] = '\0';
        longsc[5] = '\0';

        double longitude = atof(longgc) + atof(longmc) / 60 + atof(longsc) / 36000;

        if (latitude < 0) {
            printf("Sul ");
        } else if (latitude == 0) {
            printf("Equador ");
        } else {
            printf("Norte ");
        }

        if (longitude < 0) {
            printf("Oeste\n");
        } else if (longitude == 0) {
            printf("Greenwich\n");
        } else {
            printf("Leste\n");
        }
    }
    return (EXIT_SUCCESS);
}

int strpos(char s[], char p[]) {
    for (int x = 0; x <= strlen(s); x++) {
        if (s[x] == p[0]) {
            return x;
        }
    }
    return -1;
}