2141:2333(zznuoj)
2141: 2333
时间限制: 1 Sec 内存限制: 128 MB提交: 77 解决: 17
[提交] [状态] [讨论版] [命题人:admin]
题目描述
“别人总说我瓜,其实我一点也不瓜,大多数时候我都机智的一批“ 宝儿姐考察你一道很简单的题目。给你一个数字串,你能判断有多少个连续子串能整除3吗?
输入
多实例输入,以EOF结尾,每行一个数字串(长度<=1e6)
输出
每行一个数字串,表示能整除3的连续子串的个数
样例输入
2333
样例输出
6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <iostream> #include <cstdio> #include <map> #include <string> #include<cstring> #include<algorithm> #include<vector> typedef long long ll; const int maxn = 1010000; using namespace std; int n, m,res; int a[maxn]; int main() { string sr; while (cin >> sr) { int len = sr.length(); for ( int i = 0; i < len; i++) a[i + 1] = (a[i] + sr[i] - '0' )%3; int num[3] = { 0 }; num[0] = 1; ll ans = 0; for ( int i = 1; i <= len; i++) { ans += num[a[i]]; num[a[i]]++; } cout << ans << endl; } return 0; } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步