-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathcheck_password.cpp
83 lines (66 loc) · 1.45 KB
/
check_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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
You are given a function:
int CheckPassiord(char str, int n):
The function accepts string 'str of size 'n' as argument
Implement the function which returns 1 if given string str' is a valid password else 0.
str is a valid password if it satisfies below conditions:
At least 4 characters
• At least one numeric digit
• At least one Capital letter
• Must not have space or slash (/)
• Starting character must not be a number
Assumption: Input string will not be empty.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int check(char str[], int n)
{
if (n > 4)
{
int flag = 0;
for (int i = 0; i < n; i++)
{
if (isdigit(str[i]))
{
flag = 1;
}
}
if (!flag)
return 0;
flag = 0;
for (int i = 0; i < n; i++)
{
if (isupper(str[i]))
{
flag = 1;
}
}
if (!flag)
return 0;
flag = 0;
for (int i = 0; i < n; i++)
{
if (str[i] != ' ' || str[i] != '/')
{
flag = 1;
}
}
if (flag)
return 0;
if (!isdigit(str[0]))
{
return 1;
}
return 0;
}
return 0;
}
int main()
{
char str[100];
scanf("%[^\n]%*c", str);
printf("%s", str);
int n = strlen(str);
printf("%d", check(str, n));
}