Time spent here:

Tuesday, 12 April 2016

PAINT THE TILES(HOUR RANK 7)

PROBLEM STATEMENT:
Nikita has a line of NN tiles indexed from 00 to N−1N−1. She wants to paint them to match a color configuration, CC, which is comprised of 22 colors: Red(R)Red(R) and Blue(B)Blue(B).

In one stroke, Nikita can paint 11 or more adjacent tiles a single color. After she finishes painting, each tile ii should be painted color CiCi.

It should be noted that it is not allowed to apply more than 11 stroke on a tile.

Given the required color configuration, find and print the minimum number of strokes required for Nikita to paint all NN tiles.

Note: In a line of tiles, 22 tiles with the indices ii and jj are considered adjacent only if |j−i|=1|j−i|=1.

Input Format

The first line contains a single integer, NN, denoting the number of tiles to be painted.
The second line contains a string, CC, denoting the desired color configuration.

For each character CiCi in CC:

    If Ci="R"Ci="R", it means the ithith tile must be painted red.
    If Ci="B"Ci="B", it means the ithith tile must be painted blue.

Constraints

    1≤N≤10001≤N≤1000
    Ci∈{"R", "B"}Ci∈{"R", "B"}

Output Format

Print the minimum number of strokes required to paint all NN tiles in the desired color configuration.

CODE:
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int n;
    scanf("%d",&n);
    char* c = (char *)malloc(10240 * sizeof(char));
    scanf("%s",c);
    int i,count=0;
    for(i=0;c[i];i++)
    {
        if(c[i]!= c[i+1])
            count=count+1;
    }   
    printf("%d",count);
    return 0;
}
OUTPUT:

No comments:

Post a Comment