11530 - SMS Typing

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

Moderator: Board moderators

naffi
New poster
Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm
Location: BUET, Bangladesh
Contact:

11530 - SMS Typing

Post by naffi »

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?
Last edited by naffi on Wed Oct 22, 2008 1:33 pm, edited 1 time in total.
Always At Your Help.
mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Re: WA: 11530: SMS Typing

Post by mmonish »

try this case..
Input:

Code: Select all

1
  a
Output:

Code: Select all

Case #1: 3
hope this helps..
naffi
New poster
Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm
Location: BUET, Bangladesh
Contact:

Re: WA: 11530: SMS Typing

Post by naffi »

Thanks, :). I got my problem and got AC.
Always At Your Help.
Bitta
New poster
Posts: 4
Joined: Fri Jan 25, 2008 7:04 pm
Location: Dhaka,Bangladesh
Contact:

Re: WA: 11530: SMS Typing

Post by Bitta »

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;
}

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Re: WA: 11530: SMS Typing

Post by shamim »

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:
apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

Re: WA: 11530: SMS Typing

Post by apurba »

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...
aum
New poster
Posts: 1
Joined: Wed Apr 15, 2009 12:29 pm

Re: 11530 - SMS Typing

Post by aum »

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.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 11530 - SMS Typing

Post by mf »

fflush(stdin) doesn't do anything.

Insert another getline right after cin>>t to eat a newline character.
nazmuldiu
New poster
Posts: 4
Joined: Wed Aug 05, 2009 6:05 pm

Re: 11530 - SMS Typing

Post by nazmuldiu »

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;
}
saiful_sust
Learning poster
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

Re: 11530 - SMS Typing

Post by saiful_sust »

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
samin_yasar
New poster
Posts: 5
Joined: Sat Mar 28, 2009 6:15 pm

Re: 11530 - SMS Typing

Post by samin_yasar »

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).
saiful_sust
Learning poster
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

Re: 11530 - SMS Typing

Post by saiful_sust »

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
Angeh
Experienced poster
Posts: 108
Joined: Sat Aug 08, 2009 2:53 pm

Re: 11530 - SMS Typing

Post by Angeh »

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;)
ruhul_sust
New poster
Posts: 5
Joined: Tue Jul 27, 2010 8:01 pm

11530 - sms typing -- Why WA???? :(

Post by ruhul_sust »

//help me to find d ERROR

#include<stdio.h>
#include<string.h>

void count(char a[], int x)
{

//scanf("%[ ^\n]", a);

gets(a);
//
// printf("Case #%d: ", x);
int i,length, n, sum=0;
length=strlen(a);
for(i=0; i<length; i++)
{
if(a=='a' || a=='d' || a=='g' || a=='j' || a=='m' || a=='p' || a=='t' || a=='w' || a==' ')
sum+=1;
else if(a=='b' || a[i]=='e' || a[i]=='h' || a[i]=='k' || a[i]=='n' || a[i]=='q' || a[i]=='u' || a[i]=='x')
sum+=2;
else if(a[i]=='c' || a[i]=='f' || a[i]=='i' || a[i]=='l' || a[i]=='o' || a[i]=='r' || a[i]=='v' || a[i]=='y')
sum+=3;
else if (a[i]=='s' || a[i]=='z')
sum+=4;
}
printf("%d\n", sum);
return;
}

int main()
{
char a[500];
int n, i;
scanf(" %d ", &n);
//scanf("\n");
// printf("0000000\n");

for(i=1;i<=n; i++)
{
// gets(a);
printf("Case #%d: ", i);
count(a, i);
}
// while()
return 0;
}
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11530 - sms typing -- Why WA???? :(

Post by sohel »

Use the search option located at the top right corner to find existing discussions of the problem.
In the search box, type 11530 and click on the search button next to it - you will find previous discussion on this problem.

Don't create a new thread for a problem that already exists. Make your post in an existing one.

Good Luck and keep solving!
Post Reply

Return to “Volume 115 (11500-11599)”