初遇ACM之A+B问题

主要是熟悉下ACM格式。。。

1.  http://acm.hdu.edu.cn/showproblem.php?pid=1089

 

#include<iostream>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)
        cout<<a+b<<endl;
    return 0;
}

 

 

2.  http://acm.hdu.edu.cn/showproblem.php?pid=1090

 

#include<iostream>
using namespace std;
int main()
{
    int a,b,N;
    cin>>N;
    while(N--)
    {
        cin>>a>>b;
        cout<<a+b<<endl;
    }        
    return 0;
}

 

3.   http://acm.hdu.edu.cn/showproblem.php?pid=1091

 

#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    while(a!=0 || b!=0)
    {        
        cout<<a+b<<endl;
        cin>>a>>b;
    }        
    return 0;
}

 

4.  http://acm.hdu.edu.cn/showproblem.php?pid=1092

 

#include<iostream>
using namespace std;
int main()
{
    int N,a,s,i;
    cin>>N;
    while(N!=0)
    {    
        s=0;    
        for(i=0; i<N; i++)
        {
            cin>>a;
            s+=a;
        }
        cout<<s<<endl;    
        cin>>N;
    }        
    return 0;
}

 

5.  http://acm.hdu.edu.cn/showproblem.php?pid=1093

 

#include<iostream>
using namespace std;
int main()
{
    int T,N,a,s,i;
    cin>>T;
    while(T--)
    {    
        cin>>N;
        s=0;    
        for(i=0; i<N; i++)
        {
            cin>>a;
            s+=a;
        }
        cout<<s<<endl;            
    }        
    return 0;
}

 

6.  http://acm.hdu.edu.cn/showproblem.php?pid=1094

 

#include<iostream>
using namespace std;
int main()
{
    int N,a,s,i;
    while(cin>>N)
    {    
        s=0;    
        for(i=0; i<N; i++)
        {
            cin>>a;
            s+=a;
        }
        cout<<s<<endl;            
    }        
    return 0;
}

 

7.  http://acm.hdu.edu.cn/showproblem.php?pid=1095

 

#include<iostream>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)    
        cout<<a+b<<endl<<endl;                    
    return 0;
}

 

8.  http://acm.hdu.edu.cn/showproblem.php?pid=1096

 

#include<iostream>
using namespace std;
int main()
{
    int T,N,a,i,s;
    cin>>T;
    while(T--)
    {
        cin>>N;
        s=0;
        for(i=0; i<N; i++)
        {
            cin>>a;
            s+=a;
        }
        cout<<s<<endl;
        if(T)
            cout<<endl;
    }                    
    return 0;
}

 

 

 

总结:虽然这八道题都很简单,但做起来却不太顺手,看来刚接触ACM的时候练练这种题目还是很有必要的,哈哈哈!

 

posted @ 2015-12-06 10:23  Nagihiko  阅读(403)  评论(0编辑  收藏  举报