ZOJ 3427 Array Slicing (scanf use)

Source: Internet
Author: User

Test instructions Watashi invented a kind of egg ache (Eggache) language you want to implement an array slicing function for this language function is to have an array initially empty each time you give you an interval [L, R) and some number you want to output the array subscript in [l , r) and then delete these numbers and then insert those numbers to you to the position of the array subscript L.

Check-in simulation has not read test instructions saw Watashi scanf high-end usage of the weak to even scanf will not use the force to CPP preview the first record of those who do not understand the scanf usage it

int scanf (const char * format, ...);

Format consists of these contents
    • white space character: scanf all whitespace characters before the next non-whitespace character is ignored in the read-only character contains ' \ t ', ' \ n ', ' \v ', ' \f ', ' \ R '
    • Non -whitespace characters other than%: These characters must be strictly matched on input or read in failed
    • format specifier%: indicates the type of read data or read Rule %[*][width][length]specifier
* Indicates that the content of this format specifier is read without having to specify parameters for it (note that the difference between printf * requires an integer parameter to indicate at least how many digits are not sufficient to replace the space) width Indicates the maximum number of characters to read length Some words must be one of these. hh ,  h ,  L ,  ll ,  J ,  Z ,  T ,  L different types of bits that correspond to the same data, such as int (d) and long Long (LLD)
The point is specifier
specifier Description characters extracted
I Integer Any number of digits, optionally preceded by a sign (+ or -).
Decimal digits assumed by default (0-9), but a 0 prefix introduces octal digits (0-7), and 0x hexadecimal digits (0-f).
signed argument.
d or u
Decimal integer Any number of the decimal digits (0-9), optionally preceded by a sign (+ or -).
d is for a signed argument, and u for a unsigned.
O Octal integer Any number of octal digits (0-7), optionally preceded by a sign (+ or -).
Unsigned argument.
X hexadecimal integer Any number of hexadecimal digits (0-9, a-f, a-f), optionally preceded by 0x or 0X , and all optionally preceded by a sign (+ or -).
Unsigned argument.
f, e, g Floating point number A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or e character and a decimal integer (or some of the other sequences Supported by strtod ).
Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X .
A
C Character The next character. If a width other than 1 is specified, the function reads exactly widthcharacters and stores the M in the successive locations of the array passed as argument. No null character is appended at the end.
S String of characters Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence.
P Pointer Address A sequence of characters representing a pointer. The particular format used depends on the system and the library implementation, but it's the same as the one used to format %p in fprintf.
[characters] Scanset Any number of the characters specified between the brackets.
A Dash (-) that isn't the first character may produce non-portable behavior in some library implementations.
[^characters] Negated Scanset Any number of characters none of them specified as characters between the brackets.
N Count No input is consumed.
The number of characters read so far from was stored in the stdin pointed location.
% % A % followed by another % matches a single %.

except n specifier matches at least one of the input characters otherwise the read join terminates at the current character
n requires a parameter that points to an int to save how many characters were read before this
int main () {    char s[500];    int n;    scanf ("%s%n", S, &n);    printf ("%s  %d\n", S, N);    Enter Hello    //output Hello 5    return 0;}
It
is also possible to use%n in printf to indicate how many bits of characters were output before this statement
int main () {    int n;    printf ("hello%n", &n);    printf ("%d\n", n);    Output Hello 5    return 0;}


Specifier can be [...], [^ ...] Both of these regular expressions

[...] Reads the characters contained in the parentheses and encounters other characters to end this specifier

int main () {    char s[500];    int n;    scanf ("%[0-9]%n", S, &n);//%[0-9] Read only digits  encountered non-numeric end    printf ("%s%d\n", S, N);    scanf ("%[ab]%n", S, &n);    printf ("%s%d\n", S, N);    Input "   12345abc"  preceded by three spaces    //output 12345 8  AB 2    return 0;}

[^...] Indicates that all characters except the characters in the brackets are read and the characters in parentheses are encountered to end this specifier

Of course, these things sscanf also apply

After the preview of the scanf after the input of the problem is very good processing directly with the list of the splice function on the line

#include <bits/stdc++.h>using namespace Std;char s[5000], *ps;int main () {    list<int> A, b;    int L, R, N, v;    List<int>::iterator it;    while (~SCANF ("[%d:%d]%[^\n]", &l, &r, s))    {        b.clear ();        PS = s;        while (SSCANF (PS, "%*[^-0-9]%d%n", &v, &n) > 0)        {            //filter out non '-' and the number is read into a number of            //n records scanf How many characters            are read PS = PS + N;  Read n characters so go ahead n-bit            b.push_back (v);        }        Advance (it = A.begin (), l);        while (L < R)        {            printf ("%d%s", *it, L < r-1?) ", " : "");            it = a.erase (it);            l++;        }        Puts ("");        A.splice (it, b);    }    return 0;}

Array slicing Time limit: 2 Seconds Memory Limit: 65536 KB

Array slicing is a operation that extracts certain elements from an array and packages them as another array. Now your ' re asked to implements the array slicing operations for a new programming language-- eggache* (pronounce D "Eggache star"). The grammar of array slicing in eggache* is:

[ begin : end ] = x1, x2, ..., xk, ...
where begin ≤ End is indices indicating the range of slice. Redundant whitespaces should be ignored. For each operation, the original slice should is printed first, then these elements would be replaced with the new elements provided. See sample for more details.

Input

There is only one case for this problem, which contains about lines of array slicing operations. It's guaranteed that all operations is valid and the absolute values of all integers never exceed 100. The array is empty ([]) before the first operation.

Output

The output produced by array slicing operations in the eggache* programming language.

Sample Input
[0:0] = 1 2 3 4 5 6 7 8 9[1:1] = -1[1:1] =[0:8] = 9 8 7 6 5 4 3 2 1[2:8] = 2,-3, 5, 7 [0:9] = 000[0 : 1] = 1, 2, 8[2:2] = 4[0:4] =
Sample Output
1,-1, 2, 3, 4, 5, 6, 77, 6, 5, 4, 3, 29, 8,-2,-3,-5,-7, 1, 8, 901, 2, 4






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ZOJ 3427 Array Slicing (scanf use)

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.