列表

详情


NC223712. UmmCode

描述

The current programming club president, Norbit, gives speeches at the weekly club meetings. Casual viewers are underwhelmed with the quality of Norbit’s elocution. Specifically, Norbit often hesitates during his speeches with interjections like “umm.”

You, however, are no casual viewer–you are a computer scientist! You have noticed strange patterns in Norbit’s speech. Norbit’s interjections, when arranged together, form a binary code! By substituting 1’s and 0’s for u’s and m’s, respectively, you produce 7-bit binary ASCII codes that spell out secret messages.

For example, the letter ‘a’ has an ASCII code of 97, which translates to a binary value of 1100001 and an umm code of “uummmmu”. An umm code can be split up in the speech. For example, an encoding of ‘a’ could be stretched across three utterances: “uum”, “mmm”, “u” (possibly with other non-umm code words occurring between them).

Now that you have discovered Norbit’s secret, you go back through transcripts of his previous speeches to decode his cleverly concealed messages.

输入描述

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;
				}
	}
}

上一题