标签:ice size cep i++ can output created sea 奇数
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7624 | Accepted: 4586 |
Description
Input
Output
Sample Input
8 7 2 1 8 4 3 5 6
Sample Output
17
Source
1 #include <iostream> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <algorithm> 7 #define MAXN 150010 8 using namespace std; 9 int a[MAXN]; 10 int main() 11 { 12 int n; 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 15 int ans=0; 16 bool b=1; 17 for(int i=1;i<=n;i++) 18 { 19 if(b) 20 { 21 if(a[i]>a[i+1]) {ans+=a[i];b=0;} 22 else continue; 23 } 24 else 25 { 26 if(a[i]<a[i+1]) {ans-=a[i];b=1;} 27 else continue; 28 } 29 } 30 printf("%d",ans); 31 return 0; 32 }
标签:ice size cep i++ can output created sea 奇数
原文地址:http://www.cnblogs.com/YXY-1211/p/7137773.html