3.24
作者:互联网
1 #include<stdio.h> 2 typedef struct{ 3 int m,n; 4 }element; 5 typedef struct{ 6 element array[50]; 7 int top; 8 }Stack; 9 void Inite(Stack*S) 10 { 11 S->top=-1; 12 } 13 void Push(Stack*S,element e) 14 { 15 S->array[++S->top]=e; 16 } 17 element Pop(Stack*S) 18 { 19 element e; 20 e=S->array[S->top--]; 21 return e; 22 } 23 int G(element k) 24 { 25 Stack T; 26 int result=0; 27 element e; 28 Inite(&T); 29 Push(&T,k); 30 while(T.top!=-1) 31 { 32 if(T.array[T.top].m==0&&T.array[T.top].n>=0) 33 { 34 result=result+0; 35 Pop(&T); 36 } 37 else if(T.array[T.top].m>0&&T.array[T.top].n>=0){ 38 result=result+T.array[T.top].n; 39 e.m=T.array[T.top].m-1,e.n=2*T.array[T.top].n; 40 Pop(&T); 41 Push(&T,e); 42 } 43 } 44 return result; 45 } 46 int main() 47 { 48 element k; 49 scanf("%d %d",&k.m,&k.n); 50 printf("%d",G(k)); 51 return 0; 52 }
标签:int,top,element,result,array,Stack,3.24 来源: https://www.cnblogs.com/JT3895/p/15659598.html