关于 Maritozzo 问题的思考
来源于ac contest 219 B
------------------------------------------------------------
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
===================================
Problem Statement
You are given three strings S_1, S_2, S_3S1,S2,S3 consisting of lowercase English letters, and a string TT consisting of 1, 2, 3.
Concatenate the three strings according to the characters in TT and print the resulting string. Formally, conform to the following instructions.
- For each integer ii such that 1 \leq i \leq |T|1≤i≤∣T∣, let the string s_isi be defined as follows:
- S_1S1, if the ii-th character of TT is
1; - S_2S2, if the ii-th character of TT is
2; - S_3S3, if the ii-th character of TT is
3.
- S_1S1, if the ii-th character of TT is
- Concatenate the strings s_1, s_2, \dots, s_{|T|}s1,s2,…,s∣T∣ in this order and print the resulting string.
---------------------------------------------------------------
Constraints
- 1 \leq |S_1|, |S_2|, |S_3| \leq 101≤∣S1∣,∣S2∣,∣S3∣≤10
- 1 \leq |T| \leq 10001≤∣T∣≤1000
- S_1S1, S_2S2, and S_3S3 consist of lowercase English letters.
- TT consists of
1,2, and3.
---------------------------------------------------------------
Input
Input is given from Standard Input in the following format:S_1S1
S_2S2 S_3S3 TT
--------------------------------------------
Output
Print the answer.
----------------------------------------------------------------
Sample Input 1
mari to zzo 1321
---------------------------------------------
Sample Output 1
marizzotomari
We have s_1 =s1= mari, s_2 =s2= zzo, s_3 =s3= to, s_4 =s4= mari. Concatenate these and print the resulting string:
marizzotomari.
-----------------------------------------------------------------------------
Sample Input 2
abra cad abra 123
------------------------------------------------------
Sample Output 2
abracadabra
-------------------------------------------------------
Sample Input 3
a b c 1
------------------------------------------
Sample Output 3
a
-------------------------------------------
AC
#include <bits/stdc++.h> using namespace std; int main(){ vector<string> s(4); for (int i = 1; i <= 3;i++) cin >> s.at(i); string t; cin >> t; for (auto i = 0; i < t.length();i++){ int j = t.at(i) - '0'; cout << s.at(j); } cout << endl; }
对于这题,我i自己写的很是复杂。
结果呢?WA/TLE
在此就不展示自己的繁冗代码了。
这么简单的方法当然是借鉴过来的啦 <:
有个地方不是很清楚,
在于那个 at
不知道是不是 C++ 的特殊方法
我的 VScode 告诉我那是重载函数
如果可以这么使用的话
与 C 的 sprintf 大为相似
实现了 数组 与 字符串之间的转换
----------------------------------------------------------------------
希望有大佬出来指点一下,
鄙人必将感激不尽!
本文来自博客园,作者:小白兔奶糖, 侵权必究!!!







浙公网安备 33010602011771号