第一题: #include <iostream> #include <string> using namespace std; int help(string & s) {     int tmp=0,ans=0,judge=0,count=0;     for (auto x : s) {         if (x == '3' || x == '0') {             ans++;             judge++;             tmp = 0;             count = 0;             continue;         }         else {             tmp = tmp * 10 + x - '0';             count++;         }         if (tmp % 3 == 0) {             judge+=count;//使用to_string(tmp).size()也可以,代码简洁但是耗时增加。             count = 0;             ans++, tmp = 0;         }     }     return judge==s.size()?ans:0; } int main(void) {     string nums;     while (cin >> nums) {         cout << help(nums) << endl;     } }
点赞 5

相关推荐

不愿透露姓名的神秘牛友
昨天 11:30
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 17:10
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务