NC18993. 硬币游戏
描述
输入描述
第一行,一个数字n(N<=1000000)
第二,三行,每行各一个长度为2n的字符串
输出描述
一行 输出 clccle trl!或sarlendy tql!或orz sarlendy!
示例1
输入:
3 UDUDUU DUDUUD
输出:
clccle trl!
说明:
clccle先取5,sarlendy取4,clccle取6,sarlendy取2,clccle取1,sarlendy取3Pascal(fpc 3.0.2) 解法, 执行用时: 46ms, 内存消耗: 7624K, 提交时间: 2018-09-18 16:37:33
var n,i,t1,t2:longint; s1,s2:ansistring; begin readln(n); readln(s1); readln(s2); for i:=1 to 2*n do begin if s1[i]='U' then inc(t1); if s2[i]='U' then inc(t2); end; if t1>t2 then writeln('clccle trl!'); if t1<t2 then writeln('sarlendy tql!'); if t1=t2 then writeln('orz sarlendy!'); end.
C++ 解法, 执行用时: 80ms, 内存消耗: 8092K, 提交时间: 2022-03-27 16:18:39
#include<bits/stdc++.h> using namespace std; int main() { int n,i,x=0,y=0; string a,b; cin>>n; cin>>a>>b; for(i=0;i<2*n;i++) if(a[i]=='D') x++; for(i=0;i<2*n;i++) if(b[i]=='D') y++; if(x<y) cout<<"clccle trl!"; else if(x>y) cout<<"sarlendy tql!"; else cout<<"orz sarlendy!"; return 0; }
Python3 解法, 执行用时: 436ms, 内存消耗: 10412K, 提交时间: 2023-05-25 00:35:19
from collections import Counter n = int(input()) s1, s2 = input(), input() cnt = Counter(c1 + c2 for c1, c2 in zip(s1, s2)) cnt['UD'] += cnt['UU'] % 2 if cnt['UD'] > cnt['DU']: print('clccle trl!') elif cnt['UD'] == cnt['DU']: print('orz sarlendy!') else: print('sarlendy tql!')