Heshen‘s Account Book(HihoCoder - 1871)(找规律)

Time limit1000 ms
Memory limit524288 kB
judge:vjudge
hihocoder

描述

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


judge:vjudge
hihocoder

样例输入

a19 01 17b
12 bdc 13
23 14 344 bc

样例输出

12 1323 14 344
0
2
2

题解

模拟 + 猜题意

这道题WA了十几发之后也不知道错哪了,后来搜了题解发现我根本连题意都不清楚。。。

说几个比较坑的点:

  • 123abc456是可以被识别为123456
  • i行末尾是数字并且第i+1行开头也是数字时是要连起来看成一个整体的,但是当第i行的末尾有空格或者第i+1行有空格时是不能连起来的。
  • 一个空格可以作为一行单独出现
  • i行的末尾是纯数字,第i+1行的开头也是数字,但是第i+1行的开头部分的结尾是字母,这时算作错误格式。例如:
    123
    456a
    
  • 同理当第i行的末尾是个0,第i+1行的开头是数字,那么这个0将被看作是前导0,无论第i+1行的开头是不是纯数字,他们都将不作数。
  • i行的末尾部分的开头是字母,也将会牵连到第i+1行的开头部分(如果是数字的话)。
  • 0单独出现时可以被看做一个数字

再放几组测试数据:

in:
123abc456

out:
123456
1

in:
123 (有个空格)
456

out:
123 456
1
1

in:
123
 456

out:
123 456
1
1

in:
123
 (有个空格)
456

out:
123 456
1
0
1

in:
1 123
456a 2

out:
1 2
1
1

in:
1 0
123 0
12a 2

out:
1 2
1
0
1

in:
a123
4

out:
0
0

in:
0 1

out:
0 1
2

代码

#include <bits/stdc++.h>
#define _for(i, a) for(register int i = 0, lennn = (a); i < lennn; ++i)
#define _rep(i, a, b) for(register int i = (a), lennn = (b); i <= lennn; ++i)
using namespace std;
typedef long long LL;
const int maxn = 200005;

char s[maxn], str[205][1005];
int ind[maxn], n, m, num[maxn];
vector<LL> ans;

int main() {
    // freopen("in.txt", "r", stdin);
    for(m = 0; gets(str[m]); ++m);
    _for(i, m) {
        strcpy(s + n, str[i]);
        ind[n] = 1;
        n = strlen(s);
        if(!isdigit(s[n - 1]) || i + 1 < m && !isdigit(str[i + 1][0])) s[n++] = ' ';
    }
    _rep(i, 1, n) ind[i] += ind[i - 1];
    for(int l = 0, r = l; r < n; l = ++r) {
        while(r < n && s[r] != ' ') ++r;
        if(isdigit(s[l]) && isdigit(s[r - 1]) && (s[l] != '0' || l == r - 1)) {
            ++num[ind[l]];
            LL tem = 0;
            for(; l < r; ++l) if(isdigit(s[l])) tem = tem * 10 + s[l] - '0';
            ans.push_back(tem);
        }
    }
    _for(i, ans.size()) printf("%lld%s", ans[i], i == ans.size() - 1 ? "\n":" ");
    _rep(i, 1, m) printf("%d%s", num[i], i == m ? "":"\n");
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值