加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

POJ PKU 3602 模拟

(2010-04-13 23:48:04)
标签:

it

分类: 杂题

题目描述:

输入一段文字,ff, ffi, ffl, fi, fl, '', ``这7种组合出现的时候可以算作一种,并且必须算作新的字符,问你这段文字需要多少种字符。

解题报告:

纯粹模拟。

代码:

#include<iostream>
using namespace std;
char c;
bool vst[200], vst2[7];
int ans, state;//1 f 2fi 3 ff 4 ffi 5 fl 6 ffl
void judge(char x)
{
    if (x == EOF)
        return;
    if (!vst[x])
        vst[x] = 1, ans ;
}
void judge2(int pos)
{
    if (!vst2[pos])
        vst2[pos] = 1, ans ;
}
int main()
{
    memset(vst, 0, sizeof(vst));
    memset(vst2, 0, sizeof(vst2));
    ans = state = 0;
    while(true)
    {
        c = getchar();
        if (c == ' ' || c == '\n')
            continue;
        if (!state)
        {
            if (c == 'f')
               state = 1;
            else if (c == '`')
                state = 4;
            else if (c == '\'')
                state = 5;
            else
                judge(c);
        }
        else if (state == 1)
        {
            if (c == 'i')
            {
                judge2(2);
                state = 0;
            }
            else if (c == 'f')
                state = 3;
            else if (c == 'l')
            {
                judge2(5);
                state = 0;
            }
            else
            {
                state = 0;
                judge('f');
                if (c == '`')
                    state = 4;
                else if (c == '\'')
                    state = 5;
                else
                    judge(c);
            }
        }
        else if (state == 3)
        {
            if (c == 'i')
            {
                state = 0;
                judge2(4);
            }
            else if (c == 'l')
            {
                state = 0;
                judge2(6);
            }
            else if (c == 'f')
            {
                state = 1;
                judge(3);
            }
            else
            {
                state = 0;
                judge2(3);
                if (c == '`')
                    state = 4;
                else if (c == '\'')
                    state = 5;
                else
                    judge(c);
            }
        }
        else if (state == 4)
        {
            state = 0;
            if (c == '`')
                judge2(0);
            else if (c == '\'')
            {
                judge('`');
                state = 5;
            }
            else
            {
                judge('`');
                if (c == 'f')
                    state = 1;
                else
                    judge(c);
            }
        }
        else if (state == 5)
        {
            state = 0;
            if (c == '\'')
                judge2(1);
            else if (c == '`')
            {
                judge('\'');
                state = 4;
            }
            else
            {
                judge('\'');
                if (c == 'f')
                    state = 1;
                else
                    judge(c);
            }
        }
        if (c == EOF)
            break;

    }
    printf("%d\n", ans);
    return 0;
}

0

阅读 收藏 喜欢 打印举报/Report
前一篇:2010-04-13
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有