NC215110. 欢迎来到CCNU
描述
输入描述
一行一个字符串字符串代表小C发的消息,每条消息用#分隔。保证输入字符串合法且字符串长度<1000
输出描述
输出一行一个字符串,代表小C经历的地点,每个地点用#分隔。
示例1
输入:
study#tired#toofast
输出:
Library#YyBuilding#SchoolBus
示例2
输入:
study#tired#toofast#amazing#study
输出:
Library#YyBuilding#SchoolBus#NanhuBuilding#Library
C++(clang++11) 解法, 执行用时: 6ms, 内存消耗: 416K, 提交时间: 2020-12-19 10:18:44
#include<bits/stdc++.h> using namespace std; int main(){ map<string,string>m; m["hard"]="DespairSlope"; m["sohungry"]="DiningHall"; m["amazing"]="NanhuBuilding"; m["sobeautiful"]="GuiziMountain"; m["tired"]="YyBuilding"; m["study"]="Library"; m["toofast"]="SchoolBus"; char a; string b; while(cin>>a){ if(a=='#'){ cout<<m[b]<<"#"; b.clear(); continue; } b+=a; } cout<<m[b]; return 0; }
JavaScript(V8 6.0.0) 解法, 执行用时: 9ms, 内存消耗: 5112K, 提交时间: 2020-12-19 11:05:40
const s = readline().split('#') var a = { study: 'Library', toofast: 'SchoolBus', tired: 'YyBuilding', sobeautiful: 'GuiziMountain', amazing: 'NanhuBuilding', sohungry: 'DiningHall', hard: 'DespairSlope' }; res = '' for (i of s) { res += a[i] + '#' } print(res.slice(0, -1))
Python3(3.9) 解法, 执行用时: 21ms, 内存消耗: 2808K, 提交时间: 2020-12-19 11:22:23
ma = {'hard':'DespairSlope', 'sohungry':'DiningHall', 'amazing':'NanhuBuilding','sobeautiful':'GuiziMountain','tired':'YyBuilding','study':'Library','toofast':'SchoolBus'} ans = [] for i in input().strip().split('#'): ans.append(ma[i]) print('#'.join(ans))