1178B B. WOW Factor

B. WOW Factor
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Recall that string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly zero or all) characters. For example, for the string a=“wowwo”, the following strings are subsequences: “wowwo”, “wowo”, “oo”, “wow”, “”, and others, but the following are not subsequences: “owoo”, “owwwo”, “ooo”.

The wow factor of a string is the number of its subsequences equal to the word “wow”. Bob wants to write a string that has a large wow factor. However, the “w” key on his keyboard is broken, so he types two "v"s instead.

Little did he realise that he may have introduced more "w"s than he thought. Consider for instance the string “ww”. Bob would type it as “vvvv”, but this string actually contains three occurrences of “w”:

“vvvv”
“vvvv”
“vvvv”
For example, the wow factor of the word “vvvovvv” equals to four because there are four wows:

“vvvovvv”
“vvvovvv”
“vvvovvv”
“vvvovvv”
Note that the subsequence “vvvovvv” does not count towards the wow factor, as the "v"s have to be consecutive.

For a given string s, compute and output its wow factor. Note that it is not guaranteed that it is possible to get s from another string replacing “w” with “vv”. For example, s can be equal to “vov”.

Input
The input contains a single non-empty string s, consisting only of characters “v” and “o”. The length of s is at most 106.

Output
Output a single integer, the wow factor of s.

Examples
input

vvvovvv
output
4
input
vvovooovovvovoovoovvvvovovvvov
output
100
Note
The first example is explained in the legend.
**题意:**给出只含有v和o的字符串,两个相邻的v组成一个w,问这个字符串的子串有多少个子串可以组成wow.
**思路:**先遍历一遍找出w的个数,再从左到右依次遍历找出字符’o’左边的w的数目,乘于右边的w的数目,相加即可得到答案。

#include <iostream>
#include <algorithm>
#include <cstring> 
using namespace std;
typedef long long ll;
int main() {
	char s[1000005];
	scanf("%s", s);
	int len = strlen(s);
	int num = 0, num1 = 0;
	for (int i = 1; i < len; i++) { // 找出字符串中w的数目 
		if (s[i] == 'v' && s[i-1] == 'v') {
			num++;
		} 
	}
	ll ans = 0;
	for (int i = 1; i < len; i++) {
		if (s[i] == 'v' && s[i-1] == 'v') { // 找出当前字符o左边的w数目 
			num1++;
		}
		else if (s[i] == 'o') {
			ans += (ll)num1 * (num - num1); // 当前o左边w数目乘于右边w数目 
		} 
	}
	printf("%lld\n", ans);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值