engel.teddy
BAN USER
#include <string>
#include <iostream>
bool IsNumberOrDigit(char c)
{
return ((c >= '0' && c <= '9')
|| (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z'));
}
bool SameCharacters(char c1, char c2)
{
return (c1 == c2
|| (c1 >= 'a' && c1 <= 'z' && c2 >= 'A' && c2 <= 'Z' && c1 == c2 + 32)
|| (c1 >= 'A' && c1 <= 'Z' && c2 >= 'a' && c2 <= 'z' && c2 == c1 + 32));
}
bool IsPalindrome(const std::string &haystack)
{
bool isPalindrome = true;
int i, j;
if (haystack.length() != 0)
{
i = 0;
j = haystack.size() - 1;
while (i < j)
{
while (i < j && !IsNumberOrDigit(haystack[i]))
i++;
while (i < j && !IsNumberOrDigit(haystack[j]))
j--;
if (IsNumberOrDigit(haystack[i]) && IsNumberOrDigit(haystack[j]) && !SameCharacters(haystack[i], haystack[j]))
{
isPalindrome = false;
break;
}
else
{
i++;
j--;
}
}
}
return isPalindrome;
}
int main(int argc, const char * argv[]) {
/* IsPalindrome */
std::string haystack = "A man, a plan, a canal, panama!";
std::cout << IsPalindrome(haystack) << std::endl;
return 0;
}
C++ with recursion:
#include <vector>
#include <string>
#include <iostream>
bool FindNeedleInHaystack(std::vector<char> needle, const std::string &haystack, int startHay, std::string combination)
{
std::vector<char> needleCopy(needle);
for (int i = startHay; i < haystack.length(); i++)
{
for (int j = 0; j < needle.size(); j++)
{
if (needle[j] == haystack[i])
{
if (needle.size() == 1)
{
std::cout << combination + haystack[i] << std::endl;
return true;
}
needleCopy.erase(needleCopy.begin()+j);
if (FindNeedleInHaystack(needleCopy, haystack, i + 1, combination + haystack[i]))
return true;
needleCopy = needle;
break;
}
}
if (startHay > 0)
return false;
}
return false;
}
int main(int argc, const char * argv[]) {
std::vector<char> needle = {'a', 'b', 'c'};
std::string haystack = "abbcbcbbbcabb";
FindNeedleInHaystack(needle, haystack, 0, "");
return 0;
}
#include <iostream>
class Node
{
public:
Node(int nValue): nValue(nValue), pNext(0)
{};
Node(int nValue, Node *pNext): nValue(nValue), pNext(pNext)
{};
int nValue;
Node *pNext;
};
void PrintList(Node *pNode)
{
while (pNode)
{
std::cout << pNode->nValue << std::endl;
pNode = pNode->pNext;
}
}
void ReverseList(Node *pNode)
{
Node *pCurrent = 0;
Node *pNext = 0;
while (pNode)
{
// Storing the next of current node
pNext = pNode->pNext;
// If current was already set, it means it's not the first node -> we need to change the node->next to current (which is actually previous node)
if (pCurrent)
{
pNode->pNext = pCurrent;
}
else
{
// In this case, this is first node
pNode->pNext = 0;
}
pCurrent = pNode;
pNode = pNext;
}
}
int main(int argc, const char * argv[]) {
Node *a = new Node(1);
Node *b = new Node(2, a);
Node *c = new Node(3, b);
Node *d = new Node(4, c);
// Print list before
std::cout << "From D:" << std::endl;
PrintList(d);
std::cout << "From A:" << std::endl;
PrintList(a);
// Reverse linked list in O(1) memory
ReverseList(d);
// Print list after
std::cout << "From D:" << std::endl;
PrintList(d);
std::cout << "From A:" << std::endl;
PrintList(a);
delete d;
delete c;
delete b;
delete a;
return 0;
}
Rephenryhokinsh, Android test engineer at ABC TECH SUPPORT
I’m Henry, I am Children's librarian in Rolling Thunder .My Work involves the responsibility for supervising the children ...
Repallisonepollard, Applications Developer at Accenture
I am Allison from Germantown. I work as a Staff manager at The LawnGuru company. But my interest in blogging ...
Repdavisjerryh, Backend Developer at Abs india pvt. ltd.
For the last two years, I am Effectively managing the team’s performance, conducting regular performance reviews and appraisals, and ...
RepEdithJHarden, Random at Axiom Sources
Je suis un professionnel de la gestion des soins de santé avec 2 ans d'expérience en supervision d'établissements ...
Repmelodyakeel, Consultant at Progress
Hello I am Melody. I am working as Human resource clerks, also called human resource assistants. I can maintain employee ...
Reppamelajoung, Dev Lead at Absolute Softech Ltd
I have worked as a wedding photographer for the past two years, first as a photographer’s assistant and then ...
Repshirleygause93, Analyst at Absolute Softech Ltd
Hi, I am Shirley from taxes, Conducted a re-profiling project which enabled our customers to receive orders more efficiently.Planning ...
RepI am Susan From Wasilla USA. and my strong interest in yoga and reading historical books. I have a large ...
Repannehbell8, Quality Assurance Engineer at Globaltech Research
Build and maintain relationships with convention vendors. Resolve issues throughout meeting event timelines.Plan room layouts and event programs, schedule ...
RepEviePaul, Member Technical Staff at Abs india pvt. ltd.
I am a Studio camera operator from Florida USA.I love to relax n' chill. love when it's cloudy ...
Repgarycsroka, Backend Developer at Axiom Sources
Hi I’m Gary, an average 19 year old in a state college who sees life as an adventure.Provide ...
In C++, supporting numbers > 9.
- engel.teddy February 26, 2015