Problem:


Score : 300 points

Problem Statement

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

Ultimately, how many slimes will be there?

Constraints

1 \leq N \leq 10^5

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the final number of slimes.

Sample Input 1

10
aabbbbaaca

Sample Output 1

5

Ultimately, these slimes will fuse into abaca.

Sample Input 2

5
aaaaa

Sample Output 2

1

All the slimes will fuse into one.

Sample Input 3

20
xxzaffeeeeddfkkkkllq

Sample Output 3

10



Sample input:
10
aabbbbaaca


Sample output:
5

Submission status: Accepted

Solution code:
# abc143_c.py
# https://atcoder.jp/contests/abc143/tasks/abc143_c

# C - Slimes /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# N匹のスライムが横一列に並んでいます。
# これらの色に関する情報が、長さ N の英小文字から成る文字列 S で与えられます。
# 左から i 番目のスライムは、 S の i文字目に対応する色を持っています。
# 同じ色を持ち隣接するスライムは融合し、色は変わらずに 1
# 匹のスライムとなります。このとき、融合した後のスライムは、融合する前の各スライムが隣接していた他のスライムと隣接した状態になります。
# 最終的に存在するスライムは何匹となるでしょうか。

# 制約
#     1≤N≤105
#     |S|=N
#     Sは英小文字から成る

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# S

# 出力
# 最終的に存在するスライムの数を出力せよ。

# 入力例 1
# 10
# aabbbbaaca

# 出力例 1
# 5

# 最終的に残るスライムを文字列で表すと、abacaとなります。

# 入力例 2
# 5
# aaaaa

# 出力例 2
# 1

# 全てのスライムが融合します。

# 入力例 3
# 20
# xxzaffeeeeddfkkkkllq

# 出力例 3
# 10


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    S = lines[1]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    prev = ''
    cnt = 0

    for char in S:
        if prev != char:
            cnt += 1
            prev = char

    return [cnt]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['10', 'aabbbbaaca']
        lines_export = [5]
    if pattern == 2:
        lines_input = ['5', 'aaaaa']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['20', 'xxzaffeeeeddfkkkkllq']
        lines_export = [10]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()

for i in range(N - 1):
    if S[i] == S[i + 1]:
        S = S[:i] + '_' + S[i + 1:]

print(len(S.replace('_', '')))

Submission status: Accepted

Solution code:
n = input()
s = input()

slime = s[0]
for index in range(1,len(s)):
  if s[index] != s[index-1]:
    slime += s[index]
print(len(slime))

Submission status: Accepted

Solution code:
n=int(input());s=input();print(1+sum([s[i-1]!=s[i] for i in range(1,n)]))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
K=S
i=0
han=S[0]
kot=S[0]

for b in K:
    if b != han:
        kot+=b
        han=b



print(len(kot))

Submission status: Accepted

Solution code:
from itertools import groupby
n=int(input())
s=input()
print(len(list(groupby(s))))

Submission status: Accepted

Solution code:
input()
cnt = 0
x = ""
for s in input():
    if x != s:
        cnt += 1
        x = s
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
S = input()
count=1
for i in range(N-1):
    if S[i] != S[i+1]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
print(1 + sum(s[i] != s[i + 1] for i in range(n - 1)))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

ans = 1
for i, s in enumerate(S):
  if i == N-1:
    break
  if s == S[i+1]:
    continue
  else:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
s = input()

ans = 1
last = s[0]
for i in range(1,n):
    if last != s[i]:
        last = s[i]
        ans = ans + 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()

bef=s[0]
ans=1
for i in s[1:]:
  if i !=bef:
    ans+=1
    bef=i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
S.append("test")
i = 0
while N > 0:
    if S[i] == S[i+1]:
        S.pop(i)
        i = i - 1
    i = i + 1
    N = N - 1
print(len(S)-1)

Submission status: Accepted

Solution code:
from itertools import groupby
N = int(input())
S = input()
g = groupby(S)
print(len(list(g)))

Submission status: Accepted

Solution code:
# cook your dish here
import sys
def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w') 

def main(N, arr):

	#initialising with positive infinity value
	maxi=float("inf")

	#initialising the answer variable
	ans=0

	#iterating linesrly
	for i in range(N):

		#finding minimum at each step
	    maxi=min(maxi,arr[i])
	    #increasing the final ans
	    ans+=maxi
	    print("dhh")

    #returning the answer
	return ans
        
#file()	
if __name__ == '__main__':

	#length of the array
	'''N = 4

	#Maximum size of each individual bucket
	Arr = [4,3,2,1]

	#passing the values to the main function
	answer = main(N,Arr)

	#printing the result
	print(answer)'''
	n=int(input())
	s=input()

	#l=list(map(int, input().split()))
	ans=0
	for i in range(1,n):
		if(s[i]!=s[i-1]):
			ans+=1
	print(ans+1)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
l=[]
for i in range(0,len(s)):
    if(len(l)==0):
        l.append(s[i])
    elif(l[len(l)-1]!=s[i]):
        l.append(s[i])
    else:
        pass
print(len(l))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

ans = 0
pre = ''
for i in range(N):
    if pre != S[i:i+1]: ans += 1
    pre = S[i:i+1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
n = 1
for i in range(1,N):
    if S[i] == S[i-1]:
        pass
    else:
        n += 1
print(n)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=1
for x in range(N-1):
  if S[x]!=S[x+1]:
    ans +=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

s = s + '@'
prev = s[0]
ans = 0
for i in range(1, n + 1):
    if s[i] != prev:
        ans += 1
    prev = s[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

for i in range(n-1):
    if s[i] == s[i+1]:
        n -= 1

print(n)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    S = input()
    ans = 0
    prev = ""
    for c in S:
        if c == prev:
            continue
        ans += 1
        prev = c
    print(ans)

    
if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt=0
for i in range(n-1):
    if s[i]==s[i+1]:
        cnt+=1
print(n-cnt)

Submission status: Accepted

Solution code:
N=int(input())
S=input()

new = S[0]
for i in range(1,N):
  if S[i]!=S[i-1]:new = new + S[i]
print(len(new))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
fus = 0
for i in range(N - 1):
    if S[i] == S[i+1]:
        fus += 1
print(N - fus)

Submission status: Accepted

Solution code:
n = int(input())

k = input()

final = 0
for i in range(0, n - 1):
    if k[i] != k[i + 1]:
        final += 1
        
print(final + 1)

Submission status: Accepted

Solution code:
n = int(input())
st = input()

ans = 1
for i in range(n-1):
    if st[i] != st[i+1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

ans = 1
for i in range(N-1):
    if S[i]!=S[i+1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
print(sum(S[i]!=S[i+1] for i in range(N-1))+1)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    S = input()
    nw = S[0]
    ret = 1
    for i in range(1,N):
        if nw == S[i]:
            continue
        else:
            nw = S[i]
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
judge=''
for i in range(n):
    if s[i]==judge:
        n-=1
    judge=s[i]

print(n)

Submission status: Accepted

Solution code:
from itertools import groupby
n = int(input())
s = input()
g = groupby(s)
print(len(list(g)))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())

ans = 1
temp = s[0]

for i in range(1,n):
    if temp != s[i]:
        ans += 1
        temp = s[i]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
A = []
x = 0

for i in range(N):
    A.append(S[i])

for i in range(N):
    if i != N - 1:
        if A[i + 1] == A[i]:
            x += 1

print(len(A) - x)

Submission status: Accepted

Solution code:
n=int(input())
s=input()+'*'
ans=0
for i in range(n):
    if s[i]!=s[i+1]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
res=1
for i in range(1,len(s)):
    if s[i-1]!=s[i] :
        res+=1
print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = n
for i in range(1, n):
    if s[i] == s[i-1]:
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(input())
cnt = 1
for i in range(n - 1):
    if a[i] != a[i + 1]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def resolve():
    
    N=int(input())
    S=list((input()))
    ans=S[0]

    for i in range(N-1):
        if(S[i]!=S[i+1]):
            ans+=S[i+1]

    print(len(ans))        


resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n=int(input())
s=input().rstrip()
ans = 1
for i in range(n-1):
    if s[i]!=s[i+1]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n):
    if s[i]!=s[i-1]:
        ans+=1
print(ans+1)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  S = input()[:-1]

  pre = S[0]
  cnt = 1
  for i in range(1, N):
    if pre == S[i]:
      pre = S[i]
      continue
    cnt += 1
    pre = S[i]
  print(cnt)


if(__name__ == '__main__'):
  main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()

ans = 1
for i in range(1, n):
  if s[i] != s[i - 1]:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())

ans = ""
ans += S[0]

for i in range(N-1):
  if S[i] != S[i+1]:
    ans += S[i+1]
print(len(ans))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
a=[]
for i in range(n):
    if i==n-1:
        a.append(s[i])
        continue
    if s[i]!=s[i+1]:
        a.append(s[i])
print(len(a))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
i = 0
while i < len(s)-1:
    if s[i] == s[i+1]:
        s = s[:i] + s[i+1:]
        i -= 1
    i += 1
print(len(s))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
res=[S[0]]
for i in range(N-1):
  if(S[i]!=S[i+1]):
    res.append(S[i+1])
print(len(res))

Submission status: Accepted

Solution code:
N = int(input())
S = list(''.join(input()))

t = 1
for i in range(N-1):
    if S[i]!=S[i+1]:
        t += 1
print(t)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

N = int(readline())
S = readline().rstrip()

ans = 1
for i in range(1,len(S)):
  if S[i] != S[i - 1]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans=0
for i in range(1,N):
    if S[i]!=S[i-1]:
        ans+=1
print(ans+1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
num = 1
for i in range(N - 1):
    if S[i] != S[i + 1]:
        num += 1
print(num)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
fusion =[]
tmp = s[0]
fusion.append(tmp)
for i in s[1:]:
    if i != tmp:
        tmp = i
        fusion.append(i)
print(len(fusion))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())

while(True):
    count = 0
    for i in range(len(S) - 1, 0, -1):
        if S[i] == S[i-1]:
            S.pop(i)
            count += 1
    if count == 0: break
print(len(S))

Submission status: Accepted

Solution code:
import itertools
a=int(input())
b=input()

list2 = [k for k, v in itertools.groupby(b)]
print(len(list2))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n):
  if s[i] != s[i-1]:
    ans += 1
print(ans+1)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
last = S[0]
cnt = 1
for s in S[1:]:
  if last != s:
    cnt+=1
    last = s
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=input()

count=1
for i in range(n-1):
    if(s[i]==s[i+1]):
        continue
    else:
        count+=1 
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

cnt = 1
last = S[0]
for s in S:
    if last == s:
        continue
    else:
        cnt += 1
        last = s
print(cnt)

Submission status: Accepted

Solution code:
import sys

# import bisect
# import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
# import heapq
import bisect
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N =int(input())
    S = input()
    pre ="A"
    count=0
    for i in S:
        if i !=pre:
            count+=1
        pre = i
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()

c_curr = ""
ans = 0
for c in s:
    if c != c_curr:
        ans += 1
        c_curr = c
print(ans)

Submission status: Accepted

Solution code:
import re

N = int(input())
S = input()

result = ''

for i in range(len(S)):
    if i == len(S) - 1:
        result += S[i]
    elif S[i] != S[i+1]:
        result += S[i]

print(len(result))

Submission status: Accepted

Solution code:
from sys import stdin,stdout

if __name__=="__main__":

    n=int(stdin.readline())

    s=str(input())

    l=s[0]
    cnt=1

    for i in range(1,len(s)):
        if(s[i]!=l):
            cnt+=1
            l=s[i]

    stdout.write(str(cnt)+"\n")

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, S):
    fusioned = S[0]
    for s in S:
        if fusioned[-1] != s:
            fusioned += s
    print(len(fusioned))


if __name__ == '__main__':
    N = int(input())
    S = input()
    solve(N, S)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

n = k()
a = s()
for i in range(n-1):
    if a[i] != a[i+1]:
        count += 1

print(count+1)

Submission status: Accepted

Solution code:

def solve():
    ans = N
    for i in range(N-1):
        if S[i] == S[i+1]:
            ans -= 1
    print(ans)

if __name__ == "__main__":
    N = int(input())
    S = input()
    solve()

Submission status: Accepted

Solution code:
input()
S = input()
j = ""
A =""
for i in S:
    if i !=j:
        A += i
        j = i
print(len(A))

Submission status: Accepted

Solution code:
n = int(input())
s = input()

ans = 0
prev = ''
for si in s:
    if prev == si:
        continue
    ans += 1
    prev = si

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

ans = 1
for n in range(N-1):
  if S[n] != S[n+1]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
slime = []
for i in range(n-1):
	if s[i] != s[i+1]:
		slime.append(s[i+1])
print(len(slime)+1)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = 1

for i in range(1,n):
    if s[i] != s[i-1]:
        t += 1

print(t)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()
    ans = 0
    for i in range(n):
        if i == 0:
            ans += 1
            mae = s[i]
        else:
            if s[i] != mae:
                ans += 1
                mae = s[i]
    print(ans)


    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

n = int(input())
s = list(input())

if n == 1:
    print(1)
    sys.exit()

a = []

for i in range(n-1):
    if s[i] != s[i+1]:
        a.append(s[i])

if len(a) == 0:
    print(1)
else:
    if a[-1] != s[-1]:
        a.append(s[-1])

    print(len(a))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
ans = 1
for i in range(1, len(s)):
  if s[i-1] != s[i]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input().rstrip()
    current_char = S[0]
    ans = 1
    for idx in range(1, N):
        if S[idx] != current_char:
            ans += 1
            current_char = S[idx]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
b = 0
d = s[0]
for i in range(n):
    if d != s[i]:
        d = s[i]
        b += 1

print(b+1)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

count = 1
for i in range(n-1):
    if s[i] != s[i+1]:
        count += 1
        
print(count)

Submission status: Accepted

Solution code:
n=input()
s = input()
cnt=0
s_list = [word for word in s]

tmp = s_list.pop()
for _ in range(len(s_list)):
  tmp_2 = s_list.pop()
  if tmp!=tmp_2:
    cnt+=1
  tmp=tmp_2
print(cnt+1)

Submission status: Accepted

Solution code:
n = int(input())

s = input()
ans = [s[0]]
for i in range(1,n):
    if ans[-1] != s[i] :
        ans.append(s[i])

print(len(ans))

Submission status: Accepted

Solution code:
input()
s = input()
count = 1
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

def main():
    N = int(input())
    S = input()

    ans = 1
    for i in range(N-1):
        if S[i+1] != S[i]:
            ans += 1

    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 1
for i in range(1, n):
    if s[i-1] != s[i]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

counter = 0
past = S[0]
for s in S[1:]:
    
    if not s==past:
        counter += 1
        past = s
    
print(counter+1)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

ans = 0
for i in range(1,n):
  if s[i] != s[i-1]:
    ans += 1
print(ans+1)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())

cnt = 1
tmp = S[0]
for k in range(1, N):
  if not S[k] == tmp:
    cnt += 1
  tmp = S[k]
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,s = open(0).read().split()
print(1+sum(s[i-1]!=s[i] for i in range(1,int(n))))

Submission status: Accepted

Solution code:
n = int(input())
s = input()

count = 1
i = 0

while i < n-1:
    if s[i] == s[i+1]:
        i += 1

    else:
        count += 1
        i += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

slime = S[0]

for i in range(1, N):
    if S[i] != slime[-1]:
        slime += S[i]

print(len(slime))

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ans=0
i=0
while i+1<n:
  j=0
  while s[i+j]==s[i+j+1]:
    if i+j+1<=n-2:
      j+=1
    else:
      j+=1
      break
  i+=j+1
  ans+=j
  
print(n-ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
beforeChara = ""
cnt = 0
for s in S:
    if s != beforeChara:
        cnt += 1
    beforeChara = s
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=input()

ans=1
last=s[0]

for i in range(1,n):
    if s[i]!=last:
        last=s[i]
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
answer = 1
for i in range(1, n):
    if s[i - 1] != s[i]:
        answer += 1
print(answer)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
a=[s[0]]
for i in range(1,n):
  if s[i]!=s[i-1]:
    a.append(s[i])
"".join(a)
print(len(a))

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
if N == 1:
  print(1)
if N>=2:
  if S[0] == S[1]:
    S[0]==" "
  for i in range(1,N):
    if S[i-1]==S[i]:
      S[i-1]=" "
  A=[]
  for i in range(N):
        if S[i]!=" ":
              A.append(S[i])
  print(len(A))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

ans = 0
p = S[0]
for i in range(1, N):
    if S[i] == p:  continue
    else:
        ans += 1
        p = S[i]
print(ans + 1)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
cnt=1
for i in range(1, n):
  if s[i-1]!=s[i]:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

cnt = 1

for i in range(n-1):
    if s[i] != s[i+1]:
        cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

s = S[0]
cnt = 1

for i in range(1, N):
    if s != S[i]:
        cnt += 1
        s = S[i]
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())

for x in range(n-1):
  if s[x]==s[x+1]:
    s[x]='1'
    
print(len(s)-s.count('1'))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

s = [S[0]]
for i in range(1,N):
    if S[i] != S[i-1]:
        s.append(S[i])

print(len(s))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
temp = s[0]
ans = 1
for a in s:
  if temp!=a:
    temp = a
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = input()
n = input()
cnt = 0
a = n[0]
for i in range(1,len(n)):
    if a == n[i]:
        continue
    else:
        cnt += 1
        a = n[i]
print(cnt + 1)

Submission status: Accepted

Solution code:
#<C>
n = int(input())
s = list(input())
ans = "1"
for i in s:
    if ans[len(ans) - 1] != i:
        ans += i

print(len(ans) - 1)

Submission status: Accepted

Solution code:
import sys
# from math import sqrt, gcd, ceil, log
# from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n = int(input()); s = inp()
	ans = 1
	for i in range(1, n):
		if s[i-1] != s[i]:
			ans += 1
	print(ans)


		

if __name__ == "__main__":
	solve()

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
check = S[0]
count =1
for i in range(1,N):
    if(check!=S[i]):
        check=S[i]
        count +=1
print(count)

Submission status: Accepted

Solution code:
N =int(input())
S =input()
counter = 1
for i in range(1,N):
    if S[i] != S[i-1]:
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=1
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        pass
    else:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n= int(input())
s = input()
ans = 1
prev = s[0]
for i in range(n-1):
    if prev==s[i+1]:
        pass
    else:
        ans += 1
        prev = s[i + 1]

print(ans)

Submission status: Accepted

Solution code:
n= int(input())
s = input()
ans = 1
for i in range(n-1):
    if s[i]==s[i+1]:
        continue
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n= int(input())
s = input()
ans = 1
for i in range(n-1):
    if s[i]==s[i+1]:
        pass
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    ans = 1
    for i in range(N - 1):
        if S[i] != S[i + 1]:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
Count = 1
for T in range(0,N-1):
    if S[T]!=S[T+1]:
        Count += 1
print(Count)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
tmp=s[0]
ans=1
for i in range(1,n):
    if s[i]!=tmp:
        tmp=s[i]
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = list(input())
    cnt = 1
    for i in range(1, n):
        if s[i] == s[i-1]:
            continue
        else:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
mylist=[s[0]]
for i in range(1,n):
    if s[i-1]!=s[i]:
        mylist.append(s[i])
print(len(mylist))

Submission status: Accepted

Solution code:
n = int(input())
s = input()

ans = 0
prev = ''
for si in s:
    if prev == si:
        continue
    else:
        ans += 1
        prev = si

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()

S=list(S)

ans=[]
color = ''
for s in S:
    if color != s:
        ans.append(s)
        color = s
print(len(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
sl = list(s)
k = 0
cur = '0'
for i in range(n):
    if sl[i] == cur:
        continue
    else:
        k += 1
        cur = sl[i]
print(k)

Submission status: Accepted

Solution code:
n=int(input())
s=(input())

v=s[0]
count=1
for i in range(n):
  if s[i] == v:
    continue
  v = s[i]
  count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())

new_s = s[0]

for i in range(1,len(s)):
    if s[i] == s[i-1]:
        continue
    else:
        new_s += s[i]

print(len(new_s))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ex = -1
ans = 0
for i in range(n):
  if s[i] != ex:
    ans += 1
    ex = s[i]
print(ans)

Submission status: Accepted

Solution code:
def run_length(data, init=''):
    length = []
    tmp = init
    cnt = 0
    for c in data:
        if tmp != c:
            length.append(cnt)
            cnt = 0
        tmp = c
        cnt += 1
    length.append(cnt)
    return length


def resolve():
    n = int(input())
    s = input()
    length = run_length(s, '')
    print(len(length) - 1)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
prev_char = ""
result = 0

for i in s:
  if (prev_char != i):
    result += 1
  prev_char = i

print(result)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    fusion = [S[0]]
    prev = S[0]
    for s in S[1:]:
        if s == prev:
            continue
        fusion.append(s)
        prev = s
    print(len(fusion))
main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
temp = ''
cnt = 0
for i in s:
  if i != temp:
    cnt += 1
    temp = i
print(cnt)

Submission status: Accepted

Solution code:
def main():
    N = input_int()
    S = input()

    count = 1

    for i in range(1, N):
        if S[i-1] != S[i]:
            count += 1

    print(count)


def input_int():
    return int(input())


# def input_int_tuple():
#     return map(int, input().split())


# def input_int_list():
#     return list(map(int, input().split()))


main()

Submission status: Accepted

Solution code:
def main():
    N = input_int()
    S = input()

    count = 1

    for i in range(1, N):
        if S[i-1] != S[i]:
            count += 1

    print(count)


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


def input_int_list():
    return list(map(int, input().split()))


main()

Submission status: Accepted

Solution code:
def main():
    N = input_int()
    S = input()

    validitylist = [False] * N
    validitylist[0] = True

    for i in range(1, N):
        if S[i-1] != S[i]:
            validitylist[i] = True
    
    print(len([i for i in validitylist if i is True]))



def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


def input_int_list():
    return list(map(int, input().split()))


main()

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
check=""
ans=0
for i in range(N):
  if check!=S[i]:
    ans+=1
    check=S[i]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s = input()
a = s[0]
cnt = 1
for i in range(n):
    if a == s[i]:
        continue
    else:
        a = s[i]
        cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
#print(N,S)
count = 0
for i in range(N-1):
    if S[i] != S[i+1]:
        count += 1
        
print(count+1)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
#print(N,S)

stack = []
while len(S) > 0:
    if len(stack) == 0:
        stack.append(S[0])
        S = S[1:]
    elif S[0] == stack[-1]:
        S = S[1:]
    
    elif S[0] != stack[-1]:
        stack.append(S[0])
        S = S[1:]
    #print(S,stack)
print(len(stack))