水题,好久不写C++,拿来练手的
题目:
Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
Output
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
#include
using namespace std;
void OutPut(double input)
{
double sum=0.00;
int i=1.0;
while(sum<input)
{
sum=sum+1.0/(i+1);
i++;
}
cout<<int(i-1)<<"card(s)\n";
}
int main()
{
double input;
cin>>input;
while(input)
{
if(input<0.01||input>5.20)
{
cin>>input;
continue;
}
OutPut(input);
cin>>input;
}
getchar();
return 1;
}
结果如图