POJ 3371

一道模拟。。再次让我看见了我的代码能力有多垃圾。。。题目到不是很难,坑倒是不少。。以下是我写过的最丑的代码没有之一:

/*
Problem: 3371		User: Burglar
Memory: 704K		Time: 16MS
Language: G++		Result: Accepted
*/
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#define MAXN 1000
using namespace std;
char word[MAXN];
int len;
int is_sentance(char a)
{
    if(a=='.'|| a=='?'|| a==':'||a==';'||a=='!')
        return 1;
    else
        return 0;
}
int main()
{
    int words=0,sentances=0,syllable=0;
    double ans;
    int yes;
    int next_syllable;
    int add;
    while(scanf("%s",word)!=EOF)
    {
        next_syllable=syllable;
        yes=0;
        int s_len=strlen(word);
        len=0;
        add=0;
        for(int i=0;i<s_len;i++) if(word[i]<='Z'&&word[i]>='A') word[i]-=('A'-'a');
        for(int i=0;word[i]!='\0';i++)
        {
            if(word[i]<='z'&&word[i]>='a') len++;
            if(!(word[i]=='a'||word[i]=='e'||word[i]=='i'||word[i]=='o'||word[i]=='u'||word[i]=='y'))
            {
                yes=0;
            }
            if(word[i]=='a'||word[i]=='e'||word[i]=='i'||word[i]=='o'||word[i]=='u'||word[i]=='y')
            {
                if(word[i]!='e'&&yes==0)
                {
                   // printf("1\n");
                    syllable++;
                    yes++;
                }
                else if(word[i]=='e')
                {
                    //if(word[i+1]<='Z'&&word[i+1]>='A') word[i]-=('A'-'a');
                    if(i+1<s_len&&(word[i+1]!=','&&!is_sentance(word[i+1])))
                    {
                        if(i+2<s_len&&(word[i+2]!=','&&!is_sentance(word[i+2]))&&yes==0)
                        {
                          //  printf("2.1\n");
                            syllable++;
                            yes++;
                        }
                        else if(word[i+1]!='s'&&word[i+1]!='d'&&yes==0)
                        {
                          //  printf("2.2\n");
                            syllable++;
                            yes++;
                        }
                    }
                    else
                    {
                        if(word[i-1]=='l')
                        {
                        //    printf("3\n");
                            syllable++;
                            yes++;
                        }
                    }
                }
                else
                {
                    yes++;
                }
            }
            else if(word[i]==',')
            {
                words++;
                if(len<=3)
                {
                   // printf("4\n");
                    syllable=next_syllable+1;
                    next_syllable=syllable;
                    add=1;
                    len=0;
                }
                len=0;
                if(i+1==s_len) continue;
            }
            else if(is_sentance(word[i]))
            {
                words++;
                sentances++;
                if(len<=3)
                {
                   // printf("5\n");
                    syllable=next_syllable+1;
                    next_syllable=syllable;
                    add=1;
                    len=0;
                }
                len=0;
                if(i+1==s_len) continue;
            }
            if(i+1==s_len&&len<=3&&add==0)
            {
               // printf("6\n");
                syllable=next_syllable+1;
                next_syllable=syllable;
            }
        }
        if(word[s_len-1]<='z'&&word[s_len-1]>='a')
        {
            next_syllable=syllable;
            words++;
        }
        //printf("---------%d\n",syllable);
    }
    printf("%.2f\n",206.835-1.015*(double)words/(double)sentances-84.6*(double)syllable/(double)words);
    //printf("%d %d %d\n",words,sentances,syllable);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值