题目链接: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\n",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\n",ans); } return 0; } /************************************************************** Problem: 1083 User: zpfbuaa Language: C++ Result: Accepted Time:0 ms Memory:1520 kb ****************************************************************/