1058. A+B in Hogwarts (20)

本文探讨了字符串处理和进制转换的基本算法,通过C++代码实例详细展示了如何将字符串转换为十进制整数,并进行进一步的运算。涵盖了字符识别、数值解析、进制转换等核心概念。

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

1.该题不难,主要是字符串的处理和进制处理


AC代码:

//#include<string>
//#include<stack>
//#include<unordered_set>
//#include <sstream>
//#include "func.h"
//#include <list>
#include <iomanip>
#include<unordered_map>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include <algorithm>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
#include<stack>
using namespace std;

bool isNum(char c)
{
	if (c <= '9'&&c >= '0') return true;
	else return false;
}
void string2Num(string a,int&a1, int&a2, int&a3)
{
	int idx = 0;
	for (int i = 0; i < a.size(); i++)
	{
		if (idx == 0 && isNum(a[i]))
			a1 = a1 * 10 + a[i] - '0';
		else if (idx == 1 && isNum(a[i]))
			a2 = a2 * 10 + a[i] - '0';
		else if (idx == 2 && isNum(a[i]))
			a3 = a3 * 10 + a[i] - '0';
		else if (a[i] == '.')
		{
			idx++;
		}
	}
}
int main(void)
{
	
	string a, b;
	cin >> a >> b;
	int a1 = 0, a2 = 0, a3 = 0;
	int b1 = 0, b2 = 0, b3 = 0;

	string2Num(a, a1, a2, a3);
	string2Num(b, b1, b2, b3);

	int carry = 0;
	a3 = a3 + b3;
	carry = a3 / 29;
	a3 %= 29;
	a2 = a2 + b2 + carry;
	carry = a2 / 17;
	a2 %= 17;
	a1 = a1 + b1 + carry;

	printf("%d.%d.%d\n", a1, a2, a3);

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值