Skip to content

Commit 891e4ea

Browse files
committed
local
1 parent 46706b9 commit 891e4ea

23 files changed

+713
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// By Basel Bairkdar: https://www.facebook.com/baselbairkdar
2+
#include<iostream>
3+
using namespace std;
4+
5+
string input,str;
6+
7+
int main()
8+
{
9+
cin >> input >> str;
10+
bool is_prefix=1; /** we will say that it's prefix at the beginning **/
11+
int n=str.size();
12+
/**
13+
check if str is eqaul
14+
to the first n letter of input
15+
**/
16+
for (int i=0;i<n;i++)
17+
{
18+
if (input[i]!=str[i])
19+
{
20+
is_prefix=0;
21+
break;
22+
}
23+
}
24+
if (is_prefix)
25+
cout << "YES\n";
26+
else
27+
cout << "NO\n";
28+
return 0;
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// By Basel Bairkdar: https://www.facebook.com/baselbairkdar
2+
#include<iostream>
3+
using namespace std;
4+
5+
string input,str;
6+
7+
int main()
8+
{
9+
cin >> input >> str;
10+
bool is_suffix=1; /** we will say that it's suffix at the beginning **/
11+
int n=str.size();
12+
/**
13+
check if str is equal
14+
to the last n letter of input
15+
**/
16+
int in=0; /** index of str **/
17+
for (int i=input.size()-n;i<input.size();i++)
18+
{
19+
if (input[i]==str[in])/** careful, str[in] not str[i] **/
20+
{
21+
in++;
22+
}
23+
else if (input[i]!=str[in])/** careful, str[in] not str[i] **/
24+
{
25+
is_suffix=0;
26+
break;
27+
}
28+
}
29+
if (is_suffix)
30+
cout << "YES\n";
31+
else
32+
cout << "NO\n";
33+
return 0;
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// By Basel Bairkdar: https://www.facebook.com/baselbairkdar
2+
#include<iostream>
3+
using namespace std;
4+
5+
string input,str;
6+
7+
int main()
8+
{
9+
cin >> input >> str;
10+
bool is_substring=0; /** we will say that it's not a substring at the beginning **/
11+
12+
13+
int in=0;
14+
for (int i=0;i<input.size();i++)
15+
{
16+
if (input[i]==str[in])/** characters are equal (possible match) **/
17+
{
18+
in++; /** increase index **/
19+
if (in==str.size())
20+
{
21+
is_substring=1;
22+
break;/** found a solution, no need to stay in the loop **/
23+
}
24+
}
25+
else
26+
{
27+
/**
28+
if the characters are different and we have not broken
29+
the loop yet (no solution so far)
30+
make in=0 to look for possible match
31+
**/
32+
in=0;
33+
}
34+
}
35+
36+
37+
if (is_substring)
38+
cout << "YES\n";
39+
else
40+
cout << "NO\n";
41+
return 0;
42+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// By Basel Bairkdar: https://www.facebook.com/baselbairkdar
2+
#include<iostream>
3+
using namespace std;
4+
5+
string input,str;
6+
7+
int main()
8+
{
9+
cin >> input >> str;
10+
11+
int in=0;/** index of str **/
12+
13+
for (int i=0;i<input.size();i++)
14+
{
15+
if (input[i]==str[in])/** if there is a match just increase the index **/
16+
{
17+
in++;
18+
if (in==str.size())break;/** reached the end of str **/
19+
}
20+
}
21+
22+
23+
if (in==str.size())/** have we reached the end of str ? if so then it is a subsequence **/
24+
cout << "YES\n";
25+
else
26+
cout << "NO\n";
27+
return 0;
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// By Basel Bairkdar: https://www.facebook.com/baselbairkdar
2+
#include<iostream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int ans=0;
8+
string str;
9+
10+
cin >> str;
11+
/**
12+
how to convert str to int ?
13+
say we have a string "123"
14+
now, make ans=1 which is the first character of str
15+
the second character is 2
16+
we need to put 2 in the ans properly (so we get ans=12 for now)
17+
simply, if we multiply ans by 10
18+
ans*=10 => ans=10
19+
then add 2 => ans+=2 => ans=12
20+
repeat same process for every character
21+
**/
22+
for (int i=0;i<str.size();i++)
23+
{
24+
ans*=10;// when i=0 ans is 0 too, so ans*=10 keeps ans=0
25+
26+
ans+=str[i]-'0';/** when i=0 ans will be the first character of str **/
27+
}
28+
cout << ans << " " << ans*3 << endl;
29+
return 0;
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// By Mohamed Yasser https://www.facebook.com/SanfourRadwan
2+
#include <iostream>
3+
#include <string>
4+
using namespace std;
5+
int main()
6+
{
7+
string input;
8+
cin >> input;
9+
int len = input.size();
10+
/**
11+
we sure that first character in string
12+
is found in first group
13+
**/
14+
cout << input[0];
15+
for(int i = 1 ; i < len ; i++){
16+
/**
17+
if the current character is equal previous character
18+
then they are in same group
19+
otherwise they are in Different groups
20+
*/
21+
if(input[i-1] != input[i])/// print space between the different groups
22+
cout << ' ';
23+
cout << input[i];
24+
}
25+
return 0;
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// By Mohamed Yasser https://www.facebook.com/SanfourRadwan
2+
3+
#include <iostream>
4+
#include <string>
5+
using namespace std;
6+
int main()
7+
{
8+
string input;
9+
cin >> input;
10+
int len = input.size() , cnt = 1;
11+
for(int i = 1 ; i < len ; i++){
12+
/**
13+
if the current character is equal previous character
14+
then they are in same group and we need increment count by 1
15+
16+
otherwise they are in Different groups and we need print last group
17+
and start count 1
18+
*/
19+
if(input[i-1] != input[i]){
20+
cout << input[i-1] << cnt << "_";
21+
cnt = 1;
22+
}else cnt++;
23+
}
24+
/// print last group
25+
cout << input[len-1] << cnt << "\n";
26+
return 0;
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
string a, b;
6+
7+
cin >> a >> b;
8+
9+
int sz = a.size();
10+
11+
if (sz < b.size())
12+
sz = b.size();
13+
14+
int smaller = -1;
15+
16+
for (int i = 0; smaller == -1 && i < sz; ++i) {
17+
if (a[i] != b[i]) {
18+
if (a[i] < b[i])
19+
smaller = 0;
20+
else
21+
smaller = 1;
22+
}
23+
}
24+
if (smaller == -1) { // then the first letters are common. Small in length is smaller
25+
if (a.size() <= b.size())
26+
smaller = 0;
27+
else
28+
smaller = 1;
29+
}
30+
if (smaller == 0)
31+
cout << "YES\n";
32+
else
33+
cout << "NO\n";
34+
35+
return 0;
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
string num;
6+
7+
// Guarantee input: must be 6 digits or more
8+
cin >> num;
9+
10+
int sz = num.size();
11+
12+
int carry = 0;
13+
for (int i = 0; i < sz; ++i) {
14+
int digit = num[sz - 1 - i] - '0';
15+
16+
if (i < 4)
17+
digit += 5; // add 5 in first 4 times
18+
digit += carry; // add any carry
19+
20+
if (digit >= 10)
21+
digit -= 10, carry = 1;
22+
else
23+
carry = 0;
24+
25+
num[sz - 1 - i] = digit + '0';
26+
}
27+
if(carry)
28+
cout<<1;
29+
cout << num;
30+
31+
return 0;
32+
}

18-Programming-4kids/11_homework_employees_v1.cpp renamed to 18-Programming-4kids/11_homework_9_answer_employees_v1.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main() {
1414

1515
while (true) {
1616
int choice = -1;
17-
cout << "Enter your choice:\n";
17+
cout << "\nEnter your choice:\n";
1818
cout << "1) Add new employee\n";
1919
cout << "2) Print all employees\n";
2020
cout << "3) Delete by age\n";
@@ -50,7 +50,7 @@ int main() {
5050
<< " " << genders[i] << "\n";
5151
}
5252
} else if (choice == 3) {
53-
cout << "Enter start and end age\n";
53+
cout << "Enter start and end age: ";
5454
int start, end;
5555
cin >> start >> end;
5656

@@ -59,7 +59,7 @@ int main() {
5959
ages[i] = -1;// Let's mark a removed entry with -1 (lazy delete)
6060
}
6161
} else {
62-
cout << "Enter the name and salary";
62+
cout << "Enter the name and salary: ";
6363
string name;
6464
int salary;
6565
cin >> name >> salary;

0 commit comments

Comments
 (0)