扑朔迷离的问题(求助)
查看原帖
扑朔迷离的问题(求助)
478048
Remus_Zograf楼主2021/7/7 21:15

测试点全过

到头来0分。。。

#include<bits/stdc++.h>
using namespace std;
string s;
int t,n,i;
int main()
{
	scanf("%d%d",&n,&t);
	cin>>s;
	int i=0;
	while(s[i]!='.')i++;
	while(i<n&&s[i]<'5')i++;
	if(i==n){cout<<s;return 0;}
	i--;
	int len=0;
	while(t)
	{
		if(s[i]!='.')s[i]++;
		else i--,len=i;
		while(s[i]=='9'&&i>=0)
		{
			s[i--]='0';
		if(i==-1)cout<<'1';
		else{s[i]++;break;}
		}
		if(s[i]<'4')
		{
			len=i;
			break;	
		}
		else
		{
			len=i;
			i--;
		}
		t--;
	}
	for(int k=0;k<=len;k++)
		cout<<s[k];
	return 0;
}
2021/7/7 21:15
加载中...