《算法笔记》3.1小节——入门模拟->简单模拟
C简单,但是代码有点冗余,优化后省掉一般代码,保持优化习惯
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) { int a1=a; int b1=b; int ans=0; while(a1/10 || a1%10) { int temp=a1%10; a1=a1/10; b1=b; while(b1/10) { int temp2=b1%10; b1=b1/10; ans=ans+temp*temp2; } ans=ans+b1*temp; } printf("%d\n",ans); } return 0; }View Code