个人练习题

个人练习

#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;//自己的输出验证
	}
}
//处理结果
	//1.先对数字本体每一位取余,然后另一个变量保存余位,之后本体除10,处理完第一轮之后,对结果进行判断
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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值