NC214629. Scissors-Paper
描述
输入描述
The first line contains one integer T, the number of test cases.For each test case, there are two lines.The first line contains an integer n -the length of the string.The second line contains a string consists of only 'S' and 'P'.If the i-th character is 'S', Xiao Li will play Scissors in the i-th turn. Similarly, if the i-th character is 'P', Xiao Li will play Paper in the i-th turn.(T ≤ 100, ∑n≤1e6)
输出描述
For each case, your program will output only a line contains a single integer — the Xiao Wang's maximum possible score.
示例1
输入:
2 3 PSP 10 PPSSPPPSPP
输出:
0 2
说明:
For the first case, playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.C(clang11) 解法, 执行用时: 4ms, 内存消耗: 484K, 提交时间: 2020-12-27 13:42:59
int main() { int T; scanf("%d",&T); while(T--) { int a,i,s=0,p=0; char x[1000000]; scanf("%d",&a); scanf("%s",x); for(i=0;i<a;i++) { if(x[i]=='S') s++; if(x[i]=='P') p++; } int k=a/2; printf("%d\n",k-s); } return 0; }
C++(clang++11) 解法, 执行用时: 26ms, 内存消耗: 720K, 提交时间: 2021-01-06 13:11:01
#include<iostream> #include<string> using namespace std; int main(){ int t; cin>>t; int n; string s; while(t--){ cin>>n>>s; int num=0; for(int i=0;i<s.length();i++){ if(s[i]=='S') num++; } cout<<n/2-num<<endl; } }
Python3(3.9) 解法, 执行用时: 19ms, 内存消耗: 3356K, 提交时间: 2020-12-27 14:39:07
a=int(input()) for i in range(a):print((int(input())//2)-input().count('S'))