zoukankan      html  css  js  c++  java
  • [模拟]Educational Codeforces Round 2A Extract Numbers

    Extract Numbers
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string s=";;" contains three empty words separated by ';'.

    You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string a. String a should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string s). By all other words you should build string b in the same way (the order of numbers should remain the same as in the string s).

    Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not.

    For example, for the string aba,123;1a;0 the string a would be equal to "123,0" and string b would be equal to "aba,1a".

    Input

    The only line of input contains the string s (1 ≤ |s| ≤ 105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.

    Output

    Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34).

    If there are no words that are numbers print dash (ASCII 45) on the first line. If all wordsare numbers print dash on the second line.

    Examples
    input
    Copy
    aba,123;1a;0
    output
    Copy
    "123,0"
    "aba,1a"
    input
    Copy
    1;;01,a0,
    output
    Copy
    "1"
    ",01,a0,"
    input
    Copy
    1
    output
    Copy
    "1"
    -
    input
    Copy
    a
    output
    Copy
    -
    "a"
    Note

    In the second example the string s contains five words: "1", "", "01", "a0", "".

    题意:

    给你一个字符串,以‘,’或‘;’来分割单词,并让你给单词分类,a类放没有前导0的非负整数单词,b类放除a类以外的单词,如果某个类为空则输出'-',否则用引号""括起答案输出

    思路:

    现在我们以单词结尾的','或‘;’来进行分割,但一开始输入的字符串如果末尾为‘,’或‘;’,则还应统计一个空格,但这个空格末尾没有','或';'来给我判断,所以为了统一,我们在结尾加上';'
    接着要统计a类和b类单词个数
    如果到了一个单词的结束分割符','或';',则把则个字符标记为分割符,并判断要把当前单词加入a类还是b类,默认当前单词是a类,如果当前单词存在一个非整数位或有前导零则当前单词属于b类
    接着看怎么添加单词,如果当前是第一个加进的单词,就不用在前面加','分割,直接添加当前单词,否则先添一个','再添如当前单词
    输出时如果某个类为空则输出'-',否则用引号""括起答案输出

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int amn=1e5+5;
     4 char s[amn],a[amn],b[amn],tmp[amn];
     5 struct index{
     6     int st,ed;
     7 }idx[amn];
     8 int main(){
     9     ios::sync_with_stdio(0);
    10     cin>>s;
    11     int len=strlen(s);
    12     s[len]=';';                         ///现在我们以单词结尾的','或‘;’来进行分割,但一开始输入的字符串如果末尾为‘,’或‘;’,则还应统计一个空格,但这个空格末尾没有','或';'来给我判断,所以为了统一,我们在结尾加上';'
    13     int st=0,ed=0,tp=0;
    14     int atp=0,btp=0,f=1,it=0;           ///atp和btp分别是统计a类和b类单词个数
    15     for(int i=0;i<=len;i++){
    16         if(s[i]==','||s[i]==';'){       ///到了一个单词的结束
    17             s[i]=0;
    18             if(f&&s[it]){
    19                 if(++atp==1)strcat(a,s+it);        ///如果当前是第一个加进的单词,就不用在前面加','分割,直接添加当前单词
    20                 else strcat(a,","),strcat(a,s+it); ///否则先添一个','再添如当前单词
    21             }
    22             else{
    23                 if(++btp==1)strcat(b,s+it);
    24                 else strcat(b,","),strcat(b,s+it);
    25             }
    26             it=i+1;
    27             f=1;                                    ///默认是符合条件的非负整数
    28         }
    29         else if(s[i]<'0'||s[i]>'9'||((i==0||s[i-1]==0)&&s[i]=='0'&&(s[i+1]>='0'&&s[i+1]<='9')))f=0; ///如果当前单词存在一个非整数位或有前导零则当前单词属于b类
    30     }
    31     int alen=strlen(a),blen=strlen(b);
    32     if(atp){
    33         printf(""");
    34         for(int i=0;i<alen;i++){
    35             printf("%c",a[i]);
    36         }
    37         printf(""
    ");
    38     }
    39     else{                   ///如果没单词,则输出-下面同理
    40         printf("-
    ");
    41     }
    42     if(btp){
    43         printf(""");
    44         for(int i=0;i<blen;i++){
    45             printf("%c",b[i]);
    46         }
    47         printf(""
    ");
    48     }
    49     else{
    50         printf("-
    ");
    51     }
    52 }
    53 /***
    54 给你一个字符串,以‘,’或‘;’来分割单词,并让你给单词分类,a类放没有前导0的非负整数单词,b类放除a类以外的单词,如果某个类为空则输出'-',否则用引号""括起答案输出
    55 现在我们以单词结尾的','或‘;’来进行分割,但一开始输入的字符串如果末尾为‘,’或‘;’,则还应统计一个空格,但这个空格末尾没有','或';'来给我判断,所以为了统一,我们在结尾加上';'
    56 接着要统计a类和b类单词个数
    57 如果到了一个单词的结束分割符','或';',则把则个字符标记为分割符,并判断要把当前单词加入a类还是b类,默认当前单词是a类,如果当前单词存在一个非整数位或有前导零则当前单词属于b类
    58 接着看怎么添加单词,如果当前是第一个加进的单词,就不用在前面加','分割,直接添加当前单词,否则先添一个','再添如当前单词
    59 输出时如果某个类为空则输出'-',否则用引号""括起答案输出
    60 ***/
  • 相关阅读:
    如何修改Linux命令提示符
    HTTP 状态码及对应字符串详解
    Java 获取键盘输入
    Java中的IO整理完整版(一)
    清除代码异味
    报告称当前Linux人才抢手 高薪也难觅
    QT修改程序图标
    java中的io系统详解
    如果AntlrWorks的Debug报错“当前端口已被占用”,可能是防火墙的原因
    报表引擎 - 研究润乾报表的实现
  • 原文地址:https://www.cnblogs.com/Railgun000/p/11310974.html
Copyright © 2011-2022 走看看