解题说明:此题是对一个浮点型的数进行处理,首先判断小数点前一位是否为9,如果不为9就判断小数点后一位是不是超过5,超过5就进1,否则就直接切断。注意到这里进1时只需要对小数点前一位进行加1操作即可,不必担心末位加1会导致再次向前进位,因为末尾为9的情况是单独考虑的。这样题目就简单很多了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
char a[1002];
int i;
int pos1;
scanf("%s",&a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='.')
{
pos1=i;
}
}
if(a[pos1-1]=='9')
{
printf("GOTO Vasilisa.\n");
}
else
{
if(a[pos1+1]>='5')
{
for(i=0;i<pos1-1;i++)
{
printf("%c",a[i]);
}
printf("%c\n",a[i]+1);
}
else
{
for(i=0;i<pos1;i++)
{
printf("%c",a[i]);
}
printf("\n");
}
}
return 0;
}