题目描述:R-石头 S-剪刀 P-布,每个人都按周期来出,问n把后双方各输了多少次
#include <deque>
#include <unordered_map>
#include <stack>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <unordered_set>
#include <utility>
#include <limits.h>
using namespace std;
int gcd(int x, int y)
{
while(x!=y){
if(x>y) x=x-y;
else y=y-x;
}
return x;
}
int main()
{
int n, x, y,one_len, i, j;
string s1, s2, str1, str2;
cin >> n >> s1 >> s2;
x = s1.length();
y = s2.length();
one_len = x * y / gcd(x, y);
str1 = s1;
str2 = s2;
while (str1.length() < one_len)
{
str1 += s1;
}
while (str2.length() < one_len)
{
str2 += s2;
}
int repeat_time = n / one_len;
int remain_len = n % one_len;
int t1=0,t2=0;
for (i=0; i < remain_len; i++)
{
if(str1[i]=='R'){
if(str2[i]=='S')
t1++;
else if(str2[i]=='P')
t2++;
}
else if(str1[i]=='S'){
if(str2[i]=='P')
t1++;
else if(str2[i]=='R')
t2++;
}
else if(str1[i]=='P'){
if(str2[i]=='R')
t1++;
else if(str2[i]=='S')
t2++;
}
}
int ans1 = t1, ans2 = t2;
if(repeat_time)
for(;i<one_len;i++){
if(str1[i]=='R'){
if(str2[i]=='S')
ans1++;
else if(str2[i]=='P')
ans2++;
}
else if(str1[i]=='S'){
if(str2[i]=='P')
ans1++;
else if(str2[i]=='R')
ans2++;
}
else if(str1[i]=='P'){
if(str2[i]=='R')
ans1++;
else if(str2[i]=='S')
ans2++;
}
}
ans1=ans1*repeat_time+t1;
ans2=ans2*repeat_time+t2;
cout<<ans2<<" "<<ans1<<endl;
return 0;
}