[Usaco2002 Open]Wiggle Numbers摆动数

来源:互联网 发布:网络语谐音 编辑:程序博客网 时间:2024/06/07 13:46

[Usaco2002 Open]Wiggle Numbers摆动数

时间限制: 1 Sec 内存限制: 128 MB

题目描述

摇摆数是像下面的数:3748,67,869,32435465768,它们每个数每位数码的变化是:上升,下降,上升,下降,…,或者:下降,上升,下降,上升,…,上面4个数表示如下:3 < 7 > 4 < 8 and 3 > 2 < 4 > 3 < 5 > 4 < 6 > 5 < 7 > 6 < 8。特别规定一位整数也是一个摇摆数。输入一个长度不超过75位的数,计算并输出从该数的第1个数码开始,可以形成摇摆数的长度。

输入

一行,一个长度不超过75位的数

输出

1个整数,从第1个数码开始形成的摇摆数的长度

样例输入

3748

样例输出

4

var a:string; i,j,k,ans:longint;begin readln(a); for i:=1 to length(a) do  if i=1  then begin inc(ans); j:=1; end  else   if j=1   then    if a[i]>a[i-1]    then begin inc(ans); j:=0; end    else break   else    if a[i]<a[i-1]    then begin inc(ans); j:=1; end    else break; k:=ans; ans:=0; for i:=1 to length(a) do  if i=1  then begin inc(ans); j:=0; end  else   if j=1   then    if a[i]>a[i-1]    then begin inc(ans); j:=0; end    else break   else    if a[i]<a[i-1]    then begin inc(ans); j:=1; end    else break; if ans>k then writeln(ans) else writeln(k);end.
0 0
原创粉丝点击