11530 - SMS Typing

All about problems in Volume CXV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

11530 - SMS Typing

Postby naffi » Tue Oct 21, 2008 11:14 pm

I am frustrated about this easy problem. WA and WA, but can not find the error. Can anybody help me? Is there any critical IO?

Code: Select all
Last edited by naffi on Wed Oct 22, 2008 1:33 pm, edited 1 time in total.
Always At Your Help.
naffi
New poster
 
Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm
Location: BUET, Bangladesh

Re: WA: 11530: SMS Typing

Postby mmonish » Wed Oct 22, 2008 2:51 am

try this case..
Input:
Code: Select all
1
  a

Output:
Code: Select all
Case #1: 3

hope this helps..
mmonish
Experienced poster
 
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Re: WA: 11530: SMS Typing

Postby naffi » Wed Oct 22, 2008 1:33 pm

Thanks, :). I got my problem and got AC.
Always At Your Help.
naffi
New poster
 
Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm
Location: BUET, Bangladesh

Re: WA: 11530: SMS Typing

Postby Bitta » Tue Nov 18, 2008 3:22 pm

I am getting WA.Plz help me...
Code: Select all
#include<stdio.h>

int main()
{
   char s[103];
   int i,cnt,tc,n;

   scanf("%d",&tc);

   n=1;

   while(tc>0)
   {   
      fflush(stdin);
      gets(s);

      cnt=0;
      for(i=0;s[i];i++)
      {
         if(s[i]=='a' || s[i]=='d' || s[i]=='g' || s[i]=='j' || s[i]=='m' || s[i]=='p' || s[i]=='t' || s[i]=='w' || s[i]==' ')
         {
            cnt+=1;
         }

         else if(s[i]=='b' || s[i]=='e' || s[i]=='h' || s[i]=='k' || s[i]=='n' || s[i]=='q' || s[i]=='u' || s[i]=='x')
         {
            cnt+=2;
         }

         else if(s[i]=='c' || s[i]=='f' || s[i]=='i' || s[i]=='l' || s[i]=='o' || s[i]=='r' || s[i]=='v' || s[i]=='y')
         {
            cnt+=3;
         }

         else if(s[i]=='s' || s[i]=='z')
         {
            cnt+=4;
         }
      }

      printf("Case #%d: %d\n",n,cnt);
      n++;
      tc--;
      
   }

   return 0;
}

Bitta
New poster
 
Posts: 4
Joined: Fri Jan 25, 2008 7:04 pm
Location: Dhaka,Bangladesh

Re: WA: 11530: SMS Typing

Postby shamim » Wed Nov 19, 2008 1:00 pm

Just add a dummy gets after you take the number of cases as input and remove the fflush().

This should get your code AC :wink:
User avatar
shamim
A great helper
 
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Dhaka

Re: WA: 11530: SMS Typing

Postby apurba » Sat Mar 21, 2009 11:34 am

shamim wrote:Just add a dummy gets after you take the number of cases as input and remove the fflush().

This should get your code AC :wink:


Code: Select all
thanks a lot.........
Code: Select all
keep dreaming...
apurba
New poster
 
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm
Location: In Front of Computer

Re: 11530 - SMS Typing

Postby aum » Wed Apr 15, 2009 12:36 pm

Hi everyone,

I am getting WA in this problem. This is how i accept the input
Code: Select all
# include <iostream>
# include <string>

using namespace std;

int main()
{
    int t,c = 0;
    cin>>t;
   
    //do something here
   
    fflush(stdin);
    string inp;
   
    while(t--)
    {
        getline(cin,inp);

        //do something here       

        cout<<"Case #"<<++c<<": "<<res<<endl;
    }
   
 return 0;   
}



I am sure that my algorithm is correct. i think i am getting WA because i am not accepting input properly.
Please help.
aum
New poster
 
Posts: 1
Joined: Wed Apr 15, 2009 12:29 pm

Re: 11530 - SMS Typing

Postby mf » Wed Apr 15, 2009 4:28 pm

fflush(stdin) doesn't do anything.

Insert another getline right after cin>>t to eat a newline character.
mf
Guru
 
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland

Re: 11530 - SMS Typing

Postby nazmuldiu » Sun Sep 13, 2009 1:47 pm

Why My code getting WA please?
Code: Select all
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    int n[26]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4};
    char b[150];
    int a=0,t;

    cin>>t;
    for(int j=0;j<t;j++)
    {
        a=0;
      getchar();
        gets(b);
        for(int i=0;b[i];i++)
        {
            if(b[i]==32)
                a++;
            else
                a+=n[b[i]-'a'];

        }
        cout<<"Case #"<<j<<": "<<a<<endl;
    }
    return 0;
}
nazmuldiu
New poster
 
Posts: 4
Joined: Wed Aug 05, 2009 6:05 pm

Re: 11530 - SMS Typing

Postby saiful_sust » Sun Sep 13, 2009 8:49 pm

Hello nazmul..........
just change this line:
Code: Select all
 cout<<"Case #"<<j<<": "<<a<<endl;


To:
Code: Select all
 cout<<"Case #"<<j+1<<": "<<a<<endl;

:lol: :lol: :lol:
    IMPOSSIBLE MEANS I M POSSIBLE
saiful_sust
Learning poster
 
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

Re: 11530 - SMS Typing

Postby samin_yasar » Tue Sep 15, 2009 9:28 am

Code: Select all
#include <stdio.h>

int main()
{
   int test;
   char str[100];
        scanf("%d",&test);
   //fflush(stdin);
   for(int i=0;i<test;i++)
   {
      gets(str);

      int j=0,count=0;
      
      while(str[j]!='\0')
      {

if(str[j]==' ')count+=1;
else if(str[j]=='a' || str[j]=='d' || str[j] == 'g' || str[j] =='j' || str[j]=='m' || str[j] == 'p' || str[j] == 't' || str[j] =='w')count+=1;
else if(str[j]=='b' || str[j]=='e' || str[j] == 'h' || str[j] =='k' || str[j]=='n' || str[j] == 'q' || str[j] == 'u' || str[j] =='x')count+=2;
else if(str[j]=='c' || str[j]=='f'  || str[j] == 'i' || str[j] =='l' || str[j]=='o' || str[j] == 'r' || str[j] == 'v' || str[j] == 'y')count+=3;
else count+=4;
j++;
}
printf("Case %d: %d\n",i+1,count);
}
return 0;

}


would someone please tell me what is wrong with this code?
i submitted without fflush(stdin).
samin_yasar
New poster
 
Posts: 5
Joined: Sat Mar 28, 2009 6:15 pm

Re: 11530 - SMS Typing

Postby saiful_sust » Wed Sep 16, 2009 12:34 am

Hello samin

change this line
Code: Select all
printf("Case %d: %d\n",i+1,count);

To
Code: Select all
printf("Case #%d: %d\n",i+1,count);



:D :D :D
saiful_sust
Learning poster
 
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

Re: 11530 - SMS Typing

Postby Angeh » Mon Sep 28, 2009 7:42 pm

scanf("%d%d\n",&n,&m) reads not only new line character but leading spaces in second line.
use scanf("%d%d",&n,&m);gets(line) instead ;
>>>>>>>>> A2
Beliefs are not facts, believe what you need to believe;)
Angeh
Experienced poster
 
Posts: 108
Joined: Sat Aug 08, 2009 2:53 pm


Return to Volume CXV

Who is online

Users browsing this forum: No registered users and 1 guest