From e04261c67d1e01609c89ee806a551d3f5abaf100 Mon Sep 17 00:00:00 2001 From: profgrammer Date: Mon, 31 Dec 2018 13:07:53 +0530 Subject: [PATCH] cpp code for day 2 and 3 (#87) --- Day2/C++/profgrammer_reversepalindrome.cpp | 38 ++++++++++++++++++++ Day2/README.md | 41 ++++++++++++++++++++++ Day3/C++/profgrammer_hammingdistance.cpp | 25 +++++++++++++ Day3/README.md | 29 ++++++++++++++- 4 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 Day2/C++/profgrammer_reversepalindrome.cpp create mode 100644 Day3/C++/profgrammer_hammingdistance.cpp diff --git a/Day2/C++/profgrammer_reversepalindrome.cpp b/Day2/C++/profgrammer_reversepalindrome.cpp new file mode 100644 index 00000000..ba341f14 --- /dev/null +++ b/Day2/C++/profgrammer_reversepalindrome.cpp @@ -0,0 +1,38 @@ +/* + *@author: profgrammer + *@date: 30-12-2018 +*/ + +#include +using namespace std; + + +int main() { + string s; + cin>>s; + + // method 1: print the string in reverse order + cout<<"The reversed string is: "; + for(int i = s.size()-1;i >= 0;i--) cout< +using namespace std; + + +int main() { + string s; + cin>>s; + + // method 1: print the string in reverse order + cout<<"The reversed string is: "; + for(int i = s.size()-1;i >= 0;i--) cout< +using namespace std; + +int main() { + string s1, s2; + cin>>s1>>s2; + cout<<"The hamming distance is : "; + // the hamming distance is calculated for strings of EQUAL length. hence if the lengths differ we return -1 as an invalid case. + if(s1.size() != s2.size()) cout<<-1< +using namespace std; + +int main() { + string s1, s2; + cin>>s1>>s2; + cout<<"The hamming distance is : "; + // the hamming distance is calculated for strings of EQUAL length. hence if the lengths differ we return -1 as an invalid case. + if(s1.size() != s2.size()) cout<<-1<