(Data Structure Arrangement) NJUPT1054

Source: Internet
Author: User

This blog uses some questions on OJ as a carrier to sort out the data structure. Will be updated one after another...

We all know that flexible application of data structures can sometimes simplify answers to some questions.

I. Stack applications

1. njupt oj 1054 (retrieval string judgment)

Determination of the return string: stores half of a string into a stack, and then checks whether the string is a return string from the top of the stack.

/** NJUPTOJ_1054.cpp ** Created on: July 15, May 22, 2014 * Author: pc */# include

 
  
# Include

  
   
Using namespace std; const int maxn = 300; void toLower (char arr [], int len) {int I; for (I = 0; I <len; ++ I) {if (! Islower (arr [I]) {arr [I] + = 32 ;}} int main () {char a [maxn]; char s [maxn]; while (gets ()! = NULL) {int len = strlen (a); toLower (a, len); int mid = len/2-1; int top = 0; int I; for (I = 0; I <= mid; ++ I) {s [++ top] = a [I];} int next; if (len % 2 = 0) {next = mid + 1;} else {next = mid + 2;} for (I = next; I <= len-1; ++ I) {if (s [top]! = A [I]) {break;} -- top;} if (top! = 0) {printf ("Not Palindrome. \ n");} else {printf ("Bingle! Palindrome. \ n ") ;}} return 0 ;}

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.