如何将(Char,Int)的列表转换为具有给定重复字符数的字符串? [英] How to convert a list of (Char,Int) to a string with the given number of repeated chars?
本文介绍了如何将(Char,Int)的列表转换为具有给定重复字符数的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 [(char,Int)]
转换为第二个组件中的Int字符串给出第一个组件中字符的重复次数?例如,输入 [(a,9),(b,10)]
应该给出 [aaaaaaaaa,bbbbbbbbbb]
作为输出。
How can I convert [(char,Int)]
to a String of the Int in the second component gives the number of repetitions of the character in the first component? For example the input [(a,9),(b,10)]
should give ["aaaaaaaaa","bbbbbbbbbb"]
as output.
推荐答案
The facetious and horrible answer:
Prelude> let replignore ((_,x):[]) = [replicate x 'b']; replignore ((_,x):xs) = replicate x 'a' : replignore xs
Prelude> replignore [(a,9),(b,10)]
<interactive>:1:13: Not in scope: `a'
<interactive>:1:19: Not in scope: `b'
Prelude> let a = undefined
Prelude> let b = undefined
Prelude> replignore [(a,9),(b,10)]
["aaaaaaaaa","bbbbbbbbbb"]
但它并不完全符合规格,因为它在答案中包含引号。 ;)
But it didn't quite fit the specs since it includes the quotation marks in the answer. ;)
我的观点是,你需要引用你的 Char
和 String
文字。
My point is, you need quotes around your Char
and String
literals.
这篇关于如何将(Char,Int)的列表转换为具有给定重复字符数的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文