ISC practical papers › ISC 2006 › Question 3
Security Code Validation
ISC 2006 Computer Science Practical, Question 3 · Strings
The question
A new advanced Operating System, incorporating the latest hi-tech features has been designed by Opera Computer Systems.
The task of generating copy protection codes to prevent software piracy has been entrusted to the Security Department.
The Security Department has decided to have codes containing a jumbled combination of alternate uppercase letters of the alphabet starting from A upto K (namely among A,C,E,G,I,K).
The code may or may not be in the consecutive series of alphabets.
Each code should not exceed 6 characters and there should be no repetition of characters. If it exceeds 6 characters, display an appropriate error message.
Write a program to input a code and its length. At the first instance of an error display invalid!” stating the appropriate reason. In case of no error, display the message “Valid!”.
Test your program for the following data and some random data.
SAMPLE DATA INPUT: N = 4 ABCE OUTPUT: Invalid! Only alternate letters permitted!
INPUT: N = 4 AcIK OUTPUT: Invalid! Only upper case letters permitted!
INPUT: N = 4 AAKE OUTPUT: Invalid! Repetition of characters not permitted!
INPUT: N = 7 OUTPUT: Error! Length of string should not exceed 6 characters!
INPUT: N = 4 AEGIK OUTPUT: Invalid! String length not the same as specified!
INPUT: N = 3 ACE OUTPUT: Valid!
INPUT: N = 5 GEAIK OUTPUT: Valid!
Question: ISC 2006 Computer Science Paper 2 (Practical), Question 3, set by the Council for the Indian School Certificate Examinations (CISCE). Solution and video: Vinay Singh.
Java solution
import java.util.*;
class CopyProtectionCode {
private String code, output;
private static String validCharacters = "ACEGIKacegik";
private int N;
public CopyProtectionCode(String code, int N) {
this.code = code;
this.N = N;
validate();
}
private void validate() {
if (N != code.length()) {
output = "Invalid! String length not the same as specified!";
return;
}
char ch;
int foundAtPosition;
for (int position = 0; position < code.length(); position++) {
ch = code.charAt(position);
foundAtPosition = validCharacters.indexOf(ch);
if (foundAtPosition == -1) {
output = "Invalid! Only alternate letters permitted!";
return;
}
if (foundAtPosition > 5) {
output = "Invalid! Only upper case letters permitted!";
return;
}
if(code.lastIndexOf(ch)!=position){
output="Invalid! Repetition of characters not permitted!";
return;
}
output="Valid!";
}
}
public String toString(){
return output;
}
}
public class ISC2006Q3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("INPUT:\t");
int N = in.nextInt();
in.nextLine();
if (N > 6) {
System.out.println("OUTPUT:\nError! Length of string should not exceed 6 characters!");
}else{
String code = in.nextLine();
CopyProtectionCode obj = new CopyProtectionCode(code, N);
System.out.println("OUTPUT:\n" + obj);
}
in.close();
}
}
All these solutions in one free book
Pragmatic Solutions to ISC Computer Science Practical Problems collects every program from 2004 to 2021 in a 202-page PDF.