Toj1015 Line Editor-stack Application

Source: Internet
Author: User
Tags line editor

/*

Row Editor

Http://acm.tongji.edu.cn/people/ps/showproblem.php? Problem_id = 1015

Time Limit: 1 s Memory Limit: 1000 k
Total Submit: 4424 Accepted: 1364

Problem

The function of a simple row editing program is to accept the program or data entered by the user from the terminal and store it in the user's data zone.

When a user inputs data on a terminal, no error is guaranteed, it is obviously not the most appropriate practice to "store each character in the user data zone. A good practice is to set up an input buffer to accept a line of characters entered by the user and store them in the user data zone row by row. You can enter a business error and correct the error in time. For example, if you find that the entered character is incorrect, you can add a backslash (#) to indicate that the previous character is invalid;

If you find that the number of errors in the current row is large or difficult to remedy, you can enter a fallback character "@" to indicate that the characters in the current row are invalid.

If the '#' symbol already entered at the beginning of the row is invalid.

Input

Enter a multi-line character sequence. The total number of characters (including the return and return characters) is not greater than 250.

Output

The output is as follows.

Sample Input
whli##ilr#e(s#*s)   outcha@putchar(*s=#++);
Sample Output
while(*s)putchar(*s++);

*/

# Include <stdio. h>

# Define MAX_STK_SIZE 250

Int top;
Char stk [MAX_STK_SIZE];

Void InitStk ()
{
Top = 0;
}

Void TraverseStk ()
{
Int I;
For (I = 0; I <top; I ++)
Printf ("% c", stk [I]);
Printf ("/n ");
}

Int Pop (char * elem)
{
If (top = 0)
Return 0;
Else
{
Top --;
* Elem = stk [top];
Return 1;
}
}

Int Push (char elem)
{
If (top = MAX_STK_SIZE)
Return 0;
Else
{
Stk [top] = elem;
Top ++;
Return 1;
}
}

Int main ()
{
Int num;
Char CH, ELEM;
 
Initstk ();
While (num = getchar ())! = EOF)
{
Ch = (char) num;
If (CH = '#')
Pop (& ELEM );
Else if (CH = '@')
Initstk ();
Else if (CH = '/N ')
{
Traversestk ();
Initstk ();
}
Else
Push (CH );
}

Return 0;
}

Related Article

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.