个人练习
#include<iostream>
#include<vector>
using namespace std;
int DealWithTheNumber(int& number);
int main() {
string str;
cin >> str;
vector<int> ans = { 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < str.size(); i++)
{
switch (i % 6)
{
case 0:
ans[0] += str[i];
break;
case 1:
ans[1] += str[i];
break;
case 2:
ans[2] += str[i];
break;
case 3:
ans[3] += str[i];
break;
case 4:
ans[4] += str[i];
break;
case 5:
ans[5] += str[i];
break;
}
}
for (int i = 0; i < 6; i++)
{
cout << ans[i] << endl;
}
for (int i = 0; i < 6; i++)
{
DealWithTheNumber(ans[i]);
cout << ans[i] << endl;
}
}
int DealWithTheNumber(int &number)
{
int temp = 0;
while (number>0)
{
temp += number % 10;
number /= 10;
}
number = temp;
if (number > 9)
{
DealWithTheNumber(number);
}
else return number;
}