15,844,676 members
See more:
Xtreme Insecurity, Inc. has a password policy that requires users to change their password every month. Some users have a hard time remembering the password when they change it, so they have taken to using iterated passwords, in which most of the password stays the same, except for a small part that is incremented or decremented. An example would be changing a password from "Secret16!" to "Secret18!" or "PasswordOctober" to "PasswordSeptember".

For this problem, you will be given lists of iterated sequences. You will reject a password change from

p
old

to

p
new

if

p
old

can be expressed as a string

+

1
+

a+s
1

+b and

p
new

can be expressed as a string

+

2
+

a+s
2

+b, where:

+
+ is the string concatenation operator,

a is a common prefix of length 0 or longer,

1
s
1

and

2
s
2

are strings from the same iterated sequence, and

b is a common suffix of length 0 or longer.
For example, if "16" and "18" are in the same iterated sequence, we would reject the change from "Secret16!" to "Secret18!" because the two passwords can be expressed as "Secret" + "16" + "!" and "Secret" + "18" + "!". These strings have identical prefixes and suffixes, and "16" and "18" are in the same sequence.

Similarly, if "October" and "September" were in the same iterated sequence, we would reject the change "PasswordOctober" to "PasswordSeptember", since these strings can be expressed as "Password" + "October" + "" and "Password" + "September" + "".

Standard Input
The first line contains an integer

n, indicating the number of iterated sequences.

The next

n lines each give a sequence of iterated values. The

i
th
line starts with an integer,

m
i

giving the number of iterated values in the sequence

S
i

. The remainder of the line contains the list of

m space-separated values in the sequence.

The next line presents an integer

p, which denotes the number of password changes to examine. The subsequent

p lines have two space separated values specifying the old password and the new one, respectively.

Standard Output
For each password change pair, you should output "REJECT" if

p
old

and

p
new

if we should reject the change according to the rules above.

Otherwise, you should output "OK".

input given
6
10 0 1 2 3 4 5 6 7 8 9
12 January February March April May June July August September October November December
7 Monday Tuesday Wednesday Thursday Friday Saturday Sunday
3 qwerty asdf zxcv
2 ana bob
3 ? . !
20
Pass123 pass124
ShhMonday ShhMarch
January23 March23
ABCJanuary MarchABC
January23 february23
Tuesday Sunday
xyz123 124xyz
zxcvz qwertyz
asdfasdf asdfzxcv
asdfasdf zxvcasdf
bobobob anaobob
bobobob boboana
banana bbobna
banana banbob
banana baboba

What I have tried:

many questions nd many languages but didnt get any
Posted
Updated 28-Oct-23 5:52am
v2
Dave Kreskowiak 28-Oct-23 10:53am
You copied and pasted your homework assignment, but it's formatting makes it completely unreadable. You'll have to edit it so it's readable and explain what you've tried and what problems you're having.

We're not here to do your homework for you.

## Solution 1

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

## Solution 2

If I understand it correctly, the file to be read has the following format:

1. The first line contains an integer n indicating the number of iterated sequences. The next n lines each contain a sequence of iterated values.

2. Each of these lines starts with an integer m indicating the number of iterated values in the sequence. The rest of the line contains the list of m space-separated values in the sequence.

3. The next line contains an integer p indicating the number of password changes to be examined. The following p lines contain two values separated by spaces, indicating the old and the new password, respectively.
Example input file:
6
10 0 1 2 3 4 5 6 7 8 9
12 January February March April May June July August September October November December
7 Monday Tuesday Wednesday Thursday Friday Saturday Sunday
3 qwerty asdf zxcv
2 ana bob
3 ? . !
20
Pass123 pass124
ShhMonday ShhMarch
January23 March23
ABCJanuary MarchABC
January23 february23
Tuesday Sunday
xyz123 124xyz
zxcvz qwertyz
asdfasdf asdfzxcv
asdfasdf zxvcasdf
bobobob anaobob
bobobob boboana
banana bbobna
banana banbob
banana baboba
...

Obviously, a file with input values must be read first. For this one must open the file and store the contents in suitable structures.

1. In the main function the file "mydata.dat" is opened in the read mode. If the file cannot be opened, an error message is output.

2. The number of sequences n to be processed is read from the file.

3. An array of sequence structures (sequences) is dynamically allocated to store the sequences. Each sequence has a length and an array of values. The sequence structure contains information about the number of values and an array to store these values.

4. In a loop for each sequence the number of values m is read, then dynamically memory is reserved for the values of this sequence and the values are read from the file.

5. The number of password changes p to be processed is read from the file.

6. An array of PWChange structures is dynamically allocated to store the password changes. The PWChange structure stores information about password changes. It contains fields for the old and the new password.

7. In a loop the old and new passwords are read from the file and stored in the corresponding fields of PWChange structures.

8. After all data have been read in, the file can be closed and work can be done with the data.

At the end of the program, the allocated memory should be released. First the values in the sequences are released, then the sequences themselves, and finally the password changes.

A C program for this could start like this:
C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Structure to represent a single sequence
typedef struct {
int length;     // Number of values in the sequence
char **values;  // Array of values (as strings)
} Sequence;

// Structure to represent a password change
typedef struct {
} PWChange;

int main()
{
FILE* file;             // Filehandle
int n;                  // Number of sequences
int m;                  // Number of values in the sequence
int p;                  // Number of password changes

Sequence* sequences;    // Memory for sequences
PWChange* pwChanges;    // Memory for password changes

if (fopen_s(&file, "mydata.dat", "r") != 0) {
perror("Error opening file"); return 1;
}

fscanf_s(file, "%d", &n);

...

fclose(file);
return 0;
}

No one will give you a complete solution, but I hope this framework is enough to give you an idea of what the complete solution might look like. It would be necessary that you get to know the required functions and deal with them.

v3