码迷,mamicode.com
首页 > 其他好文 > 详细

codeforce 600A - Extract Numbers

时间:2015-11-28 12:01:24      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

学习string

技术分享
 1 #include <bits/stdc++.h>
 2 #define eps 1e-8
 3 #define M_PI 3.141592653589793
 4 const int N = 100005;
 5 using namespace std;
 6 
 7 string st;
 8 vector<string>v1,v2;
 9 
10 bool judge(string str)
11 {
12     if(str.size()==0)
13         return false;
14     for(int i=0; i<str.size(); i++)
15     {
16         if(str[i]>9||str[i]<0)
17             return false;
18     }
19     if(str.size()>1&&str[0]==0)
20         return false;
21     return true;
22 }
23 
24 void add(string str)
25 {
26     if(judge(str))
27         v1.push_back(str);
28     else
29         v2.push_back(str);
30 }
31 
32 int  main()
33 {
34     cin>>st;
35     string temp="";
36     for(int i=0; i<st.size(); i++)
37     {
38         if(st[i]==,||st[i]==;)
39         {
40             add(temp);
41             temp="";
42         }
43         else
44             temp+=st[i];
45     }
46     add(temp);
47 
48     if(v1.size()==0)
49         cout<<"-"<<endl;
50     else
51     {
52         cout<<"\"";
53         for(int i=0; i<v1.size(); i++)
54         {
55             if(i)
56                 cout<<",";
57                 cout<<v1[i];
58         }
59         cout<<"\"";
60         cout<<endl;
61     }
62     if(v2.size()==0)
63         cout<<"-"<<endl;
64     else
65     {
66         cout<<"\"";
67         for(int i=0; i<v2.size(); i++)
68         {
69             if(i)
70                 cout<<",";
71                 cout<<v2[i];
72         }
73         cout<<"\"";
74         cout<<endl;
75     }
76     return 0;
77 }
View Code

 

codeforce 600A - Extract Numbers

标签:

原文地址:http://www.cnblogs.com/ITUPC/p/5002361.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!