Type the Question

Monday, February 25, 2019

Question Name:INTELLIGENT GIRL

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main()
{
    string s;
    cin>>s;
    ll l=s.length();
    ll a[l],k=0;
    for(ll i=(l-1);i>=0;i--)
    {
        if(s[i]%2==0)
        {
            k+=1;
            a[i]=k;
        }
        else
        {
            a[i]=k;
        }
    }
    for(ll i=0;i<l;i++)
    {
       cout<<a[i]<<" "; 
    }
    
    return 0;
}
  • Problem Description
    Soumika has a string S and its starting index is 1. The string S consists of characters from 19. As she is very intelligent, she wants to test his brother Vinay Tendulkar.

    She asked her brother Vinay Tendulkar to count the number of even numbered characters ( i.e 2,4,6,8 ) for every index
    (1<=i<=|S|). For an index i, the result should be calculated from i to the end of the string. As Vinay doesn’t know about programming, he wants you to help him find the solution.

    Input:
    First line contains a string S.

    Output:
    Print |S| space-separated integers,the result of every index.

    Constraints:

    1<= |S| <= 10^4
  • Test Case 1
    Input (stdin)574674546
    Expected Output5 5 5 4 3 3 2 2 1
  • Test Case 2
    Input (stdin)54566987543
    Expected Output5 5 4 4 3 2 2 1 1 1 0

No comments:

Post a Comment

Question Name:TOWER OF HANOI

#include < bits / stdc ++. h > #define lli long long using namespace std ; lli dp [ 202 ]; int main () { int t , n ; ...