PAT Grade B 1040 has several PAT 25 (points)

topic

String APPAPT contains two words PAT , the first of which PAT is a second position ( P ), bit 4 ( A ), bit 6 ( T ); the second PAT is the bit 3 ( P ), bit 4 ( A ), 6 Bit ( T ).

Given a string, how many can be formed in total PAT ?

Input format:

Input single line comprising a string of not more than 10 510 ^ 5 . 1 0 ? 5 ? ? , Contains only , , three kinds of letters. P A T

Output format:

Print how many of the given string contains in one line PAT . Since the result may be relatively large, only the result of taking the remainder of 1000000007 is output.

Input sample:

APPAPT

Sample output:

2

Code


#include<iostream>
using namespace std;
int main()
{
    
    
	long long cal = 0;
	long long *p=new long long[100000], * a = new long long[100000], * t = new long long[100000], i = 0;
	string in="";
	cin >> in;
	for (i = 0; i < 100000; i++)
	{
    
    
		p[i] = 0;
		a[i] = 0;
		t[i] = 0;
	}
	i = 0;
	while (in[i++] != '\0')
		if (in[i - 1] == 'P')
			p[i-1]++;
		else if(in[i - 1] == 'A')
			a[i-1]++;
		else if(in[i - 1] == 'T')
			t[i-1]++;
	for (i = 99998; i >= 0; i--)
		t[i] += t[i + 1];
	for (i = 0; i < 100000; i++)
		a[i] *= t[i];
	for (i = 99998; i >= 0; i--)
		a[i] += a[i + 1];
	for (i = 0; i < 100000; i++)
		if (p[i] != 0)
			cal += p[i] *a[i];
	cout << cal % 1000000007;
	return 0;
}

Question details link

Guess you like

Origin blog.csdn.net/qq_41985293/article/details/115035365