10921 - Find the Telephone

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

Moderator: Board moderators

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

10921 - Find the Telephone

Post by ranacse05 » Tue Apr 10, 2007 10:41 am

*************code removed***************
Last edited by ranacse05 on Tue Apr 24, 2007 7:37 pm, edited 1 time in total.
I like to solve problems.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Tue Apr 10, 2007 10:57 am

Try this input

Code: Select all

-1
My output is

Code: Select all

-1

Use code tag when you post code..
If you get AC, remove your code.. :-)

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Post by ranacse05 » Fri Apr 13, 2007 10:11 am

HERE is my coad again and i got WA again

*************code removed***************
how can i stop the input??
Last edited by ranacse05 on Tue Apr 24, 2007 7:40 pm, edited 1 time in total.
I like to solve problems.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Fri Apr 13, 2007 10:58 am

Try this case.. what do you get..?

Code: Select all

-1ABC

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Post by ranacse05 » Sat Apr 14, 2007 9:48 am

Ya i tryed that but the output was unexpected.Should i break then?How i change it?plz help me i cant get any solution
I like to solve problems.

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

what is the problem in this code??????

Post by abid_iut » Wed Sep 17, 2008 11:58 am

Pls Help :(

Code: Select all

Removed after AC
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 10921 - Find the Telephone

Post by sazzadcsedu » Wed Dec 03, 2008 8:10 am

I NEED SOME CRITICAL INPUT.

CAN ANYONE HELP!!!!???

HOW TO INDICATE END OF FILE???
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10921 - Find the Telephone

Post by abid_iut » Wed Dec 03, 2008 7:57 pm

to indicate the end of file u can use:

Code: Select all

while(scanf("%s",string)==1)
actually this problem is quite easy,
only print the corresponding number for the character encountered and print the same thing if it is not a character given in the table.
finish!!
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

MISTERKENTANG
New poster
Posts: 1
Joined: Wed Feb 09, 2011 9:49 am

Re: 10921 - Find the Telephone

Post by MISTERKENTANG » Wed Feb 09, 2011 9:53 am

pls help... got WA

Code: Select all

GOT ACCEPTED
Last edited by MISTERKENTANG on Wed Jul 27, 2011 7:11 am, edited 1 time in total.

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10921 - Find the Telephone

Post by DD » Mon Mar 14, 2011 12:15 am

MISTERKENTANG wrote:pls help... got WA

Code: Select all

#include<cstdio>
#include<iostream>
using namespace std;
char kalimat[40];
int a,b;
int main()
{

    while(scanf("%s",&kalimat)==1)
    {
        b=strlen(kalimat);
        for(a=0;a<=b;a++)
        {
            switch(kalimat[a])
            {    
                 case 'A': {printf("2");break;}
                 case 'B': {printf("2");break;}
                 case 'C': {printf("2");break;}
                 case 'D': {printf("3");break;}
                 case 'E': {printf("3");break;}
                 case 'F': {printf("3");break;}
                 case 'G': {printf("4");break;}
                 case 'H': {printf("4");break;}
                 case 'I': {printf("4");break;}
                 case 'J': {printf("5");break;}
                 case 'K': {printf("5");break;}
                 case 'L': {printf("5");break;}
                 case 'M': {printf("6");break;}
                 case 'N': {printf("6");break;}
                 case 'O': {printf("6");break;}
                 case 'P': {printf("7");break;}
                 case 'Q': {printf("7");break;}
                 case 'R': {printf("7");break;}
                 case 'S': {printf("7");break;}
                 case 'T': {printf("8");break;}
                 case 'U': {printf("8");break;}
                 case 'V': {printf("8");break;}
                 case 'W': {printf("9");break;}
                 case 'X': {printf("9");break;}
                 case 'Y': {printf("9");break;}
                 case 'Z': {printf("9"); break;}
                 default: {printf("%c",kalimat[a]);break;}
            }           
        }
        printf("\n");
    }
    return 0;
}
You should change this line from

Code: Select all

for(a=0;a<=b;a++)
to

Code: Select all

for(a=0;a<b;a++)
Good luck! :D
Have you ever...
  • Wanted to work at best companies?
  • Struggled with interview problems that could be solved in 15 minutes?
  • Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.

nebulousboy
New poster
Posts: 6
Joined: Thu Dec 15, 2011 3:06 pm

runtime error in 10921

Post by nebulousboy » Thu Dec 15, 2011 5:00 pm

why do i get a runtime error in this code...

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

int main()
{
char a[30];
int i,j;

while(gets(a))
{
j=strlen(a);
for(i=0;i<j;i++)
{
if(a>64 && a<=67)
a='2';
else if(a>67 && a<=70)
a='3';
else if(a>70 && a<=73)
a='4';
else if(a>73 && a[i]<=76)
a[i]='5';
else if(a[i]>76 && a[i]<=79)
a[i]='6';
else if(a[i]>79 && a[i]<=83)
a[i]='7';
else if(a[i]>83 && a[i]<=86)
a[i]='8';
else if(a[i]>86 && a[i]<=90)
a[i]='9';
}
printf("%s\n",a);
}

return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: runtime error in 10921

Post by brianfry713 » Fri Dec 16, 2011 8:00 pm

Make array a at least size 31, don't forget about the null character at the end of a string. Try using fgets or scanf instead of gets.
Check input and AC output for thousands of problems on uDebug!

nebulousboy
New poster
Posts: 6
Joined: Thu Dec 15, 2011 3:06 pm

Re: runtime error in 10921

Post by nebulousboy » Sat Dec 17, 2011 8:30 am

ya thanx......i got it.....

CyberPunk
New poster
Posts: 7
Joined: Sat Mar 02, 2013 11:11 pm

Re: 10921 - Find the Telephone

Post by CyberPunk » Fri Mar 08, 2013 4:46 pm

Why do I get WA for this?

Code: Select all

#include <stdio.h>
#include <string.h>
int main()
{
    char s[32767];
    int i,j,k,l,len;
    while(scanf("%s",s)!=EOF) {
        len=strlen(s);
        for(i=0;i<len;i++) {
            if(s[i]>=65 && s[i]<68) s[i]='2';
            else if(s[i]>=68 && s[i]<71) s[i]='3';
            else if(s[i]>=71 && s[i]<74) s[i]='4';
            else if(s[i]>=74 && s[i]<77) s[i]='5';
            else if(s[i]>=77 && s[i]<80) s[i]='6';
            else if(s[i]>=80 && s[i]<84) s[i]='7';
            else if(s[i]>=84 && s[i]<87) s[i]='8';
            else if(s[i]>=87 && s[i]<90) s[i]='9';
            else ;
        }
        printf("%s\n",s);
    }
    return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10921 - Find the Telephone

Post by brianfry713 » Fri Mar 08, 2013 10:14 pm

Try reading one character at a time.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 109 (10900-10999)”