Prasun the detective

Prasun, a wanna-be detective, has been assigned a case after his continuous failure at solving any. This is the murder 

of Snehashis who was killed last night. Prasun has already made some guesses on who could be the murderer and it seems that 
the two murderers are communicating via some strange arrangement of words. As prasun has been involved at solving cases of 
such fashion, he is making some guesses on what the message could probably be. Though he is pretty smart (:P), you have to 
help him by checking whether his guess is actually a possible one from the messages received.

Example:

Input:  s = "jogod #! siara.", t = "raja is good!"
Output: YES

Approach

C++

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

void theDetective(string s1string s2)
{

    int i = 0j = 0;
    vector<stringvv1;
    int n = s1.size(), m = s2.size();
    int f[26] = {0}, f1[26] = {0};
    for (int i = 0i < ni++)
    {
        if (s1[i] >= 'A' && s1[i] <= 'Z')
            s1[i] = s1[i] + 32;
        if (s1[i] >= 'a' && s1[i] <= 'z')
            f[s1[i] - 'a']++;
    }
    for (int i = 0i < mi++)
    {
        if (s2[i] >= 'A' && s2[i] <= 'Z')
            s2[i] = s2[i] + 32;
        if (s2[i] >= 'a' && s2[i] <= 'z')
            f[s2[i] - 'a']--;
    }
    sort(ff + 26);
    sort(f1f1 + 26);
    if (f[0] == 0 && f[25] == 0 && f1[0] == 0 && f1[25] == 0)
        cout << "YES\n";
    else
        cout << "NO\n";
}
int main()
{
    string s1 = "jogod #! siara."s2 = "raja is good!";

    theDetective(s1s2);

    return 0;
}


No comments:

Post a Comment