筆試題—股神

#include <stdio.h>

int calut(int m){
	int count,temp,h ;
	temp = m;
	for (int j=1; temp-j>=0; j++){
      temp=temp-j;
      h=j;
      count=1+(j-2)*(j-1)/2;
	}
  if((m-(h+1)*h/2)>0)
    count=count+(m-(h+1)*h/2);
    return count;
}

int main(){
	int m,cnt=0;
	scanf("%d",&m);
	cnt=calut(m);
	printf("%d\n",cnt);
	return 0;
}
第一次筆試題調試成功,謹以此文章作爲紀念,用以自勉!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章