当前位置: 代码迷 >> 综合 >> smart browser
  详细解决方案

smart browser

热度:64   发布时间:2023-12-06 21:37:17.0

链接:https://ac.nowcoder.com/acm/contest/7501/C
来源:牛客网

post 发      grass 草  shapes 形状   browser 浏览器   effects 效果 影响     gap 间隙    adjacent adj邻接的    determine v确定 

题目描述

In some social platforms, there are some netizen who like to post "www". Since the string is like the grass, which contains plenty of "/\" shapes, so there are also some netizen who post "grass".

As a fast, smart, and convenient browser, MI Browser can recognize this kind of text and show some special effects. Specifically, given a string, MI Browser will determine the number of "/\" shapes made by character "w", where "w" itself and the gap between two adjacent "w"s both give one `/\` shape. If still not clear, please turn to sample input/output for more details.

As a MI fan, you want to detect the relationship between the special effects and the number of "/\" shapes, so the thing you should do first is to determine the number of "/\" shapes by yourself.
 

输入描述:

Only one line containing a string s (1≤∣s∣≤105)s~(1\le |s| \le 10^5)s (1≤∣s∣≤105).It's guaranteed that s only contains lowercase letters.

输出描述:

Only one line containing one integer, denoting the answer.

示例1

输入

复制wwwvwwvw

wwwvwwvw

输出

复制9

9

说明

In "www", there are 5 "/\" shapes.In "ww", there are 3 "/\" shapes.In "w", there is only 1 "/\" shape.
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<set>
using namespace std;
const int inf=0x3fffffff;
const int maxn=10010;int main(){long long res=0;string str;cin>>str;// wwwvvwwvvww// wwwlong long len = str.length();for(int i=0;i<len;){int cnt=0;while(i!=len && str[i]=='w'){cnt++;i++;	}if(cnt) res = res + cnt*2-1 ;while(i!=len && str[i]!='w') {i++;}}	if(res<=0)  res=0;cout<<res;return 0;
}

 

  相关解决方案