Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day6 implementation in c++ #75

Merged
merged 1 commit into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions day6/C++/day6_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* @author : dhruv-gupta14
* @date : 27/12/2018
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
string s;
getline(cin,s);

string ans;
ans = toupper(s[0]);
for(int i=1; i < s.size(); i++)
{
if(s[i-1] == ' ')
{
ans += toupper(s[i]);
} else{
ans += s[i];
}
}

cout << ans;
return 0;
}
23 changes: 23 additions & 0 deletions day6/C++/day6_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* @author : dhruv-gupta14
* @date : 27/12/2018
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
string str;
getline(cin,str);

string ans;
stringstream s(str);

while(s >> ans)
{
reverse(ans.begin(),ans.end());
cout << ans << " ";
}
return 0;
}
43 changes: 43 additions & 0 deletions day6/C++/day6_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* @author : dhruv-gupta14
* @date : 27/12/2018
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
int flag=0;
string str1;
getline(cin,str1);

string str2;
getline(cin,str2);

int n = str1.length();
int m = str2.length();

if(n!=m)
{
cout << "Not Anagrams";
} else{
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());

for(int i=0; i<n; i++)
{
if(str1[i] != str2[i])
{
cout << "Not Anagrams";
flag = 1;
break;
}
}
if(flag == 0)
{
cout << "Anagrams";
}
}
return 0;
}
117 changes: 117 additions & 0 deletions day6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,41 @@ print("String \'", string, "\' with first letter of each word capitalized (short
print("String \'", string, "\' with first letter of each word capitalized (slightly long version): ", capitalize_sentence_long(string))
```

## C++ Implementation

### [Solution](./C++/day6_1.cpp)

```cpp
/*
* @author : dhruv-gupta14
* @date : 27/12/2018
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
string s;
getline(cin,s);

string ans;
ans = toupper(s[0]);
for(int i=1; i < s.size(); i++)
{
if(s[i-1] == ' ')
{
ans += toupper(s[i]);
} else{
ans += s[i];
}
}

cout << ans;
return 0;
}
```

## Part B -- Word Reversal

**Question** - Given a sentence, Write a program to reverse each word in it.
Expand Down Expand Up @@ -424,6 +459,38 @@ string = input()
print("Reverse of string: ", reverse_words(string)})
```


## C++ Implementation

### [Solution](./C++/day6_2.cpp)

```cpp
/*
* @author : dhruv-gupta14
* @date : 27/12/2018
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
string str;
getline(cin,str);

string ans;
stringstream s(str);

while(s >> ans)
{
reverse(ans.begin(),ans.end());
cout << ans << " ";
}
return 0;
}
```


## Part C -- Anagram Check

**Question** - Write a program to check whether the two provided strings are anagrams of each other.
Expand Down Expand Up @@ -615,3 +682,53 @@ first_str = input()
second_str = input()
print("Are ", first_str, "and ", second_str, "anagrams? ", check_anagram(first_str, second_str))
```

## C++ Implementation

### [Solution](./C++/day6_3.cpp)

```cpp
/*
* @author : dhruv-gupta14
* @date : 27/12/2018
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
int flag=0;
string str1;
getline(cin,str1);

string str2;
getline(cin,str2);

int n = str1.length();
int m = str2.length();

if(n!=m)
{
cout << "Not Anagrams";
} else{
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());

for(int i=0; i<n; i++)
{
if(str1[i] != str2[i])
{
cout << "Not Anagrams";
flag = 1;
break;
}
}
if(flag == 0)
{
cout << "Anagrams";
}
}
return 0;
}
```