ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1567. SMS-spam

what wrong?!
Posted by Gelioscope 28 Jun 2011 01:32
#include <stdio.h>
#include <string.h>
#define ulong unsigned long
void main ()
{
#ifndef ONLINE_JUDGE
    freopen("Data.txt","rt",stdin);
    freopen("Output.txt","wt",stdout);
#endif
    char slogan[1001];
    ulong cost=0,i;
    fgets(slogan,1001,stdin);
    for(i=0;i<strlen(slogan);++i)
    {
        if(slogan[i]>='a'&&slogan[i]<='z')
        {
            if((slogan[i]-'a')%3==0)
            {
                ++cost;
                continue;
            }
            if((slogan[i]-'a')%3==1)
            {
                cost+=2;
                continue;
            }
            cost+=3;
            continue;
        }
        if(slogan[i]==' '||slogan[i]=='.')
        {
            ++cost;
            continue;
        }
        if(slogan[i]==',')
        {
            cost+=2;
            continue;
        }
        cost+=3;
    }
    printf("%lu",cost);
}
why i get wa1?!

Edited by author 28.06.2011 01:33
Re: what wrong?!
Posted by Gelioscope 28 Jun 2011 03:50
Ok, i got ac. The thing was that fgets reads also '\n' and handled it as '!', before finish the program. But i don't understand why simple printf("%lu",cost-3) was not enough and had to append the condition? In fact, all the other possibilities characters are handled above...