参考:https://blog.csdn.net/kuroko_ghh/article/details/80968412
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 int main() 6 { 7 float a; 8 while (cin>>a) 9 { 10 if (a==0) 11 { 12 break; 13 } 14 float t=0; 15 int l=0; 16 for (int i=2;t<a;i++) 17 { 18 t+=1.0/i;//如果是1/i将陷入死循环! 19 l++; 20 } 21 cout<<l<<' '<<"card(s)"<<endl; 22 } 23 24 return 0; 25 }