Search This Blog

Monday, 18 July 2016

HackerEarth- Intelligent Girl- Dynamic Programming

Intelligent Girl- HackerEarth- Dynamic Programming- Easy
Solution:-

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 10010
int arr[MAX];

int main()
{
    string s;
    cin>>s;
    int len=s.length();
    if((s[len-1]-'0')%2==0)
        arr[len-1]=1;
    else
        arr[len]=0;
    for(int i=len-2;i>=0;i--)
    {
        if((s[i]-'0')%2==0)
            arr[i]=arr[i+1]+1;
        else
            arr[i]=arr[i+1];
    }

    for(int i=0;i<len;i++)
        cout<<arr[i]<<" ";
    return 0;


}

No comments:

Post a Comment