10921 - Find the Telephone
Moderator: Board moderators
10921 - Find the Telephone
*************code removed***************
Last edited by ranacse05 on Tue Apr 24, 2007 7:37 pm, edited 1 time in total.
I like to solve problems.
Try this input
My output is
Use code tag when you post code..
If you get AC, remove your code..![:-)](./images/smilies/icon_smile.gif)
Code: Select all
-1
Code: Select all
-1
Use code tag when you post code..
If you get AC, remove your code..
![:-)](./images/smilies/icon_smile.gif)
HERE is my coad again and i got WA again
*************code removed***************
how can i stop the input??
*************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.
what is the problem in this code??????
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 10921 - Find the Telephone
I NEED SOME CRITICAL INPUT.
CAN ANYONE HELP!!!!???
HOW TO INDICATE END OF FILE???
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
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 10921 - Find the Telephone
to indicate the end of file u can use:
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!!
Code: Select all
while(scanf("%s",string)==1)
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/
http://akanoi.webs.com/
-
- New poster
- Posts: 1
- Joined: Wed Feb 09, 2011 9:49 am
Re: 10921 - Find the Telephone
Last edited by MISTERKENTANG on Wed Jul 27, 2011 7:11 am, edited 1 time in total.
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10921 - Find the Telephone
You should change this line fromMISTERKENTANG 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; }
Code: Select all
for(a=0;a<=b;a++)
Code: Select all
for(a=0;a<b;a++)
![:D](./images/smilies/icon_biggrin.gif)
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?
-
- New poster
- Posts: 6
- Joined: Thu Dec 15, 2011 3:06 pm
runtime error in 10921
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;
}
# 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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: runtime error in 10921
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!
-
- New poster
- Posts: 6
- Joined: Thu Dec 15, 2011 3:06 pm
Re: runtime error in 10921
ya thanx......i got it.....
Re: 10921 - Find the Telephone
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10921 - Find the Telephone
Try reading one character at a time.
Check input and AC output for thousands of problems on uDebug!