In this HackerEarth The Upload Server problem solution A new website to host video and music is built up by the company X. The engineers at X are facing a major issue in identifying whether the data they receive in one of their API is of video or music.

Now, you will be given N lines of data. Each line of data consists of a list of strings. Each string either represents an integer or a name. For each line of data, you need to check whether that data corresponds to music or a video.

You need to follow the following rules to detect the data and store it:
  1. A Music data consists of a name and an integer that denote the bitrate and nothing else.
  2. Video data consists of a name and two integers that denote the resolution of the video and nothing else.
  3. The rest of the data which does not match any of the formats above is to be ignored.
  4. Music or a video name can consist of integers but it will contain at least one character of the English alphabet.
  5. An integer in the data will consist only of integers, and it will never start with 0.
For each line of data, if it satisfies the constraints of music then print M, if it satisfies constraints of a video print V, or else print N which means that the data has to be ignored.


HackerEarth The Upload Server problem solution


HackerEarth The Upload Server problem solution.

#include<bits/stdc++.h>
#define LL long long int
#define M 1000000007
#define endl "\n"
#define eps 0.00000001
LL pow(LL a,LL b,LL m){LL x=1,y=a;while(b > 0){if(b%2 == 1){x=(x*y);if(x>m) x%=m;}y = (y*y);if(y>m) y%=m;b /= 2;}return x%m;}
LL gcd(LL a,LL b){if(b==0) return a; else return gcd(b,a%b);}
LL gen(LL start,LL end){LL diff = end-start;LL temp = rand()%start;return temp+diff;}
using namespace std;
vector<string> lines[100001];
set<string> music , video;
set<int> bitrate;
set<pair<int,int> > res_video;
bool check_integer(string s){
    if(s[0] == '0'){
        return 0;
    }
    for(int i = 0; i < s.length(); i++){
        if(!(s[i] >= '0' && s[i] <= '9')){
            return 0;
        }
    }
    return 1;
}

bool check_string(string s){
    for(int i = 0; i < s.length(); i++){
        if(s[i] >= 'a' && s[i] <= 'z'){
            return 1;
        }
    }
    return 0;
}

void process_data(string a,string b,string c){
    if(check_string(a) == 1){
        if(check_integer(b) == 1 && check_integer(c) == 1){
            cout << "V" << endl;
            return;
        }
    }
    if(check_string(b) == 1){
        if(check_integer(a) == 1 && check_integer(c) == 1){
            cout << "V" << endl;
            return;
        }
    }
    if(check_string(c) == 1){
        if(check_integer(b) == 1 && check_integer(a) == 1){
            cout << "V" << endl;
            return;
        }
    }
    cout << "N" << endl;
}

void process_data(string a, string b){
    if(check_integer(a) == 1){
        if(check_string(b) == 1){
            cout << "M" << endl;
            return;
        }
    }
    if(check_integer(b) == 1){
        if(check_string(a) == 1){
            cout << "M" << endl;
            return;
        }
    }
    cout << "N" << endl;
    
}

int main()
    {
        //ios_base::sync_with_stdio(0);
        int n;
        cin >> n;
        char ch = getchar();
        for(int i = 1; i <= n; i++){
            string temp;
            string temp2;
            getline(cin , temp2);
            for(int j = 0; j < temp2.size(); j++){
                if(temp2[j] == ' '){
                    lines[i].push_back(temp);
                    temp.clear();
                }
                else{
                    temp.push_back(temp2[j]);
                }
            }
            lines[i].push_back(temp);
        }
        for(int i = 1; i <= n; i++){
            if(lines[i].size() == 3){
                process_data(lines[i][0] , lines[i][1] , lines[i][2]);
            }
            else if(lines[i].size() == 2){
                process_data(lines[i][0] , lines[i][1]);
            }
        }
    }


Second solution

N = input()
for _ in range(N):
    A = map(str, raw_input().split())
    n = len(A)
    wrd = 0 ; num = 0 
    for i in A:
        flag = False
        for j in i:
            if(j.isalpha()):
                flag = True
                break
        if(flag == True):
            wrd += 1
        elif(i[0] != '0'):
            num += 1
    if(n == 2 and wrd == 1 and num == 1):
        print 'M'
    elif(n == 3 and wrd == 1 and num == 2):
        print 'V'
    else:
        print 'N'