21695_Parse

2022-5-16 18:20| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505767124400-Problem List-采集的数据-后羿采集器.html

Pro.ID

21695

Title

Parse

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21695

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    The CSV ("Comma Separated Value") file format is often used to exchange data between disparate applications. The file format, as it is used in Microsoft Excel, has become a pseudo standard throughout the industry, even among non-Microsoft platforms.

    The CSV file format in this problem is defined below:

    • A CSV file consists of zero or more records, and a record consists of zero or more fields.

    • Each record ends with a line feed character (ASCII/LF=0x0A).

    However, fields may contain embedded line-breaks (see below) so a record may span more than one line.

    • Fields are separated with commas.

    Example: John,Doe,120 any st.,"Anytown, WW",08123

    • Leading and trailing space-characters in a field are ignored, if they are not delimited by double quotes.

    So John  ,   Doe  ,... resolves to "John" and "Doe", etc. Space characters can be spaces, or tabs.

    • Fields with embedded commas must be delimited with double quote characters.

    In the above example. "Anytown, WW" has to be delimited in double quotes because it has an embedded comma.

    • Fields that contain double quote characters must be entirely surrounded by double quotes, and the embedded double-quotes must each be represented by a pair of consecutive double quotes.

    So, John "Da Man" Doe would convert to "John ""Da Man""",Doe, 120 any st.,...

    • A field that contains embedded line-breaks must be surrounded by double quotes.

    So:

    Field 1: Conference room 1
    Field 2:
       John,
       Please bring the M. Mathers file for review
       -J.L.
    Field 3: 10/18/2002
     ...

    can be converted to:

    Conference room 1, "John,
     Please bring the M. Mathers file for review
     -J.L.
     ",10/18/2002,...

    Note that this is a single CSV record, even though it takes up more than one line in the CSV file. This works because the line breaks are embedded inside the double quotes of the field.

    • Fields with leading or trailing spaces must be delimited with double-quote characters.

    So, to preserve the leading and trailing spaces around, the last name above: John ,"   Doe   ", ...

    • Fields may always be delimited with double quotes.

    The delimiters will always be discarded.

    Your task is to write a program as a CSV parser which can parse the input CSV file correctly.

    输入

    Your program should read the content of input file and parse it according to the CSV format described above. Input is ended by EOF.

    Every field contains no more than 50 characters, and there are at most 500 fields in the input file.

    输出

    Description

    The CSV ("Comma Separated Value") file format is often used to exchange data between disparate applications. The file format, as it is used in Microsoft Excel, has become a pseudo standard throughout the industry, even among non-Microsoft platforms.

    The CSV file format in this problem is defined below:

    • A CSV file consists of zero or more records, and a record consists of zero or more fields.

    • Each record ends with a line feed character (ASCII/LF=0x0A).

    However, fields may contain embedded line-breaks (see below) so a record may span more than one line.

    • Fields are separated with commas.

    Example: John,Doe,120 any st.,"Anytown, WW",08123

    • Leading and trailing space-characters in a field are ignored, if they are not delimited by double quotes.

    So John  ,   Doe  ,... resolves to "John" and "Doe", etc. Space characters can be spaces, or tabs.

    • Fields with embedded commas must be delimited with double quote characters.

    In the above example. "Anytown, WW" has to be delimited in double quotes because it has an embedded comma.

    • Fields that contain double quote characters must be entirely surrounded by double quotes, and the embedded double-quotes must each be represented by a pair of consecutive double quotes.

    So, John "Da Man" Doe would convert to "John ""Da Man""",Doe, 120 any st.,...

    • A field that contains embedded line-breaks must be surrounded by double quotes.

    So:

    Field 1: Conference room 1
    Field 2:
       John,
       Please bring the M. Mathers file for review
       -J.L.
    Field 3: 10/18/2002
     ...

    can be converted to:

    Conference room 1, "John,
     Please bring the M. Mathers file for review
     -J.L.
     ",10/18/2002,...

    Note that this is a single CSV record, even though it takes up more than one line in the CSV file. This works because the line breaks are embedded inside the double quotes of the field.

    • Fields with leading or trailing spaces must be delimited with double-quote characters.

    So, to preserve the leading and trailing spaces around, the last name above: John ,"   Doe   ", ...

    • Fields may always be delimited with double quotes.

    The delimiters will always be discarded.

    Your task is to write a program as a CSV parser which can parse the input CSV file correctly.

    Input

    Your program should read the content of input file and parse it according to the CSV format described above. Input is ended by EOF.

    Every field contains no more than 50 characters, and there are at most 500 fields in the input file.

    Output

    If the input file isn't a legal CSV format file, simply output "Wrong Format" in one line, otherwise you should output all fields. Please output one line-break ('\n') after each field. E.g. suppose the input file is like:

    field11, field12, …, field1n
    field21, field22, …, field2n

    fieldm1, fieldm2, …, fieldmn

    So the output should actually be like:

    field11
    field12

    field1n
    field21
    field22

    field2n

    fieldm1
    fieldm2

    fieldmn

    Note that one field may contain embedded line-breaks, so in the output file one field may occupy several lines. (You can refer to the Sample Input 3 and Sample Output 3 for details).

    Sample Input

    Sample Input 1:
    field11, field12
    field21, field22

    Sample Input 2:
    John,   Doe   , "Anytown, WW" , "John ""Da Mon"" Von"

    Sample Input 3:
    Conference room 1, "John,
    Please bring the M.Mathers file for review
    -J.L.
    ", 3/20/2006

    Sample Input 4:
    John, "Wrong field" sample", Bob

    Sample Output

    Sample Output 1:
    field11
    field12
    field21
    field22

    Sample Output 2:
    John
    Doe
    Anytown, WW
    John "Da Mon" Von

    Sample Output 3:
    Conference room 1
    John,
    Please bring the M.Mathers file for review
    -J.L.
    3/20/2006

    Notes:
    In this case, the second field in input is surrounded by double-quotes thus can take link-breaks in it. So we can see that in the sample output the second field is right there as what it appears in input and a line-break is added after it and before the third field.


    Sample Output 4:
    Wrong Format

    Source

    样例输入

    Sample Input 1:
    field11, field12
    field21, field22

    Sample Input 2:
    John,   Doe   , "Anytown, WW" , "John ""Da Mon"" Von"

    Sample Input 3:
    Conference room 1, "John,
    Please bring the M.Mathers file for review
    -J.L.
    ", 3/20/2006

    Sample Input 4:
    John, "Wrong field" sample", Bob

    样例输出

    Sample Output 1:
    field11
    field12
    field21
    field22

    Sample Output 2:
    John
    Doe
    Anytown, WW
    John "Da Mon" Von

    Sample Output 3:
    Conference room 1
    John,
    Please bring the M.Mathers file for review
    -J.L.
    3/20/2006

    Notes:
    In this case, the second field in input is surrounded by double-quotes thus can take link-breaks in it. So we can see that in the sample output the second field is right there as what it appears in input and a line-break is added after it and before the third field.


    Sample Output 4:
    Wrong Format

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部