閱讀568 返回首頁    go 技術社區[雲棲]


poj 1003 Hangover

我隻能說我又刷了一道水題。。。基本題目理解了,就是注意一下強製轉換就可以了。

題目大意:已知c=1/2+1/3+1/4+....1/(n+1).現給出一個值m,求n的值使得c剛好超過m。


AC的代碼:


#include <stdio.h>

int main()
{
	double c;
	int i;

	while(scanf("%lf",&c))
	{
		if(c==0)
			return 0;

		for(i=2; ;i++)
		{
			c-=(double)1/i;
			
			if(c<0)
				break;
		}

		printf("%d card(s)\n",i-1);
	}
	
	return 0;
}


最後更新:2017-04-03 14:53:41

  上一篇:go 技術人員談管理之九大項目管理記憶口訣
  下一篇:go poj 1503 Integer Inquiry【高精度】