PREGLO-EDITORIAL

PROBLEM LINK:

Practice
Contest:Hey Newbees, Here is Some Honey, round 1

Author: Arefin Labib
Tester: Samia Rahman
Tester: Nazmus Sakib Rhythm

DIFFICULTY:

Easy

PREREQUISITES:

String, Math

PROBLEM:

Given a line of string, You have to define the roll number of the student who shouted with that string. Suppose the student with roll no. 1 will say aoreee gelooo similarly zaoreee gelooo will be said by roll no. 26 and next student of him will say aaoreee gelooo. 52nd student will say azoreee gelooo and next student will say baoreee gelooo.

QUICK EXPLANATION:

There are two string, second one is absolutely unnecessary. Last 5 character of the first string is also unnecessay. Take the remaining characters. Then take the value of the characters in lexicographical order as a=1, b=2, c=3. Suppose for abcoreee gelooo, take abc and it is 123 and it is a 26 based number. Convert it to 10 based number and it is the answer.

EXPLANATION:

Students will remove first character from the first word of “Poreee gelooo” and
replace with one or more character into it. “gelooo” have no use here. So take the
word “poreee” in a string and reverse it ( example: poreee will be reversed to
eeerop). Now skip first 5 character “eeero” and start from the 6th. Just type cast each characters to its integer value as a=1, b=2,… and multiply the value with the power of 26. For the first character(6th in the reversed word), you should multiply with 26^0 and for the second character(7th in the reversed word), it will be 26^1 and so on.

Why power of 26? Think of a decimal number, suppose it is 237. How it is
represented with its positional value? Simply 2x(10^2 )+ 3*(10^1) + 7*(10^0) = 237. 237 is a 10-based number so we used power of 10. But there are 26 character from a to z. So we used the power of 26.

Let’s clear with an example, for abcoreee gelooo. reverse abcoreee and you will
find eeerocba. Now skip eeero and get cba. Now c=3, b=2, a=1. So it will be, 326^0+ 226^1 + 1*26^2 is the answer.

Time complexity: O(n)

SOLUTIONS:

Setter's Solution
//BISMILLAHIR RAHMANIR RAHIM
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t>0)
    {
        string s,a;
        long long int i,sum=0,c=0;
        double x=0;
        cin>>s>>a;
        reverse(s.begin(),s.end());
        for(i=5; i<s.size(); i++)
        {
            x+=((int)s[i]-96)*(pow(26,c));
            c++;
        }
        sum=(long long int)x;
        cout<<sum<<endl;
        t--;
    }

    return 0;
}
1 Like