forked from ChicoState/UnitTestPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Practice.cpp
59 lines (54 loc) · 1.24 KB
/
Practice.cpp
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
#include "Practice.h"
#include <string>
using std::string;
// Receive three integers and rearrange their values so that they are in
// descending order from greatest (first) to least (third)
void Practice::sortDescending(int & first, int & second, int & third)
{
if( first < second )
{
int temp = first;
first = second;
second = temp;
}
if( first < third )
{
int temp = first;
first = third;
third = temp;
}
if( second < third )
{
int temp = second;
second = third;
third = temp;
}
// if((first > second) && (second > third))
// {
// return true;
// }
// else
// {
// return false;
// }
}
// Receive a string and return whether or not it is strictly a palindrome,
// where it is spelled the same backwards and forwards when considering every
// character in the string, but disregarding case ('x' is the same as 'X')
bool Practice::isPalindrome(string input)
{
for(unsigned int i=0; i < input.size(); i++)
{
if( input[i] < 'A' || input[i] > 'Z' )
{
//change lower case to upper case
input[i] = input[i] - ('a' - 'A');
}
}
for(unsigned int i=0; i < input.size()/2; i++)
{
if( input[i] != input[input.size()-1-i] )
return false;
}
return true;
}