HDU 5373 The shortest problem (水题)

本文详细解析了一个简单的C++代码实例,该代码用于解决一个基础的数学问题。通过遍历字符串并进行数学运算,实现特定逻辑。代码中包含输入处理、字符串操作和循环迭代等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

~~水题,,,

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <time.h>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef long long LL;

char s[1000005];
int main()
{
	int n, t, cnt, cas = 1;
	while (~scanf("%s%d", &s, &t))
	{
		if (s[0] == '-'&&t == -1)
			break;
		int l = strlen(s), sum = 0;
		for (int i = 0; i < l; i++)
			sum += s[i] - '0';
		while (t--)
		{
			int nn = sum;
			itoa(sum, s + l, 10);
			cnt = 0;
			while (nn)
			{
				sum += nn % 10;
				nn /= 10;
				cnt++;
			}
			l += cnt;
		}
		int ans = 0;
		for (int i = 0; i < l; i++)
		{
			if (i & 1)
				ans += s[i] - '0';
			else
				ans -= s[i] - '0';
		}
		if (abs(ans) % 11 == 0)
			printf("Case #%d: Yes\n", cas++);
		else
			printf("Case #%d: No\n", cas++);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值