forked from Shubhamlmp/Programming-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
248_New_Password.cpp
32 lines (30 loc) · 1.1 KB
/
248_New_Password.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;
/* Explanation
To make the length of the password as mentioned in the ques upto the give leangth
and with distinct letters.
We can take the first letter to be 'a' and keep on going to the next character until
the number of distinct char becomes equal to the given size and then again repeat form
character 'a' so that number of the same distinct char remains same,
For eg if we take input 4 3
then we have to go form a b c to match the required dinstinct char and again print 'a'
int the end . So the answer is "abca";
*/
int main(){
int length;
cin>>length;
int no_of_distinct_char;
cin>>no_of_distinct_char;
char k='a'; //starting from a character
int p=1;
for(int i=0;i<length;i++){
cout<<k;
p++;
k++; //increases the char by one means make a b and b to c and so on.
if(p==no_of_distinct_char+1){ // if it becomes equal to the number of distinct char we
k='a'; //we will again make it 'a'.
p=1;
}
}
return 0;
}