#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; } }