-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY8.cpp
More file actions
94 lines (87 loc) · 1.54 KB
/
DAY8.cpp
File metadata and controls
94 lines (87 loc) · 1.54 KB
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
84
85
86
87
88
89
90
91
92
93
94
//LENGTH OF STRING
#include<iostream>
using namespace std;
int main()
{
string str="Hello World this is a string in c++";
//HELLO WORLD
int word=0;
for(int i=0;str[i]!='\0';i++)
{
if(str[i]==' '&& str[i+1]!=' ')
{
word++;
}
}
if(str[0]!=' ')
{
word++;
}
else if(str[str.length()-1]==' ')
{
word--;
}
cout<<word<<endl;
}
//PASSWORD TESTING
#include<iostream>
using namespace std;
int main()
{
string str="teststring12*3";
int lower=0,upper=0,number=0,special=0;
for(int i=0;str[i]!='\0';i++)
{
if(str[i]>='A' && str[i]<='Z')
{
upper++;
}
if(str[i]>='a' && str[i]<='z')
{
lower++;
}
if(str[i]>='0' && str[i]<='9')
{
number++;
}
else
{
special++;
}
}
if(lower&&upper&&number&&special)
{
cout<<"Valid";
}
else{
cout<<"Not Valid";
}
return 0;
}
//STRING COMPARISON
#include<iostream>
using namespace std;
int compare_string(string str1,string str2)
{
for(int i1=0,i2=0; str1[i1]!='\0' && str2[i2]!='\0';i1++,i2++)
{
if(str1[i1]!=str2[i2])
{
if(str1[i1]>str2[i2])
{
return 1;
}
else
{
return -1;
}
}
}
return 0;
}
int main()
{
string str1="Painter";
string str2="Painting";
cout<<compare_string(str2,str1)<<endl;
}