A - Stones on the Table
Problem Link: [Codeforces 266A##link##]
- [tab]
- C++
#include <iostream> using namespace std; int main() { string s; int count=0,i,n; cin>>n; cin>>s; for(i=0;i<s.length();i++) { if(s[i]==s[i+1]) { count++; } } cout<<count; return 0; }
- Python3
n=int(input()) l1=list(input()) tot=1 for i in range(n-1): if l1[i]==l1[i+1]: tot+=1 print(tot-1)
- JAVA
import java.util.*; public class AnotherOne { public static void main (String[] args) throws java.lang.Exception { // Input Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); // Counters int counter = 0; char last = s.charAt(0); for (int i = 1; i < n; i++) { if (s.charAt(i) == last) counter++; else last = s.charAt(i); } // Output System.out.println(counter); sc.close(); } }