1093. Count PAT's (25)

#include <iostream>
#include <string.h>

using namespace std;

char s[100010];

int main()
{
	gets(s);

	int i, len = strlen(s);
	long long pcount = 0, acount = 0, tcount = 0;
	char ch;
	
	for(i = 0; i < len; i++)
	{
		ch = s[i];
		if(ch == 'T')
		{
			tcount++;
		}
	}

	long long res = 0;
	for(i = 0; i < len; i++)
	{
		ch = s[i];
		if(ch == 'T')
		{
			tcount--;

			if(tcount == 0)
			{
				break;
			}
		}
		else if(ch == 'P')
		{
			pcount++;
		}
		else
		{
			res += pcount * tcount;
		}
	}

	printf("%lld\n", res % 1000000007);

	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:22  王景迁  阅读(3)  评论(0)    收藏  举报

导航