当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3583:Text Message Formatting

题目描述

frkstyc has always wanted POJ to have a multiligual user interface. He has considered several schemes to implement the functionalities. Unfortunately, he has been occupied during the recent months, which prevents him from working on the development of POJ. Still, he would like to share some of his ideas in the hope that someone could finish the work for him.

One challenge in implementing a multilingual user interface is the manipulation of text messages. As you can easily identify, POJ has been developed with English as the primary language in its user interface. Hundreds of text messages that appear in web pages scatter in tens of source files as string resources. Isolating these string resources in the source files to faciliate the use of a unified programming interface for multilingualism support is itself a tedious and time-comsuming job and frequently triggers dismay in frkstyc. Besides, there are still some subtleties concerning differences between languages.

One particular such tricky aspect in which frkstyc is interested is word order. Consider the caption of the table in the page of Login Log. In English, it shall read “Last num login attempts by user”, where user appears after num. In Chinese, in contrast, it shall read “user的最后num次登录尝试”, where user appears before num. Such difference causes complexity. You may argue that the caption in English can be changed to “user’s last num login attempts” to avoid the trouble with Chinese. However, in the case of Spanish, it may not be that easy to reorder the words in “Los últimos num intentos de user por acceder” as in English.

frkstyc’s proposed solution is rather simplistic. He uses format strings with numbered placeholders. Take the aforementioned text messages for example. frkstyc creates the following three format strings

  • Last {1} login attempts by {2}
  • {2}的最后{1}次登录尝试
  • Los últimos {1} intentos de {2} por acceder

where {1} and {2} are the numbered placeholders. By supplying a format string and the array of arguments [num, user] to a formatting function which replaces {1} with num and {2} with user, frkstyc always gets desired result regardless of the choice of language. Furthermore, the backslash is designated as the escape character. An unescaped backslash escapes the immediately following character, which shall be directly copied to the output and not further processed. A placeholder is recognized if none of its comprised characters is escaped and the number immediately surrounded by braces is a valid 1-based index into the array of arguments. A recognized placeholder shall be replaced in the output by array element indexed by the number in braces.

frkstyc recognizes writing the formatting function as the only fun part in implementing the envisioned multilingualism support. He delightfully invites you to share such joy by also writing the function.

输入解释

The input consists of a single test case. The test case contains at most 1001 lines, each being a string of at most 80 printable ASCII characters. The first string is the format string. The rest comprises the array of arguments.

输出解释
The output shall contain only the formatted string.
输入样例
Last {1} login attempts by {2}
20
frkstyc
输出样例
Last 20 login attempts by frkstyc

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3583

最后修改于 2020-10-29T07:05:12+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536