C-printf Parser
约 219 字小于 1 分钟
2026-02-11
题目
There is a function in C language: printf. This function allows us to print something with formatting. Like this:
printf("The result is %d.", 42);This challenge requires you to parse the input string and extract the format placeholders like %d and %f. For example, if the input string is "The result is %d.", the parsed result is a tuple ['dec'].
Here is the mapping:
type ControlsMap = {
c: 'char',
s: 'string',
d: 'dec',
o: 'oct',
h: 'hex',
f: 'float',
p: 'pointer',
}解题思路
待补充
答案
type ControlsMap = {
c: 'char'
s: 'string'
d: 'dec'
o: 'oct'
h: 'hex'
f: 'float'
p: 'pointer'
}
type ParsePrintFormat = any验证
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<ParsePrintFormat<''>, []>>,
Expect<Equal<ParsePrintFormat<'Any string.'>, []>>,
Expect<Equal<ParsePrintFormat<'The result is %d.'>, ['dec']>>,
Expect<Equal<ParsePrintFormat<'The result is %%d.'>, []>>,
Expect<Equal<ParsePrintFormat<'The result is %%%d.'>, ['dec']>>,
Expect<Equal<ParsePrintFormat<'The result is %f.'>, ['float']>>,
Expect<Equal<ParsePrintFormat<'The result is %h.'>, ['hex']>>,
Expect<Equal<ParsePrintFormat<'The result is %q.'>, []>>,
Expect<Equal<ParsePrintFormat<'Hello %s: score is %d.'>, ['string', 'dec']>>,
Expect<Equal<ParsePrintFormat<'The result is %'>, []>>,
]参考
无
