fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int N;
  7. string S;
  8. cin >> N >> S;
  9.  
  10. // Initialize the count with 1 (first character is always included)
  11. int count = 1;
  12.  
  13. // Traverse the string and count characters that are different from the previous one
  14. for (int i = 1; i < N; ++i) {
  15. if (S[i] != S[i - 1]) {
  16. count++;
  17. }
  18. }
  19.  
  20. cout << count << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
1