题目描述
来源:牛客网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 one integer, denoting the answer.
示例1
输入
wwwvwwvw
输出
思路:
if(s[i]=='w') { int nu=0; while(s[i]=='w') ++i,++nu; an+=(nu*2-1); }
AC代码
#include<bits/stdc++.h> using namespace std; char s[100005]; int main() { scanf("%s",s); int an=0; int ls=strlen(s); for(int i=0;i<ls;++i) { if(s[i]=='w') { int nu=0; while(s[i]=='w') ++i,++nu; an+=(nu*2-1); } } printf("%d\n",an); return 0; }