## Left and Right Handed

Time limit: 2000 ms

Memory limit: 65536 KB

### Description

Some students are seated in a row next to each other. Each of them is either left-handed or right-handed. The students are trying to write down lecture notes. Whenever a left-handed person sits immediately to the right of a right-handed person, their elbows collide when they both try to write at the same time. Compute and return the number of elbow collisions, assuming that all students in the row attempt to write at the same time.

### Input Format

First line contains an integer N (1 <= N <= 50), the number of students. The next line contains of N characters, each character of S is either ‘L’ or ‘R’, representing a left-handed or a right-handed person, respectively. The characters describe the row from the left to the right: for all i, the person described by character i+1 sits to the right of the person described by character i.

### Output Format

An integer, the number of collisions.

```1
L```

`0`

### Note

There’s only one person in the row so there are no collisions.

```3
RRR```

`0`

### Note

Everybody is right-handed so there are no collisions.

```6
LRLRLR```

`2`

### Note

There will be two collisions: one of them between the second and the third person from the left (described by S and S) and the other between the fourth and the fifth person.

```6
LLLRRR```

`0`

```6
RLRLRL```

`3`

## SOLUTION

```#include
#include

int main()
{
int N,i,counter = 0;
scanf("%d",&N);
if(N>=1 && N <=50){
char temp[N];
scanf("%s",&temp);
for(i=0;i<N-1;i++){
if(temp[i]!=temp[i+1]&&(temp[i] == 'R'||temp[i] == 'r')){
counter++;
}
}
printf("%d\n",counter);
}
return 0;
}```
Programming Problem Set #Left and Right Handed

This site uses Akismet to reduce spam. Learn how your comment data is processed.