1. Member
Join Date
Aug 2014
Posts
6
Rep Power
0

## 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{

}
}
}```
_____________________

2. ## 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.

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

## Re: The Alphabet Sticker

Originally Posted by makpandian
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. ## 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.

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

## Re: The Alphabet Sticker

Originally Posted by Norm
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. ## 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.

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

## Re: The Alphabet Sticker

Originally Posted by Norm
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. ## 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.

#### Posting Permissions

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