B : Heshen's Account Book

时间限制:1000ms  单点时限:1000ms  内存限制:512MB

描述

Heshen was an official of the Qing dynasty. He made a fortune which could be comparable to a whole country's wealth by corruption. So he was known as the most corrupt official in Chinese history. But Emperor Qianlong liked, or even loved him so much that was not punished during Qianlong's regime even everybody knew he was totally corrupted.

After Qianlong quit his job, his son Jiaqing took the throne. The new Emperor hated Heshen very much, so he threw Heshen into jail and awarded him death immediately after Qianlong died. Of course Jiaqing would not forget to raid Heshen's house for money --- that was the story of "Heshen fell, Jiaqing full."

Jiaqing's man got a notebook from Heshen's home which was obviously an account book.But the text of the book was written in English! Jiaqing thought all numbers in that account book should stand for money. Please find out all numbers for Jiaqing.

The text of the account book consists only lower case letters, spaces, and digits
('0' - '9'). One or several consecutive digits form a number. But Jiaqing only cared about the ACTUAL numbers among all numbers. Only if a number DOESN'T satisfy any of the conditions below, it is an ACTUAL number:

1) The character to the left of the number is a lower case letter, for example: a123

2) The character to the right of the number is a lower case letter, for example: 123b

3) The number has one or more extra leading zeros, such as 01 , 0012….

Please note that if the last character of a line is a digit, and the first character of the next line is also a digit, those two digits are considered consecutive.

输入

There are no more than 200 lines. The length of each line is no more than 1000 characters.

And it is guaranteed that every number's length is no more than 18.

There may be spaces at the end of a line, and those spaces matter.

No blank lines in the input. A line consisting of only spaces is not a blank line.

输出

Print all ACTUAL numbers in a single line in the original order.
Then, count the number of ACTUAL numbers of each line, and print them. A number X only belongs to the line which contains the first digit of X.

样例解释

We assume there is no spaces at the end of each line in the Sample Input.

In the sample input, the '3' at the end of the second line and the '2' at the beginning of the third line are considered consecutive, so "1323" is a number.  But this number only belongs to the second line, so the third line has only 2 numbers ---- 14 and 344..

样例输入

a19 01 17b
12 bdc 13
23 14 344 bc

样例输出

12 1323 14 344
0
2
2

题意:

给你一个文本,文本中只包含小写字母,空格和数字字符,然后你要提炼出文本中所有的合法数字,且还要输出每一行有多少个合法数字,其中合法数字满足:

  • 一串连续的数字字符
  • 前面和后面都不能紧接小写字母
  • 不能出现前导0

除此之外,如果某一行的末尾是数字字符,下一行的开头也是数字字符,那么它们可以被视作连在一起的,不过这段数字若合法仍然算在前一行里面

思路:

看起来就是个签到题,但是坑比较多,比如单个0,或者被段切割的数字等等

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define LL unsigned long long
#define mod 1000000007
char str[200005];
int ans[1005], id[200005];
LL p[200005];
int main(void)
{LL now;int n, i, ok, cnt, bel, tot, len;len = 1, cnt = tot = 0;bel = ok = now = 0;while(gets(str+len)!=NULL){cnt++;n = len-1+strlen(str+len);if(len!=1 && (str[len]<'0' || str[len]>'9' || str[len-1]<'0' || str[len-1]>'9')){for(i=n;i>=len;i--)str[i+1] = str[i];str[len] = ' ';n++;}for(i=len;i<=n;i++)id[i] = cnt;len = n+1;}str[++n] = ' ';for(i=1;i<=n;i++){if(str[i]>='1' && str[i]<='9'){if(ok==1)now = now*10+str[i]-'0';else   {if(str[i-1]==' ' || i==1){ok = 1, bel = id[i];now = str[i]-'0';}}}else if(str[i]=='0'){if(ok==1)now = now*10;else{if((str[i-1]==' ' || i==1) && str[i+1]==' '){ans[++tot] = 0;ans[id[i]]++;}}}else if(str[i]==' '){if(ok==1){p[++tot] = now;ans[bel]++;now = ok = 0;}}else{if(ok==1)ok = 0, now = 0;}}if(tot>=1){printf("%llu", p[1]);for(i=2;i<=tot;i++)printf(" %llu", p[i]);}printf("\n");for(i=1;i<=cnt;i++)printf("%d\n", ans[i]);return 0;
}

2018北京ICPC B. Heshen's Account Book(模拟)相关推荐

  1. 2018北京ICPC D. Frog and Portal(构造)

    D : Frog and Portal 时间限制:1000ms  单点时限:1000ms  内存限制:512MB 描述 A small frog wants to get to the other s ...

  2. 2018北京ICPC H. Approximate Matching(AC自动机+DP)

    H : Approximate Matching 时间限制:1000ms,单点时限:1000ms,内存限制:512MB 描述 String matching, a common problem in ...

  3. [2018北京ICPC网络赛H] HihoCoder - 1835 K-Dimensional Foil II(点到平面的距离)

    题目链接: 点击前往 题目: 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 "K-Dimensional Foil" is a dimensional ...

  4. 2018青岛ICPC ZOJ 4061: Magic Multiplication(模拟)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意: 定义一种新型运算符: 也就是说Gao(23, 45 ...

  5. 解题报告(一)F、(2018 ACM - ICPC shenyang I)Distance Between Sweethearts(数学期望 + 乘法原理 + FWT)(4.5)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  6. 2018焦作ICPC E - Resistors in Parallel(规律+Java大数)

    2018焦作ICPC E - Resistors in Parallel题目链接 Time limit  2000 ms Memory limit  1048576 kB In this physic ...

  7. The Open Group 2018 北京峰会召开,看行业大咖都说了哈?

    The Open Group 2018 北京峰会"数字化时代企业变革与人才转型"于8月20日正式拉开帷幕.此次峰会汇集知名企业.国内外顶级专家共同分享数字业务转型.峰会由The O ...

  8. ACM-ICPC 2018 北京赛区网络预赛(A B C D H)

    ACM-ICPC 2018 北京赛区网络预赛(A B C D H) 自闭症患者 A. Saving Tang Monk II 题目链接 题面: 划掉 题意: 大搜索,队友写的 思路: 大搜索,队友写的 ...

  9. 北京理工大学计算机学院研究生培养方案,2018北京理工大学非全日制研究生专业学位培养方案...

    [导读]2018北京理工大学非全日制研究生专业学位培养方案包括培养目标.培养方式.学制.课程设置与学分要求.必修环节.培养环节及学位论文相关工作和教学大纲要求等七个部分. 一.培养目标 2018北京理 ...

最新文章

  1. 科研 | Nature:新型土壤细菌具有多种合成次级代谢物的基因
  2. [深度学习] Pytorch nn.CrossEntropyLoss()和nn.NLLLoss() 区别
  3. 诺贝尔奖得主Paul Krugman认可bch发展路线
  4. 嵌入式系统功能需求分析_超市监控系统的功能作用分析
  5. mysql数据库varchar的区别_MySQL数据库char与varchar的区别分析及使用建议
  6. php integer
  7. 【机器学习算法-python实现】决策树-Decision tree(2) 决策树的实现
  8. 编码练习——Java-2-流程控制
  9. c#重命名文件 递归_文件结构、文件操作及压缩解压操作
  10. html怎么样做出两列布局页面,HTML+CSS实现两栏和三栏布局
  11. 47.本地Hyper-V虚拟机的异地(Azure)容灾(上)
  12. 从浏览器启动客户端程序的方法
  13. Deskew Technologies Gig Performer 4 Mac(现场调音机架)
  14. Centos7 防火墙常用配置
  15. 如何解决SSM框架前台传参数到后台乱码的问题
  16. C#可空类型(Nullable)
  17. Android 8.0 解决不能自动安装APK问题(完美适配)
  18. 人工智能终究会抢了我们程序员的饭碗
  19. HTML5CSS3知识点总结(1)
  20. android棒棒糖,Android L正式定名Lollipop(棒棒糖)

热门文章

  1. 自学python能干些什么副业-用Python赚钱的5个方法,教你业余时间赚外快!
  2. python自学要多久-自学Python要学多久可以学会?
  3. 自学python能干什么-学习python可以做什么
  4. python爬虫怎么赚钱-如何用爬虫技术赚钱?
  5. python最适合做什么-python学完之后比较适合哪些职业工作呢?
  6. redis 能不能监听特定的key失效_Spring boot实现监听Redis key失效事件实现和其它方式...
  7. Error in mounted hook: “TypeError: Cannot read property ‘init‘ of undefined“
  8. vuex-token的持久化
  9. Leetcode445 两数相加||(单链表)
  10. 最简单的基于FFmpeg的内存读写的例子:内存转码器