1.能不用strlen,尽量不用
2.for循环的操作放前放后问题,本题的flag 放置问题
思路,先找第一个大于5的,t-- 还有到整数就不继续进位
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int main()
{
char s[300000];
int n,t,t1;
int point;
// freopen("test.txt","r",stdin);
memset(s,0,sizeof(s));
scanf("%d%d%s",&n,&t,s);
t1=t;
for(int i=n+1;i>=1;i--)
{
s[i]=s[i-1];
}
s[0]='0';
for(int i=1;i<=n;i++)
if(s[i]=='.')
point = i;
int flag = 0;
for(int i=point+1;i<strlen(s);i++)
{
if(s[i]>='5')
{
flag = i;
break;
}
}
while(t--)
{
if(s[flag]<'5')
break;
s[flag]='\0';
if(s[flag-1]=='.')
{
for(int i=point-1;i>=0;i--)
{
if(s[i]=='9')
s[i]='0';
else
{
s[i]+=1;
break;
}
}
break;
}
s[--flag] +=1;
}
for(int i=strlen(s)-1;i>=point;i--)
{
if(s[i]!='0'&&s[i]!='.')
break;
s[i]='\0';
}
if(s[0]=='1')
printf("1");
puts(s+1);
return 0;
}