L1-017 到底有多二

题目 L1-017 到底有多二

image-a0cd0b8e

思路分析

s.front()

s.back()

s.erase(s.begin())

判断偶数 %2==0

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

int main()

{

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	//50位 不可能用整型存 用字符串处理

	string s;cin>>s;

	bool isfu=false,isou=false;

	if(s.front()=='-')	 {

		isfu=true;

		s.erase(s.begin());

	}

	if(((s.back() - '0') % 2 == 0))

		isou=true;

	int total=0,have2=0;

	for(auto c:s){

		total++;

		if(c=='2')

			have2++;

	}

	double ans;

	ans = have2 * 100.0 / total;

	if(isfu)	ans*=1.5;

	if(isou)	ans*=2;

	printf("%.2lf%%\n", ans);

	return 0;

}

同类题型

视频讲解


⬅️ L1-016 查验身份证 🏠 00-天梯赛 ➡️ L1-018 大笨钟