NC223712. UmmCode
描述
输入描述
There is one line of input of length S (20 ≤ S ≤ 500 000), which ends with a single newline. Before the newline, theinput may contain any characters in the ASCII range 32 – 126 (that is, space (‘ ’) through tilde (‘~’)).Let’s define a “word” as a space-delimited sequence of characters. If a word does not contain any letters or digitsexcept lowercase u’s and/or m’s, then it is part of the umm-coded message. If a word contains digits or letters otherthan lowercase u and m, then it is not part of the umm-coded message (even if it does contain u or m). Note that aword that is part of the umm-coded message may contain punctuation (which is defined as anything other than letters,digits, or space). Naturally, you should only consider the u and m characters (and not punctuation) when decoding theumm-coded message. Let M be the length of the entire umm-coded message (counting only its u and m characters).It is guaranteed that M ≥ 7 and M is evenly divisible by 7
输出描述
Print the de-umm-coded message. Note that for this problem, the judging is case-sensitive. It is guaranteed that each character that should be output is in the same ASCII range as the input.
示例1
输入:
uu Friends m Romans ummuuummmuuuuumm countrymen mmuummmuu
输出:
icpc
示例2
输入:
umm ummm uum umm um ummmm u?
输出:
Hi!
Python3 解法, 执行用时: 345ms, 内存消耗: 15028K, 提交时间: 2022-02-24 15:41:31
s=input().split() d={'u':'1','m':'0'} cnt=0 tmp='' vec=[] for i in s: flag=1 for k in i: ac=ord(k) if (ac>64 and ac<91) or (ac>96 and ac<109) or (ac>109 and ac<117) or (ac>117 and ac<123): flag=0 break if flag: for j in i: if j in d: tmp+=d[j] cnt+=1 if cnt==7: vec.append(tmp) tmp='' cnt=0 ans='' for i in vec: if not i: continue ans+=chr(int(i,2)) print(ans)
C++ 解法, 执行用时: 102ms, 内存消耗: 452K, 提交时间: 2021-08-19 13:29:47
#include<bits/stdc++.h> using namespace std; char c; string s; signed main() { for(int i = 0, j = 0; cin >> s; ) { int is = 1; for(auto c : s) if(isdigit(c) || isalpha(c) && c != 'u' && c != 'm') is = 0; if(is) for(auto c : s) if(c == 'u' || c == 'm') { j = j * 2 + (c == 'u'); if(++i % 7 == 0) printf("%c", j), i = j = 0; } } }