Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2014
    Posts
    6
    Rep Power
    0

    Default The Alphabet Sticker

    Hi everyone!

    I do not understand this problem .If anyone can help me I would appreciate it.

    Here is the statement:

    the link: 2. The Alphabet Sticker - A2 Online Judge

    I divided the problem into five cases: four specific cases and one general.

    Specific cases (respectively as in the program):

    Case 1: there is no question mark in the Statement

    Case 2: The question mark is at the beginning of the statement only

    Case 3: The question mark is located at the end of the statement only

    Case 4: there is only one lowercase letter in the statement

    *Case 5: General case (The other cases)

    here is my code (incomplete just to have an idea of ​​my approach)
    Java Code:
    import java.util.Scanner;
    	class Main{
    		public static void main(String[] args){
    			Scanner sc=new Scanner(System.in);
    			int T=sc.nextInt();
    			int p;
    			sc.nextLine();
    			String chaine=sc.nextLine();
    			char lettres[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    			int cptlettre[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    			int cpt=0;
    			int case1=0;
    			int case2=1;
    			int case3=1;
    			for(int i=0;i<(chaine.length);i++){
    				carac=chaine.charAt(i);
    				switch(carac){
    					case 'a':
    						cptlettre[0]=1;
    					break;
    					case 'b':
    						cptlettre[1]=1;
    					break;
    					case 'c':
    						cptlettre[2]=1;
    					break;
    					case 'd':
    						cptlettre[3]=1;
    					break;
    					case 'e':
    						cptlettre[4]=1;
    					break;
    					case 'f':
    						cptlettre[5]=1;
    					break;
    					case 'g':
    						cptlettre[6]=1;
    					break;
    					case 'h':
    						cptlettre[7]=1;
    					break;
    					case 'i':
    						cptlettre[8]=1;
    					break;
    					case 'j':
    						cptlettre[9]=1;
    					break;
    					case 'k':
    						cptlettre[10]=1;
    					break;
    					case 'l':
    						cptlettre[11]=1;
    					break;
    					case 'm':
    						cptlettre[12]=1;
    					break;
    					case 'n':
    						cptlettre[13]=1;
    					break;
    					case 'o':
    						cptlettre[14]=1;
    					break;
    					case 'p':
    						cptlettre[15]=1;
    					break;
    					case 'q':
    						cptlettre[16]=1;
    					break;
    					case 'r':
    						cptlettre[17]=1;
    					break;
    					case 's':
    						cptlettre[18]=1;
    					break;
    					case 't':
    						cptlettre[19]=1;
    					break;
    					case 'u':
    						cptlettre[20]=1;
    					break;
    					case 'v':
    						cptlettre[21]=1;
    					break;
    					case 'w':
    						cptlettre[22]=1;
    					break;
    					case 'x':
    						cptlettre[23]=1;
    					break;
    					case 'y':
    						cptlettre[24]=1;
    					break;
    					case 'z':
    						cptlettre[25]=1;
    					break;
    					default:;
    				}
    			}
    			for(int i=0;i<26;i++){
    				cpt=cpt+cptlettre[i]
    			}
    			for(int i=0;i<chaine.length;i++){
    				if ((chaine.charAt(i))=='?'){
    					case1=1;
    				}
    			}
    			if(case1=1)
    				p=1;
    			else if((chaine.charAt(0))=='?'){
    				for(int i=1;i<chaine.length;i++){
    					if((chaine.charAt(i))=='?')
    						case2=0;
    				}
    				if(case2==1)
    					p=1;
    				
    			}
    			else if((chaine.charAt(chaine.length))=='?'){
    				for(int i=0;i<((chaine.length)-1);i++){
    					if((chaine.charAt(i))=='?')
    						case3=0;
    				}
    				if(case3==1)
    					p=1;
    				
    			
    			}
    			else if (cpt==1){
    				p=1;			
    			}
    			else{
    			
    			}
    		}
    	}
    _____________________
    Thanks in advance

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default Re: The Alphabet Sticker

    Hi,

    Please understand your problem and then come up where you are stucking. It is highly impossible to guess/imagine what your problem is.
    Mak
    (Living @ Virtual World)

  3. #3
    Join Date
    Aug 2014
    Posts
    6
    Rep Power
    0

    Default Re: The Alphabet Sticker

    Quote Originally Posted by makpandian View Post
    Hi,

    Please understand your problem and then come up where you are stucking. It is highly impossible to guess/imagine what your problem is.
    Thanks for your important post.I think that I have detailed clearly my problem

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: The Alphabet Sticker

    Hint: You can do math with char values. 'a'+1 = 'b' and 'c' - 'a' = 2
    That would allow you to compute the array index instead of using the huge switch statement.

    Also it makes the program more friendly to use if it prints a message to the user before trying to read his input.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Aug 2014
    Posts
    6
    Rep Power
    0

    Default Re: The Alphabet Sticker

    Quote Originally Posted by Norm View Post
    Hint: You can do math with char values. 'a'+1 = 'b' and 'c' - 'a' = 2
    That would allow you to compute the array index instead of using the huge switch statement.

    Also it makes the program more friendly to use if it prints a message to the user before trying to read his input.
    Thanks for answering me. I can't print a message to the user before trying to read his input because the Online Judge may consider this as a fault.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: The Alphabet Sticker

    the Online Judge
    What's that? Why would a prompt before reading be a fault?
    Is the program supposed to be getting input from another program and not from a person?
    If from a person, then printing a message would be more user friendly.

    Another hint: the variables should have names that describe what they contain. case1, etc doesn't say anything.
    The caseX variables look like they will only have two values: 0 and 1. If so, they should be boolean with values of true and false.
    Last edited by Norm; 08-25-2014 at 11:08 PM.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    Aug 2014
    Posts
    6
    Rep Power
    0

    Default Re: The Alphabet Sticker

    Quote Originally Posted by Norm View Post
    What's that? Why would a prompt before reading be a fault?
    Is the program supposed to be getting input from another program and not from a person?
    If from a person, then printing a message would be more user friendly.

    Another hint: the variables should have names that describe what they contain. case1, etc doesn't say anything.
    The caseX variables look like they will only have two values: 0 and 1. If so, they should be boolean with values of true and false.

    The Online Judge is like Usacoo training Gateway, uva Online Judge, Ahmed Aly Online Judge. A sort of an Online corrector:
    Usaco Training Gateway: http://cerberus.delosent.com:791/usacogate
    Uva Online Judge : UVa Online Judge - Home
    Ahmed Aly Online Judge: A2 Online Judge

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: The Alphabet Sticker

    Whatever.
    For testing I'd recommend hard coding the values in the program until you get the logic working. That will make for consistent values while debugging.
    After that change it to read the values.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. get a string's first alphabet.
    By noobplus in forum New To Java
    Replies: 1
    Last Post: 07-13-2013, 02:19 PM
  2. Replies: 2
    Last Post: 11-08-2010, 08:01 AM
  3. Incremented alphabet
    By ashin in forum New To Java
    Replies: 1
    Last Post: 10-07-2010, 12:36 PM
  4. Alphabet timer help.
    By kosok in forum New To Java
    Replies: 2
    Last Post: 12-24-2008, 06:05 PM
  5. Listing the alphabet (beginner)
    By SuperOnion in forum New To Java
    Replies: 3
    Last Post: 12-22-2008, 03:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •