求助基础赛T2
  • 板块学术版
  • 楼主_Chronostatis_
  • 当前回复9
  • 已保存回复9
  • 发布时间2023/8/6 18:57
  • 上次更新2023/11/3 05:32:51
查看原帖
求助基础赛T2
768951
_Chronostatis_楼主2023/8/6 18:57
#include<bits/stdc++.h>

using namespace std;

string s;

int main(){

    int n;

    cin >> n;

    getchar();

    getline(cin,s);

    long long now = 0,ans = 0;

    for (int i = 0; i < s.size(); i++){

        if (s[i] == 'W'){

            ans += abs(0 - now);

            // cout << "i=" << i << ':' << abs(0 - now) << '\n';

            now = 0;
        }
        
        if (s[i] == 'B'){

            ans += abs(1 - now);

            // cout << "i=" << i << ':' << abs(1 - now) << '\n';

            now = 1;
        }
        
        if (s[i] == 'R'){

            ans += abs(2 - now);

            // cout << "i=" << i << ':' << abs(2 - now) << '\n';

            now = 2;
        }
    }

    cout << ans;

    return 0;
}
2023/8/6 18:57
加载中...