0 of 1 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 1 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
阅读程序,根据输入写出输出结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <iostream> using namespace std; const int SIZE=20; int data[SIZE]; int n,i,h,ans; void merge(){ data[h-1]=data[h-1]+data[h]; h--; ans++; } int main(){ cin>>n; h=1; data[h]=1; ans=0; for (i =2; i <=n; i++){ h++; data[h]=1; while(h>1&&data[h]==data[h-1]) merge(); } cout<<ans<<endl; } |
输入:8
输出:
输入:2012
输出:
(2012年提高组)