犯二程度

题目地址: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;
}
发布了101 篇原创文章 · 获赞 13 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/a735311619/article/details/88751712