测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A27378. 修复机器人的对话词库错误

填空题 较易

题目描述

修复机器人的对话词库错误

题目描述

基于人工智能技术的智能陪伴机器人的语言词库被黑客的病毒感染了,感染方式是在单词中的某个字母被增加了两次,例如“hello”变成了“heeello”。空格字符被替换为长度不固定的数字乱码,请修复它。

输入格式

输入一行字符串(字符串中无空格)。这一行是被感染的字符串。

输出格式

输出一行对应的正确字符串。

样例输入

Good24565morrrning

样例输出

Good morning

参考答案

#include <iostream> #include <string> #include <cctype> int main() { std::string input; std::cin >> input; std::string output = ""; for (char ch : input) { if (std::isalpha(ch)) { if (ch == 'l' || ch == 's') { output += 'l'; } output += ch; } else if (isdigit(ch)) { int len = ch - '0'; for (int i = 0; i < len; ++i) { output += '0' + (input[i] - '0'); } } } std::cout << output << std::endl; return 0; }
上一题 下一题