SDNUOJ1018

模拟

题目链接:SDNUOJ1018
纯正而不加掩饰的字符串处理加模拟

思路

  1. 读入字符串,并取得字符串长度便于逐个处理
  2. 将判断W、L并使对应的计数+1,当其中任意一个到达3,都将w、l数重置为0(即开始下一场)
  3. 如果是w到达3,则ans++;

代码

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[10001];
int main(){
 gets(a);
 int len=strlen(a);
// int flag=0;
 int ans=0;
 int w=0;
 int l=0;
 for(int i=0;i<len;i++){
  if(a[i]=='W'){
   w++; 
  }
  else l++;
  if(w==3){
   ans++;
   w=0;
   l=0;
  }
  else if(l==3){
   w=0;
   l=0;
  }
 }
 cout<<ans<<endl;
 return 0;
}

猜你喜欢

转载自blog.csdn.net/L_Saint00/article/details/82993517