zoukankan      html  css  js  c++  java
  • 题目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
    ****************************************************************/
  • 相关阅读:
    docker-machine create ,,,
    docker run with zabbix3.0
    mysql 官网
    取模性质
    欧涛最短路【记录最短路径】
    P4568 飞行路线【分层图最短路】
    CCF201403 无线网络【限制型最短路】
    POJ2449 【第k短路/A*】
    Feeding Time 【bfs求最大连通块】
    printf特殊用法
  • 原文地址:https://www.cnblogs.com/zpfbuaa/p/6686469.html
Copyright © 2011-2022 走看看