UVA 4879 Old Fafhioned Typefetting(易WA细节题)

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

 

一、问题:

Description

In Olden Days, before digital typesetting (before Babbage, even), typesetting was an art, practiced by highly skilled craftsmen. Certain character combinations, such as a-e or f-i were typeset as a single character, called a ligature, to save space and to make the characters look better together on the printed page (the ligatures for a-e and f-i were `a e' and `f i', respectively; the table on the next page, lists all possible ligature combinations).
In addition, there were two different versions of the lowercase letter s: the ``long s" (ß) and the ``short s". Only the short s is used today. The rules for when to use which version are odd, but straightforward:

 

  1. Short s is used at the end of a word, or before punctuation within a word, such as a hyphen or apostrophe: programs, success, hocus-pocus, revis'd. (programs, ßucceßs, hocus-pocus, revis'd)
  2. Short s is used before the letters `f', `b', or `k': transfer, husband, ask, successful. (transfer, husband, ask, ßucceßsful)
  3. Long s is used everywhere else, except...
  4. It is possible that a compound word consists of a word ending in a double s followed by a word beginning with s (this is the only situation where the sequence ``sss" occurs in English text). In this case, the middle s is set short and the other two are set long: crossstitch, crossstaff. (croßsßtitch, croßsßaf f)

UVA 4879 Old Fafhioned Typefetting(易WA细节题)

Note that a “word” is not the same thing as an “identifier.” While identifiers can contain punctuation marks such as ‘ ’ or ‘$’, words can contain only letters (at least as far as typographers are concerned). Therefore, identifiers like “radius3” and “ adios amigo” would be typeset as “radius3” and “adios amigo,” respectively, rather than “radiuß3” and “adioß amigo.”

 

Input

The first line of input contains a single integer P (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of a single line containing the data set number, followed by a space, followed by a string of no more than 1000 characters.

 

Output

For each data set, print the data set number, a space, and the input string, with the appropriate ligature and ``long s" codes substituted into the string.
The table on the next page shows the code strings to use for each symbol or ligature (note that the short s remains unchanged on output; note also that `A E' and `O E' are the only uppercase ligatures):

Note that the rules for the use of long and short s can combine with these ligatures in interesting (and not always obvious) ways. For example, the input word ‘crossstitch’ becomes ‘cro[longs]s[longst]itch’, not ‘cro[longs]s[longs]titch’.

 

Sample Input

3 
1 Last night, we went to see 
2 "Oedipus Rex" at the 
3 AEgyptian's theater.

 

Sample Output

1 La[longst] night, we went to [longs]ee 
2 "[OE]dipus Rex" at the 
3 [AE]gyptian's theater.

 

二、题意:

对于每组样例给出的串,按照相应要求进行对应的变换。

 

三、思路:

特殊情况是真 tm 多啊这题... WA了好几发...

注意:

1)AE / Ae / aE,都要转换为[AE]输出,但ae要转换成[ae];

同理: OE / Oe / oE,都要转换为[OE]输出,但oe要转换成[oe]。(如样例2)。

2)特殊的s,关键就在s的处理上了。。

首先,sss的情况,按照中间的是short s,两边的是long s处理。

其次,si / sh / sl / st / ss / ssi的情况,这里边的s都要是long s才可以合并。

然后,每个单词末尾的s,或者s后面紧跟着 f / b / k 的按short s处理。

还有,它说的 word 和 identifier 的区别,判断特殊字符用 a[ i ] < 'a'  ||  a[ i ] > 'z'就可以。

3)另外还要注意,在找是否可以合并的时候,不要数组越界。

4)还有.... 循环里也有i++,不要移多了...

 

我的思路是:

先开一个 vis 数组,把long s对应的标记为1,short s 不作处理。

然后先从是否可以3个一起合并开始判,可以合并的话把下标往后移然后直接continue,不能合并了3个的再合并两个的。

如果3个的不能合并再判两个能合并的,也不能合的话就直接输出这个字符 (如果是s再判是不是long s)。

 

四、代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define read(x) scanf("%d",&x)
#define mem(a,b) memset(a,0,sizeof(a))
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define fork(a,b) for(int k=a;k<=b;k++)

using namespace std;
typedef long long LL;

int main()
{
    int T, k;
    char a[1010];
    bool vis[1010];
    read(T);
    while(T--)
    {
        mem(vis,0);
        read(k);
        getchar();
        gets(a);
        int len = strlen(a);
        printf("%d ",k);
        fori(0, len-1)
        {
            bool flag = 0;
            if(a[i] == 's')
            {
                if(i+1 <= len-1)
                {
                    if(a[i+1] == ' '|| a[i+1] == 'f' || a[i+1] == 'b' || a[i+1] == 'k' || a[i+1] < 'a' || a[i+1] > 'z')
                        flag = 1;
                }
                else if(i == len-1)
                    flag = 1;
                if(!flag)
                    vis[i] = 1;
            }
        }
        fori(0, len-1)
        {
            if(i+2 <= len-1)
            {
                if(a[i] == 's' && a[i+1] == 's' && a[i+2] == 's')
                {
                    printf("[longs]s");
                    i++;
                    continue;
                }
                else if(a[i] == 's' && vis[i] && a[i+1] == 's' && vis[i+1] && a[i+2] == 'i')
                {
                    printf("[longssi]");
                    i += 2;
                    continue;
                }
                else if(a[i] == 'f' && a[i+1] == 'f' && a[i+2] == 'l')
                {
                    printf("[ffl]");
                    i += 2;
                    continue;
                }
                else if(a[i] == 'f' && a[i+1] == 'f' && a[i+2] == 'i')
                {
                    printf("[ffi]");
                    i += 2;
                    continue;
                }
            }
            if(i+1 <= len-1)
            {
                if((a[i] == 'A' && a[i+1] == 'E') || (a[i] == 'A' &&a[i+1] == 'e') || (a[i] == 'a' &&a[i+1] == 'E'))
                {
                    printf("[AE]");
                    ++i;
                    continue;
                }
                else if(a[i]=='a' && a[i+1]=='e')
                {
                    printf("[ae]");
                    ++i;
                    continue;
                }
                else if((a[i]=='O' && a[i+1]=='E') || (a[i]=='O' && a[i+1]=='e') || (a[i] == 'o' && a[i+1] == 'E'))
                {
                    printf("[OE]");
                    ++i;
                    continue;
                }
                else if(a[i] == 'o' && a[i+1] == 'e')
                {
                    printf("[oe]");
                    ++i;
                    continue;
                }
                else if(a[i] == 'c' && a[i+1] == 't')
                {
                    printf("[ct]");
                    ++i;
                    continue;
                }
                else if(a[i] == 'f' && a[i+1] == 'f')
                {
                    printf("[ff]");
                    ++i;
                    continue;
                }
                else if(a[i] == 'f' && a[i+1] == 'i')
                {
                    printf("[fi]");
                    ++i;
                    continue;
                }
                else if(a[i] == 'f' && a[i+1] == 'l')
                {
                    printf("[fl]");
                    ++i;
                    continue;
                }
                else if(a[i] == 's' && vis[i] && a[i+1] == 'i')
                {
                    printf("[longsi]");
                    ++i;
                    continue;
                }
                else if(a[i] == 's' && vis[i] && a[i+1] == 'h')
                {
                    printf("[longsh]");
                    ++i;
                    continue;
                }
                else if(a[i] == 's' && vis[i] && a[i+1] == 'l')
                {
                    printf("[longsl]");
                    ++i;
                    continue;
                }
                else if(a[i] == 's' && vis[i] && vis[i+1] && a[i+1] == 's')
                {
                    printf("[longss]");
                    ++i;
                    continue;
                }
                else if(a[i] == 's' && vis[i] && a[i+1] == 't')
                {
                    printf("[longst]");
                    ++i;
                    continue;
                }
            }
            if(a[i] == 's')
            {
                if(vis[i])
                    printf("[longs]");
                else
                    printf("s");
            }
            else
                printf("%c",a[i]);
        }
        printf("\n");
    }
    return 0;
}

 

 

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

上一篇:中国石油大学天梯赛真题模拟第五场


下一篇:CSU-1982 小M的移动硬盘