HDU前5题

1000
Calculate A + B.



Input
Each line will contain two integers A and B. Process to end of file.



Output
For each case, output A + B in one line.



Sample Input
1 1


Sample Output
2


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

    }
return 0;
}

1001
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.



Input
The input will consist of a series of integers n, one integer per line.



Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.



Sample Input
1
100


Sample Output
1

5050


#include <iostream>

using namespace std;

int main()
{
   int n;

   while(cin>>n)
   {
       int sum=0;
       for(int i=1;i<=n;++i)
       {
           sum=sum+i;
       }
       cout<<sum<<endl;
        cout<<endl;
   }

}

1002

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.



Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.



Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.



Sample Input
2
1 2
112233445566778899 998877665544332211


Sample Output
Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

#include<iostream>  
#include<string>  
#define MAX 1000  
using namespace std;
int main(){
    int i, j, T, cont = 0;
    cin >> T;
    int A[MAX] = { false }, B[MAX] = { 0 };
    char a[MAX], b[MAX];
    while (T--){
        cin >> a >> b;
        int alen = strlen(a);
        int blen = strlen(b);

        for (i = 0; i<alen; ++i)
            A[i] = a[alen - 1 - i] - 48;
        for (i = 0; i<blen; ++i)
            B[i] = b[blen - 1 - i] - 48;
        int c = 0;    //进位   
        for (i = 0; i<MAX; ++i)
        {
            int s = A[i] + B[i] + c;
            A[i] = s % 10;   //最后的数存到 A数组中   从左向右个十百千的顺序。。。。   
            c = s / 10;//一般是1,有时候是0
        }

        //输出  
        cout << "Case " << ++cont << ":" << endl;
        for (i = 0; i<alen; ++i)
            cout << a[i];
        cout << " + ";
        for (i = 0; i<blen; i++)
            cout << b[i];
        cout << " = ";
        for (i = MAX - 1; i >= 0; --i) 
        { 
            if (A[i])//如果 遇到非零数,即第一个数,向下执行。 
                break;
        }

        for (j = i; j >= 0; j--)
        {
            cout << A[j];
        }
        cout << endl;
        if (T) cout << endl;
    }

}

1003
Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

Sample Input
2
5 6 -1 5 4 -7(第一个意思是一共5个数字,剩下5个数,怎么加才能获得最大值,可以是一个数据相加,2个数据相加,....)
7 0 6 -1 1 -6 7 -5

Sample Output
Case 1:
14 1 4(最大为14  ,第一个位置到第四个位置之间的相加最大)

Case 2:
7 1 6

#include<iostream>  
using namespace std;
#include<string.h>  
using namespace std;
int main()
{
    int t, i, j, sum, a, n, l, r, max, z;
    cin >> t;
    for (i = 0; i<t; i++)
    {
        cin >> n;
        for (z = l = 0, r = 0, sum = 0, max = -1001, j = 0; j<n; j++)
        {
            cin >> a;
            sum += a;
            if (max<sum)
            {
                l = z;
                r = j;
                max = sum;
            }

            if (sum<0)
            {
                z = j + 1;
                sum = 0;
            }
        }
        cout << "Case " << i + 1 << ":\n" << max << " " << l + 1 << " " << r + 1 << endl;
        if (i<t - 1)
            cout << endl;
    }
}

1004
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you. 



Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.



Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.



Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0


Sample Output
red
pink

#include<iostream>
#include<string>
using namespace std;
int main()
{

    int n, i, j;
    cin >> n;
    string color;

    while (n != 0)
    {
        int num[1001] = { 0 };
        string str[1001];
        for(int i =0;i<1001;i++)
        {
            str[i]=" ";
        }

        for (i = 0; i < n; i++)
        {
            cin >> color;
            for (j = 0; j < i; j++)
            {
                if (str[j] == color)
                {
                    num[j]++;
                }
            }
            if (j == i)
            {
                str[i] = color;
            }


        }
        int max = 0;
        for (int z = 0; z <= n; z++)
        {
            if (num[z]>num[max])
            {
                max = z;
            }
        }
        cout << str[max] << endl;
        max = 0;
        cin >> n;
    }
    return 0;

}


1005
A number sequence is defined as follows:

f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.

Given A, B, and n, you are to calculate the value of f(n).



Input
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.



Output
For each test case, print the value of f(n) on a single line.



Sample Input
1 1 3
1 2 10
0 0 0


Sample Output
2
5


#include<iostream>
using namespace std;
int main()
{
    int A, B, N;
    int a[50];
    while (cin >> A >> B >> N)
    {
        if (A == 0 && B == 0 && N == 0)
        {
            break;
        }
        a[1] = 1;
        a[2] = 1;
        for (int i = 3; i < 49; i++)
        {
            a[i] = (A*a[i - 1] + B*a[i - 2]) % 7;
        }
        N = N % 48;
        a[0] = a[48];
        cout << a[N] << endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值