Website Summary Files Commits Branches @commit @diff @stats
path: root / Week11 / Exercise12.cpp
blob: 3ebb9475d96e14c4ea2abfd9774d0ca234aa6c66 (plain) (blame)
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
#include <iostream>

unsigned passwordGrade(const char* password) {
	unsigned charCount = 0;
	bool containsLetter = false, containsDigit = false, containsSpecial = false, noNeighbouring = true;

	while (*password != '\0') {
		if (('a' <= *password && *password <= 'z') ||
		    ('A' <= *password && *password <= 'Z'))
		{
			containsLetter = true;
		}
		else if ('0' <= *password && *password <= '9') {
			containsDigit = true;
		}
		else {
			containsSpecial = true;
		}

		if (password[0] == password[1]) {
			noNeighbouring = false;
		}

		charCount++;
		password++;
	}

	return (charCount >= 15) + containsLetter + containsDigit + containsSpecial + noNeighbouring;
}

int main() {
	unsigned allocated = 8, size = 0;
	char* password = new char[allocated];

	char curr;
	std::cin.get(curr);
	while (curr != '\n') {
		password[size++] = curr;
		std::cin.get(curr);

		// Реоразмеряване
		if (size >= allocated) {
			allocated *= 2;
			char* newSentenceArray = new char[allocated];

			for (unsigned i = 0; i < size; i++)
				newSentenceArray[i] = password[i];

			delete[] password;
			password = newSentenceArray;
		}
	}
	password[size] = '\0';

	std::cout << passwordGrade(password) << std::endl;

	delete[] password;

	return 0;
}