def f(n): f=1 global ans #global 表示此处的 ans 就是全局变量 ans ans=str(a[n-1]) for i in range(n-2,-1,-1): if b[i]: f=f+1 ans=str(a[i])+","+ans return f s=input() a=[0]*20 b=[False]*20 flag,n,i,t,ans=0,0,0,'','' for ch in s: if ch==',': a[i]=int(t) n+=1 i+=1 t='' else: __________ for i in range(1,n): gd=True if flag==0: if a[i]>a[i-1]: flag=1 elif a[i]<a[i-1]: flag=2 else: gd=False elif __________: flag=2 elif flag==2 and a[i]>a[i-1] : flag=1 else: gd=False __________ if f(n)<3: print('不构成摇摆子序列') else: print('最长摇摆子序列长度为:',str(f(n))) print('最长摇摆子序列为:',ans)