• 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;

    }

  • 相关阅读:
    Oracle问题之ORA-12560TNS:协议适配器错误
    调用脚本的方式自动的创建或者是更新oracle数据库自带的Seq序列号的值
    linux在telnet情况下root登录提示login incorrect
    CentOS 7 中 Systemd详解
    CentOS7 下安装telnet服务
    linux 安装telnet命令及使用
    Linux安装telnet
    Linux系统xinetd服务启动不了
    linux服务安装与配置(二):安装xinetd服务
    Linux超级守护进程——xinetd
  • 原文地址:https://www.cnblogs.com/beibeibao/p/2983255.html
Copyright © 2020-2023  润新知