zoukankan      html  css  js  c++  java
  • HDU水题(2)

    HDU1000

    这一题吧最简单了。但是很多次都没通过的原因是应该定义变量为long long  避免溢出。代码略

    HDU 1001

    这一题,我也莫名其妙地写了很多次每次都没算准

    主要是在for 循环的时候要注意i<=n;另外是题目要求followed by a blank line.

    所以输出的时候要再次换行。代码略;

    HDU 1002

    注意输出数据的形式就可以了!

    #include <string>
    #include <iostream>
    using namespace std;
    int main(){
        char str1[1001], str2[1001];
        int t, i, len_str1, len_str2, len_max, num = 1, k;
        cin>>t;
     getchar();
        while(t--){
            int a[1001] = {0}, b[1001] = {0}, c[1001] = {0};
            cin>>str1;
            len_str1 = strlen(str1);
            for(i = 0; i <= len_str1 - 1; ++i)
                a[i] = str1[len_str1 - 1 - i] - '0';
          cin>>str2;
            len_str2 =  strlen(str2);
            for(i = 0; i <= len_str2 - 1; ++i)
                b[i] = str2[len_str2 - 1 - i] - '0';
            if(len_str1 > len_str2)
                len_max = len_str1;
            else
                len_max = len_str2;
            k = 0;
            for(i = 0; i <= len_max - 1; ++i){
                c[i] = (a[i] + b[i] + k) % 10;
                k = (a[i] + b[i] + k) / 10;
            }
            if(k != 0)
            c[len_max] = 1;
            cout<<"Case "<<num<<":"<<endl;
            num++;
            cout<<str1<<" + "<<str2<<" = ";
            if(c[len_max] == 1)
              cout<<"1";
            for(i = len_max - 1; i >= 0; --i){
            cout<<c[i];
            }
           cout<<endl;
            if(t >= 1)
            cout<<endl;
        }
        return 0;

    }

  • 相关阅读:
    .net开发COM组件之组件签名&注册
    msmq访问格式
    IIS宿主WCF服务*.svc Mime类型映射
    匿名方法的机种书写形式
    GMTUTC YYYY-MM-DDTHH:mm:ss.sssZ、YYYY-MM-DDTHH:mm:ss.sss+8:00意义及与北京时间转换
    允许浏览器下载exe.config文件
    WCF部署失败
    原码、补码、反码
    Java 符号引用 与 直接引用
    计算机理论基础知识
  • 原文地址:https://www.cnblogs.com/beibeibao/p/2983255.html
Copyright © 2011-2022 走看看