题解:P11751 [COCI 2024/2025 #5] 呜哇 / Wow
这是一道简单的字符串题。
解题思路:
- 我们可以遍历整个字符串,如果上一个字符是
/且字符a_i 为.。如果t=4 就是v,否则是w。t 的作用会在下午阐述。 - 否则我们
t=t+1 。在这里,我们的t 是一个计数器,用于统计当前连续的字符个数。
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string a;
cin>>n>>a;
int t=0;
for(int i=0;i<n;i++){
if(a[i-1]=='/'&&a[i]=='.'){
if(t==4) cout<<'v';
else cout<<'w';
t=0;
}
else t++;
}
if(t==4) cout<<'v';
else cout<<'w';
return 0;
}