• 题目1083:特殊乘法(求模运算符的使用)


    题目链接:http://ac.jobdu.com/problem.php?pid=1083

    详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

    觉得这道题没有给完整,题目或许应该把数据均为正数说出来。代码就凑合着看吧。

    参考代码:

    //
    //  1083 特殊乘法.cpp
    //  Jobdu
    //
    //  Created by PengFei_Zheng on 09/04/2017.
    //  Copyright © 2017 PengFei_Zheng. All rights reserved.
    //
     
    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <cmath>
     
    using namespace std;
     
    int n, m;
    int a[12],b[12];
     
    int main(){
        while(scanf("%d%d",&n,&m)!=EOF){
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            int tmp1 = n, tmp2 = m;
            int len1 = 0, len2 = 0;
            while(tmp1 != 0){
                a[len1++]=tmp1%10;
                tmp1 = tmp1/10;
            }
            while(tmp2 != 0){
                b[len2++]=tmp2%10;
                tmp2 = tmp2/10;
            }
            int ans = 0;
            for(int i = 0 ; i < len1 ; i++){
                for(int j = 0 ; j < len2; j++){
                    ans += a[i]*b[j];
                }
            }
            printf("%d
    ",ans);
        }
    }
    /**************************************************************
        Problem: 1083
        User: zpfbuaa
        Language: C++
        Result: Accepted
        Time:0 ms
        Memory:1520 kb
    ****************************************************************/

    参考代码2(感觉不对,可以试一下负数的情况,但是OJ数据好像都是正数):

    //
    //  1083 test负号.cpp
    //  Jobdu
    //
    //  Created by PengFei_Zheng on 09/04/2017.
    //  Copyright © 2017 PengFei_Zheng. All rights reserved.
    //
     
    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <cmath>
     
    //这道题目没有判断正负数!!!
    //下面这个做法是不对的!!!
    using namespace std;
     
    int main(){
        char a[11],b[11];
        while(scanf("%s%s",a,b)!=EOF){
            int ans = 0;
            for(int i = 0 ; a[i]!=0 ; i++){
                for(int j = 0 ; b[j]!=0 ; j++){
                    ans+=(a[i]-'0')*(b[j]-'0');
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    /**************************************************************
        Problem: 1083
        User: zpfbuaa
        Language: C++
        Result: Accepted
        Time:0 ms
        Memory:1520 kb
    ****************************************************************/
  • 相关阅读:
    scrapy爬虫框架实例二
    查看系统信息
    scrapy中ROBOTSTXT_OBEY = True的相关说明
    scrapy爬虫框架实例一,爬取自己博客
    一个节点rac+单节点dg网络配置(listener.ora与tnsnames.ora)
    lsnrctl启动报错,Linux Error: 29: Illegal seek
    单机11g ogg 双向DML复制
    OGG 进程清除、重建
    OGG 11g Checkpoint 详解
    ogg日常运维命令
  • 原文地址:https://www.cnblogs.com/zpfbuaa/p/6686469.html
Copyright © 2020-2023  润新知