poj 3602-字符串模拟
来源:互联网 发布:吴江司法拍卖淘宝网 编辑:程序博客网 时间:2024/06/08 18:00
Description
Typesetting involves the presentation of textual material in graphic form on paper or some other medium. Close as it is related to our daily life, typesetting exhibits certain complexities which may be unfamiliar and sometimes unimaginable to the layman. The use of typographical ligatures is one such complexity.
Compare the two appearances of the word “define” in Figure 7. Figure 7(a) illustrates the word typeset with the “fi” ligature as Knuth’s TeX does. The letters “f” and “i” are combined into a single glyph. Figure 7(b) shows the word typeset without the ligature as Microsoft Word does. The letters “f” and “i” remain separate. Other examples include the “ff”, “ffi”, “fl” and “ffl” ligatures, as shown in Figure 8. Perhaps the most notable ligature in active use is the “&” (ampersand), which originated from “et”, the Latin word for “and”.
Figure 7: The word “define” typeset with and without the “fi” ligature
Figure 8: Examples of the “ff”, “ffi”, “fl” and “ffl” ligatures
Ligatures are primarily intended to improve spacing between letters. Despite that their impact on legibility is debated and that their use is declining, some people insist that they are an essential part of quality typesetting. In order to typeset ligatures, separate glyphs have to be used since ligatures generally differ from direct combinations of their constituent letters in most cases.
Given some text, count the number of glyphs that have to be used to typeset it. Only the “ff”, “fi”, “ffi”, “fl”, and “ffl” ligatures are considered. Note that they are case-sensitive. Ligatures are recognized following the leftmost longest rule—find the leftmost match, then the longest match if there are any ties. Each distinct letter, ligature or punctuation mark requires a separate glyph. However, if a letter appears only in ligatures and nowhere else, it shall not be assigned a glyph. Furthermore, left single and double quotes differ from their right counterparts. Spaces do not require a glyph.
Input
The input contains a single test case consisting of some text. The text is given on multiple lines not longer than 100 characters each. The text contains only letters (lowercase and uppercase), punctuation marks and spaces. Punctuation marks include periods, commas, semicolons, colons, single and double quotes, exclamation and question marks. Quotes are represented by “`” (left single quote), “'” (right single quote), “``” (left double quote) and “''” (right double quote), respectively. They are also recognized following the leftmost longest rule. The input ends where EOF is met.
Output
Print the number of glyphs that have to be used to typeset the given text.
Sample Input
```define, effect; office.reflect? waffle!'''
Sample Output
23
代码:
#include<stdio.h>#include<string.h>char s[1000];int count[1000];int ff[7];int len;void solve(){int ans=0;memset(count,0,sizeof(count));memset(ff,0,sizeof(ff));for(int i=0;i<len;i++){if(s[i]=='f'){if(s[i+1]=='f' && (s[i+2]=='i' || s[i+2]=='l')){if(s[i+2]=='i'){ff[2]++;}if(s[i+2]=='l'){ff[4]++;}i+=2;}else if(s[i+1]=='f'){ff[0]++;i+=1;}else if(s[i+1]=='i' || s[i+1]=='l'){if(s[i+1]=='i')ff[1]++;if(s[i+1]=='l')ff[3]++;i++;}else count[s[i]]++;}else if(s[i]=='`' && s[i+1]=='`'){ff[6]++;i++;}else if(s[i]=='\'' && s[i+1]=='\''){ff[5]++;i++;}else count[s[i]]++;}for(int i=0;i<=256;i++){if(count[i])ans++;}for(int i=0;i<7;i++)if(ff[i])ans++;printf("%d\n",ans);}int main(){char c;len=0;while(scanf("%c",&c)!=EOF){if(c==' ' || c=='\n')continue;s[len++]=c;}//printf("%s",s);solve();}
- poj 3602-字符串模拟
- POJ 1002 (字符串 && 模拟)
- POJ 3972 BF (字符串模拟)
- POJ 1035(字符串模拟)
- POJ-1028(字符串模拟)
- POJ 3652 Persistent Bits 简单字符串模拟
- POJ 3095 Linear Pachinko 字符串模拟
- POJ 3852 StringLD 左字符串模拟
- POJ 1035 Spell checker (字符串模拟)
- 字符串 模拟 Spell checker (poj 1035)
- POJ 3573 I18n (字符串模拟)
- poj Babelfish 2503 (字符串模拟)
- POJ 1555 Polynomial Showdown(字符串模拟)
- poj 2408 字符串模拟题(值得回顾)。
- POJ 1107 : W\'s Cipher - 密码,字符串模拟
- poj 2334 Simple prefix compression(模拟/字符串处理)
- POJ-3087- Shuffle'm Up(字符串模拟)
- 字符串模拟
- php数据库备份脚本
- 关于 chekpoint
- 让我生不如死的Windows CE内存泄漏
- 数据库索引、主键区别【微谈】
- 35+多用途WordPress主题
- poj 3602-字符串模拟
- Android蓝牙开发浅析
- 举例说明IKAanlyzer分词
- 关于TP-LINK宽带路由器上的“转发规则”功能用途及设置办法
- spring 国际化配置
- Windows CE OAL层的结构与开发
- java实现线程安全的单利模式
- Linux platform中用到的数据结构分析
- 在Windows CE下实现拨号上网