Description
Editor's note: all the "[]" and the content included in this article are designed to respond to the "maximum public appointment" of the harmonious society, which can be ignored and may cause inconvenience to reading questions, sorry ~
Tomorrow is the 6th power of two, and g [] f [] W (ignore if you don't know) is about to start a major operation ......
Suddenly, just listen to Gg and say, "MD! Lao Tzu's website is on the wall again !", The people around me were speechless, saying that Gg's website seldom involves topics such as politics and governance. Is it ...... (Go to the noodle shop without thinking about it !)
Suddenly too, GG solemnly announced: "I want to test my latest research on information transmission methods on my website! "
The following content is transferred from an international conference of GG:
"G [] f [] W is usually used to capture information to determine whether the content is hexie. Once a brand new code is used, the troubles of'' can be completely eliminated. The current network usually uses base64, which converts every three 8-bit bytes into four 6-bit bytes (3*8 = 4*6 = 24 ), then, add 6 bits to two more 0 bits to form four 8 bits. In another simple and effective way, we can convert each 8-bit byte into four 2-bit bytes, and then replace them with four characters. The encoding and character schemes are as follows:
00---g
01---f
10---w
11 --- Space
In this way, the encoded string will only contain 'G', 'F', 'w', and spaces.
For example, the ASCII code of the character y is 121, and the corresponding binary string is 01111001. After dividing it into four parts: 01 11 10 01, the string encoded with base4 is 'fwf '."
Now, we will specify any string that requires the number of "G [] f [] W" in the results obtained based on Gg's latest research results ".
Input
The first line has a positive integer N, which represents the next n original strings to be encoded. (N <= 20)
Next there are n rows. Each row has an original string of no more than 10 ^ 5 characters. The characters in the original string may be any visible characters except line breaks in ASCII code.
Output
There are n rows in total, each of which is an integer k, indicating the number of complete "G [] f [] W" in the encoding of each group of input data ".
Solution: To solve this problem, you need to convert English letters into ASCII codes, convert them according to the base encoding method, and finally count the number of gb f w. The specific operation can be directly converted to numbers 0, 1, and 2 through bitwise operations, which can be stored in arrays and directly searched.
#include<iostream>#include<cstdio>using namespace std;char d[400000];char s[100001];int main(){int t;scanf("%d",&t);while(t--){scanf("%s",s);int n=0;for(int i=0;s[i];i++){char c = s[i];d[n++] = c>>6;d[n++] = (c>>4)&3;d[n++] = (c>>2)&3;d[n++] = c&3;}int ans = 0;for(int i=0;i<n-2;i++)if (d[i]==0&&d[i+1]==1&&d[i+2]==2) ++ans;cout<<ans<<endl;}return 0;}