int main() { Palindrome test; // Initialize the class object. test.AskUser(); // Run the AskUser() function to begin the program. return 0; }
int main() { string input; ifstream ifs; ifs.open("testfile.txt"); if(ifs.good()){ getline(ifs, input, ' '); Palindrome p = Palindrome(input); cout << "Palindrom Class" << endl; cout << "Longest: " << p.longest() << endl; } else cout << "File Failed" << endl; std::cin.get(); return 0; }
int main() { Palindrome palindrome; std::vector<int> products; bool foundPalindrome=false; int b = 999; //Populate products vector for(int a=999; a > 99; a--){ foundPalindrome=false; b=999; while(!foundPalindrome) { if( b > 0 ){ if( palindrome.isPalindrome(a * b) ){ products.push_back(a * b); foundPalindrome=true; }else{ b--; } }else{ //printf("%d failed to yield any palindromes.\n", a); foundPalindrome=true; } } } //DEBUGGING OPTION -- print out contents of products //printf("Products is %d elements long.\n",products.size()); //for(int &i : products){ // printf("%d\n", i); //} //Sort products vector std::sort(products.rbegin(), products.rend()); //DEBUGGING OPTION -- print out contents of sorted products //printf("Sorted products is %d elements long.\n",products.size()); //for(int &i : products){ // printf("%d\n", i); //} printf("%d is the highest palindromic product.\n", products[0]); return 0; }
int main(){ //InsertValue test; //vector<int> A = { 1, 3, 4, 5, 7 }; vector<int> nxt = { 1, 2, 3, 4, 0 }; int val = 2; //ListNode* ans = test.insert(A, nxt, val); //vector<int> A = { 360,220,2 }; int val = 2; //Divide test; //ListNode *ans = test.listDivide(head, val); vector<int> A = { 1, 3, 4, 3, 1 ,1}; int n = A.size(); ListNode *head = new ListNode(A[0]); ListNode *temp = head; for (int i = 1; i < n; i++) { //构成链表 temp->next = new ListNode(A[i]); temp = temp->next; } Palindrome test; bool ans = test.isPalindrome(head); cout << ans; //KInverse test; //ListNode *ans = test.inverse(head, k); /*temp = ans; while (temp != NULL){ cout << temp->val; temp = temp->next; }*/ return 0; }
int main() { // read the string s. string s; getline(cin, s); // create the Palindrome class object p. Palindrome p; // push all the characters of string s to stack. for (int i = 0; i < s.length(); i++) { p.pushCharacter(s[i]); } // enqueue all the characters of string s to queue. for (int i = 0; i < s.length(); i++) { p.enqueueCharacter(s[i]); } bool f = true; // pop the top character from stack. // dequeue the first character from queue. // compare both the characters. for (int i = 0; i < s.length(); i++) { if (p.popCharacter() != p.dequeueCharacter()) { f = false; break; } } // finally print whether string s is palindrome or not. if (f) { cout << "The word, " << s << ", is a palindrome."; } else { cout << "The word, " << s << ", is not a palindrome."; } return 0; }
int main() { srand(time(0)); Palindrome* p = new Palindrome(); // test 1: empty strings and single letters are palindromes assert(p->test_string("") == -1); assert(p->test_string("a") == -1); std::cout << "Test 1 passed." << std::endl; // test 2: correct palindromes, all lowercase, no non-letters assert(p->test_string("aa") == -1); assert(p->test_string("bob") == -1); assert(p->test_string("abba") == -1); assert(p->test_string("stats") == -1); std::cout << "Test 2 passed." << std::endl; // test 3: correct palindromes, not all lowercase, with non-letters assert(p->test_string("aA") == -1); assert(p->test_string("Aa") == -1); assert(p->test_string("Bob") == -1); assert(p->test_string("Madam") == -1); assert(p->test_string("A man, a plan, a canal, Panama!") == -1); assert(p->test_string("Bob: Did Anna peep? Anna: Did Bob?") == -1); std::cout << "Test 3 passed." << std::endl; // test 4: returning the correct position of the failed palindromes assert(p->test_string("ab") == 0); assert(p->test_string("abca") == 1); assert(p->test_string("A man, a plan, a canal, Panema!") == 2); assert(p->test_string("rm -rf /") == 0); assert(p->test_string("a,,b,,c,,d,,b,,a") == 2); std::cout << "Test 4 passed." << std::endl; // test 5: random palindromes so you cannot hard code them for (int i = 0, len = rand_range, current = (rand() % (len / 2)) - 1; i < rand_range; ++i, len = rand_range, current = (rand() % (len / 2)) - 1) assert(p->test_string(randPalindrome(len, current)) == current); std::cout << "Test 5 passed." << std::endl; std::cout << "\nAll Tests Passed!" << std::endl; // cleanup delete p; }