zoukankan      html  css  js  c++  java
  • cidefirces Educational Codeforces Round 2 A. Extract Numbers

    A. Extract Numbers

     

    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 words are numbers print dash on the second line.

    Sample test(s)
    Input
    aba,123;1a;0
    Output
    "123,0"
    "aba,1a"
    Input
    1;;01,a0,
    Output
    "1"
    ",01,a0,"
    Input
    1
    Output
    "1"
    -
    Input
    a
    Output
    -
    "a"
    Note

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

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<vector>
     4 #include<cmath>
     5 #include<queue>
     6 #include<string>
     7 #include<map>
     8 #include<cstring>
     9 #include<algorithm>
    10 using namespace std;
    11 typedef long long ll;
    12 typedef unsigned long long ull;
    13 const int maxn=1e5+5;
    14 vector<string>v1,v2;
    15 int main()
    16 {
    17     char s[maxn],t[maxn];
    18     scanf("%s",s);
    19     int len=strlen(s);
    20     int k=0;
    21     for(int i=0;i<len;i++)
    22     {
    23         if(s[i]==','||s[i]==';')
    24         {
    25             t[k]='';
    26             string ss=t;
    27             if(!k)v1.push_back("");
    28             else
    29             {
    30                 int j=0;
    31                 for(j=0;j<k;j++)
    32                     if(t[j]<'0'||t[j]>'9')break;
    33                 if(j!=k)v1.push_back(ss);
    34                 else
    35                 {
    36                     for(j=0;j<k;j++)
    37                         if(t[j]!='0')break;
    38                     if(j==0||k==1)v2.push_back(ss);
    39                     else v1.push_back(ss);
    40                 }
    41                 k=0;
    42                 continue;
    43             }
    44         }
    45         else
    46         t[k++]=s[i];
    47     }
    48     if(k)
    49     {
    50         t[k]='';
    51         string ss=t;
    52         int j=0;
    53         for(j=0;j<k;j++)
    54             if(t[j]<'0'||t[j]>'9')break;
    55         if(j!=k)v1.push_back(ss);
    56         else
    57         {
    58             for(j=0;j<k;j++)
    59                 if(t[j]!='0')break;
    60             if(j==0||k==1)v2.push_back(ss);
    61             else v1.push_back(ss);
    62         }
    63     }
    64     else v1.push_back("");
    65     if(v2.size()==0)
    66     {
    67         puts("-");
    68         printf("%c",34);
    69         for(int i=0;i<(int)v1.size()-1;i++)
    70             cout<<v1[i]<<",";
    71         cout<<v1[(int)v1.size()-1];
    72         printf("%c
    ",34);
    73     }
    74     else if(v1.size()==0)
    75     {
    76         printf("%c",34);
    77         for(int i=0;i<(int)v2.size()-1;i++)
    78             cout<<v2[i]<<",";
    79         cout<<v2[(int)v2.size()-1];
    80         printf("%c
    ",34);
    81         puts("-");
    82     }
    83     else
    84     {
    85         printf("%c",34);
    86         for(int i=0;i<(int)v2.size()-1;i++)
    87             cout<<v2[i]<<",";
    88         cout<<v2[(int)v2.size()-1];
    89         printf("%c
    ",34);
    90         printf("%c",34);
    91          for(int i=0;i<(int)v1.size()-1;i++)
    92             cout<<v1[i]<<",";
    93         cout<<v1[(int)v1.size()-1];
    94         printf("%c
    ",34);
    95     }
    96     return 0;
    97 }
  • 相关阅读:
    redis持久化RDB与AOF
    oracle PL/SQL习题
    pl/sql中的三种循环
    转 Oracle Cursor用法总结
    Oracle与MySQL的SQL语句区别
    安装mysql 遇到最后一步卡死解决方案
    Oracle安装
    mysql安装
    sql语句的优先级
    MVC设计模式
  • 原文地址:https://www.cnblogs.com/homura/p/5002238.html
Copyright © 2011-2022 走看看