codeforce 600A - Extract Numbers

学习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 }

时间: 2025-01-01 04:35:14

codeforce 600A - Extract Numbers的相关文章

Codeforce 9C - Hexadecimal&#39;s Numbers

One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain tota

codeforce round#466(div.2)C. Phone Numbers

C. Phone Numbers time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find th

Codeforce 401D Roman and Numbers[数位DP+状态压缩]

给出数n和m,求n的所有排列中,模m得0的有多少个 n (1?≤?n?<?1018) and m (1?≤?m?≤?100). 暴力法我们直接枚举n的所有排列,显然18!超时. 考虑怎么dp 假设给了我们数n=23765 显然有 (237%m*10+6)%m=2376%m (367%m*10+2)%m=3672 我们很自然的想到了 这样的状态转移 dp[i][k] i代表取的数的状态 代表在取数状态为i的情况下模m为k的数有多少 比如 对于23765的356 取数状态为01011 dp方程就是

Codeforce 22B Bargaining Table

B. Bargaining Table Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n?×?m meters. Each square meter of the room is either occupied by so

Codeforce Circle Line 环形数据操作

The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station; ... dn?-?1 is t

CodeForce 113B DP

Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find t

Two progressions CodeForce 125D 思维题

An arithmetic progression is such a non-empty sequence of numbers where the difference between any two successive numbers is constant. This constant number is called common difference. For example, the sequence 3, 7, 11, 15 is an arithmetic progressi

LeetCode OJ - Sum Root to Leaf Numbers

这道题也很简单,只要把二叉树按照宽度优先的策略遍历一遍,就可以解决问题,采用递归方法越是简单. 下面是AC代码: 1 /** 2 * Sum Root to Leaf Numbers 3 * 采用递归的方法,宽度遍历 4 */ 5 int result=0; 6 public int sumNumbers(TreeNode root){ 7 8 bFSearch(root,0); 9 return result; 10 } 11 private void bFSearch(TreeNode ro

129. Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. For example, 1 / 2 3 T