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;

    }

  • 相关阅读:
    apache 多站点设置
    关键词使用什么分隔符好
    ASP.NET MVC ModelState与数据验证【转】
    Sealed,new,virtual,abstract与override的区别
    ASP.NET MVC4中调用WEB API的四个方法
    wcf 基础连接已经关闭: 连接被意外关闭
    解决MySQL不允许从远程访问的方法有哪些?
    PHP魔法函数 自动转义 magic_quotes_gpc和magic_quotes_runtim
    Html.RenderPartial与Html.RenderAction 用法
    MVC中的扩展点 ActionResult
  • 原文地址:https://www.cnblogs.com/beibeibao/p/2983255.html
Copyright © 2011-2022 走看看