心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
<2011年5月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

留言簿(15)

随笔分类(415)

随笔档案(400)

搜索

  •  

最新随笔

最新评论

评论排行榜

从左向右扫描一遍即可。
以下是我的代码:
#include<iostream>
#include
<vector>
#include
<cstdio>
#include
<cstdlib>
using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen(
"data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    
#endif

    
int n;
    
while(scanf("%d",&n)==1 && n)
    {
        vector
<int> r;
        
for(int i=0;i<n;i++)
        {
            
int t;
            scanf(
"%d",&t);
            r.push_back(t);
        }

        
long long ans(0);
        
for(int i=0;i<n-1;i++)
        {
            r[i
+1]+=r[i];
            ans
+=abs(r[i]);
        }

        cout
<<ans<<endl;
    }
}
posted on 2011-05-16 17:26 lee1r 阅读(241) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:基础/模拟

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理