NBC005- Editorial

Practice
NOOB_CODING_2k20 Contest

Author: arpitaj_123
Tester: sourav472
Editorialist: sourav472

DIFFICULTY:

Easy.

PREREQUISITES:

ASCII Value Concept and Mathematics.

EXPLANATION:

First step is to check the first character of the given string. According to the first character you have to proceed.
i)If the first character of the string is “a” , then the value of each character of the string is like “a”=100, “b”=101, “c”=“102” ………“z”=125.
ii)If the first character of the string is “b” , then the value of each character of the string is like “a”=200, “b”=201, “c”=“202” ………“z”=225.
Lastly you have to calculate the “Wonder Sum” i.e. the sum of the value of each character in the string and take the output modulo (1e9+7).

SOLUTIONS:

Setter's Solution
 #include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio( false );cin.tie(NULL);
#define mod (1e9+7)
using namespace std;

int main() {
    ll t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    ll sum=0,a[26],p,i;
    for(i=0;i<26;i++){
        a[i]=100*(i+1)+i;
    }
    for(i=0;i<26;i++){
        if((s[0]-'a')==a[i]-100*(i+1)){
            p=100*(i+1);
            break;
        }
    }
    for(ll j=0;j<s.length();j++){
            sum=sum+p+(s[j]-'a');
             sum = sum%mod;
    }
    cout<<sum<<"\n";
    }
	return 0;
}
Tester's Solution
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ull unsigned long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define dfor(i,a,b) for(ll i=(a);i<(b);i++)
#define rfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define pii pair<ll,ll>
#define vi vector<ll>
#define vpii vector<pii>
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define fast ios_base::sync_with_stdio( false );cin.tie(NULL);
const ll mod = (ll)(1e9+7); 
using namespace std;
int main(){
fast
ll t;
cin>>t;
while(t--)
  {
      ll a[26],p;
      for(ll i=0;i<26;i++)
         a[i]=100 * (i+1);
      string s;
      cin>>s;
      p = a[s[0]-'a'];
      ll sum = p + (s[0]-'a');
      for(ll i=1;i<s.length();i++)
      {
          sum += (p+(s[i]-'a'));
          sum = sum%mod;
      }
      cout<<sum<<"\n";
      
  }

  	return 0;
}