当前位置:网站首页>String decompression (Huawei OD)
String decompression (Huawei OD)
2022-07-20 07:08:00 【go_ flush】
String decompression
There is a simple compression algorithm :
For strings composed of all lowercase English letters , Compress the part of more than two consecutive identical letters into consecutive numbers plus the other parts of the letter to keep the same
unchanged , for example aaaab 4ab
White those decompression functions , According to the input string , Judge whether it is a legally compressed string
Input description :
The input line , For one asccii character string
Length not exceeding 100 character
The use case ensures that the length of the output string will not exceed 100 character
Output description :
If it is judged that the input is a legal compressed string
Output the string before compression
If the input is illegal , Output "!error"
4dff
ddddff
- Answer key
- The situation of this problem is relatively , I don't know how to organize filter conditions , It's not difficult to mention . At present, I can only do the following , such 4dddd This situation is not considered .
The code is as follows :
def decompression():
string = input()
legal_string = "abcdefghijklmnopqrstuvwxyz0123456789"
index = 0
res = ""
# Validation
if len(set(string)) == 1 and len(string) >= 3:
print("!error")
return
while index < len(string):
if string[index] not in legal_string:
print("!error")
break
num = ""
if string[index].isdigit():
while string[index].isdigit(): # consider 22d 11d 20a 10a The situation of
num += string[index]
index += 1
if num == "2" or num == "1": # Exclusion number is 2 perhaps 1 The situation of
print("!error")
break
# It must be a letter
res += int(num) * string[index]
else:
res += string[index]
index += 1
else:
print(res)
if __name__ == '__main__':
decompression()
边栏推荐
猜你喜欢
Fundamentals of C language: structure (elementary level)
Microservice 2-nacos configuration center
Redis删除策略和淘汰策略
pdf.js 使用介绍
D. Rating Compression(思维 + 双指针)
09基于ZigBee的水质监测系统设计
Silicon Valley class lesson 10 - marketing module and official account menu management
什么是跨站脚本 (XSS)?
09 design of water quality monitoring system based on ZigBee
Live broadcast today | Apache pulsar meetup: vivo, Tencent cloud, bigo, Yunxing technology practice sharing
随机推荐
一次翻好多倍的SQL优化过程
Debezium同步之监测Debezium
Enter the enterprise series | streamnational x Zhong'an insurance
仆人式领导的八个注意事项
超时放弃订单怎么实现(几种方案)
渗透测试神器之metasploit
这几款实用的安全浏览器插件,让你效率提高
Detailed WC find xargs zip gzip bzip2 XZ tar SFTP command or protocol
什么是跨站脚本 (XSS)?
C语言枚举类型和联合体
由浅入深了解羚珑平台统一接入服务 —— Monet
Sovit3d rapid development of intelligent agriculture 3D visualization system of Internet of things
视频24 ALexNet
数据库压力测试方法概述
G. Count the Trains(思维set + 二分)
UXDB如何在多个处理器上工作
【无标题】
2022-07-18:以下go语言代码输出什么?A:Groutine;B:Main;C:Goroutine;D:GoroutineMain。 package main import ( “f
Silicon Valley class lesson 9 - integration gateway and order and marketing module
How to realize the overtime abandonment order (several schemes)