#include <iostream> using namespace std; int getSum(string str, int begin, int len) { int sum = 0; while (begin < len) { sum += str.at(begin++) - '0'; } return sum; } void findSubStr(string str) { int strlen = str.length(); int sublen = strlen; while (sublen > 1) { //长度控制 int front = 0; int sublenTmp = sublen; int sum = getSum(str, front, sublen); while (sublenTmp <= strlen) { //范围控制 if (sum % 3 == 0) { // cout << sum << ' '; //args2是长度 cout << str.substr(front, sublenTmp - front) << endl; } if (sublenTmp + 1 <= strlen) { sum -= str.at(front++) - '0'; sum += str.at(sublenTmp++) - '0'; } else { break; } } sublen--; } }