犯二程度

博客介绍了判断一个数是否为偶数的技巧,即判断该数的个位数是否为偶数。还给出了题目地址https://pintia.cn/problem - sets/994805046380707840/problems/994805121500692480。

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

题目地址:https://pintia.cn/problem-sets/994805046380707840/problems/994805121500692480
在这里插入图片描述

技巧

判断一个数是不是偶数,判断它的个位数是不是偶数就行啦!

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>

#define debug true
using namespace std;



int main() {
#if debug
	freopen("in.txt", "r", stdin);
#endif // debug
	
	double mult1 = 1;
	double mult2 = 1;
	string str;
	int fu = 0;
	cin >> str;
	if (str[0] == '-')
	{
		fu = 1;
		mult1 = 1.5;
	}

	// 判断一个数是不是偶数,判断它的个位数就行啦!
	if ((str[str.size() - 1] - '0')% 2 == 0)
	{
		mult2 = 2;
	}
	double count = 0;
	for (size_t i = 0; i < str.size(); i++)
	{
		if (str[i] == '2')
		{
			count++;
		}
	}

	double temp = count / (str.size() - fu);
	printf("%.2lf%%", temp * mult1 * mult2 * 100);


	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值