杭电OJ 1000-1002 2000-2005 C++

1000.

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

}

1002.

#include<iostream>  
#include<string>  
using namespace std;

int main()
{
    string a, b;
    int num, sum[1000];
    cin >> num;
    for (int l = 0; l<num; l++)
    {
        cin >> a >> b;
        int la = 0, lb = 0, jinwei = 0, c, d;
        int q = 0;  
        la = a.length()-1;
        lb = b.length()-1;
    
        while (la >= 0 && lb >= 0)
        {
            c = a[la] - '0';
            d = b[lb] - '0';
            sum[q++] = (jinwei + c + d) % 10;
            jinwei  = (jinwei + c + d) / 10;
            la--;
            lb--;
        }
        if (la>lb)  
        {
            while (la >= 0)
            {

                c = a[la] - '0';
                sum[q++] = (jinwei+c) % 10;
                jinwei= (jinwei + c) / 10;

                la--;
            }
        }
        if (lb>la)
        {
            while (lb >= 0)
            {
                d = b[lb] - '0';
                sum[q++] = (jinwei+d) % 10;
                jinwei = (jinwei + d) / 10;
                lb--;
            }
        }
        sum[q] = jinwei;
        cout << "Case " << l + 1 << ":" << endl;
        cout << a << " + " << b << " = ";
        if (sum[q] != 0)
            cout << sum[q];
        for (--q; q >= 0; q--)
        {
            cout << sum[q];
        }
        cout << endl;
        if (l < num - 1) cout << endl;

    }
    return 0;
}


2000。


#include<iostream>  
#include<string>  
using namespace std;

int main()
{
    char a, b, c;
    while (cin >> a >> b >> c)
    {
        char temp;
        if (a > b){
            temp = a;
            a = b;
            b = temp;
        }
        if (a > c){
            temp = a;
            a = c;
            c = temp;
        }
        if (b > c)
        {
            temp = b;
            b = c;
            c = temp;
        }
        cout << a << " " << b << " " << c << endl;
    }

}

2001.


#include<iostream>  
#include<string>

#include<math.h>
using namespace std;

int main()
{
    double a, b, c, d;
    double result;
    while (cin >> a >> b >> c >> d)
    {
        result = sqrt((d - b)*(d - b) + (c - a)*(c - a));
        cout.precision(2);//保留两位
        cout << fixed << result << endl;//fixed 输出浮点数
    }

}

2002

#include<iostream>  
#include<string> 

#include<math.h>
using namespace std;
#define PI 3.1415927
int main()
{
    double a;
    double result;
    while (cin >> a )
    {
        result = 4.0/3.0*PI*a*a*a;
        cout.precision(3);
        cout << fixed<<result << endl;
    }
}

2003

#include<iostream>  
#include<string> 

#include<math.h>
using namespace std;

int main()
{
    double a;
    double result;
    while (cin >> a )
    {
        result = abs(a);
        cout.precision(2);
        cout << fixed<<result << endl;
    }
}

2004


#include<iostream>  
#include<string>

#include<math.h>
using namespace std;
#define PI 3.1415927
int main()
{
    double a;
    char result;
    while (cin >> a )
    {
        if (a <= 100 && a >= 90){
            result = 'A';
            cout << result << endl;
        }
            
        else if (a <= 89 && a >= 80){
            result = 'B';
            cout << result << endl;
        }
            
            
        else if (a <= 79 && a >= 70)
        {
            result = 'C';
            cout << result << endl;
        }
            
        else if (a <= 69 && a >= 60)
        {    result = 'D';
            cout << result << endl;
        }
            
        else if (a <= 59 && a >= 0){
            result = 'E';
            cout << result << endl;
        }
        else
            cout << "Score is error!"<<endl;
        
        
    }

}


2005.

#include<cstdio>
#include<stdio.h>
int main()
{
    int year, month, day,num;
    int m[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    while (~scanf("%d/%d/%d",&year,&month,&day))
    {
        num = 0;
        for (int i = 0; i < month; i++)
        {
            num += m[i];
        }
        if (year % 400 == 0 || (year % 4 == 0 && year % 100!=0)){
            if (month <= 2)
                num += 0;
            else num +=1;
        }
        num += day;
        printf("%d\n",num);
    }
    return 0;
}

 



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值