犯二程度

題目地址: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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章