剧情提要:
[机器小伟]在[工程师阿伟]的陪同下进入练气期第五层功法的修炼,
这次要修炼的目标是[多位数乘一位数]。
那么怎样笔算呢?
小伟看到了关于数字编码的知识:
本节到此结束,欲知后事如何,请看下回分解。
[机器小伟]在[工程师阿伟]的陪同下进入练气期第五层功法的修炼,
这次要修炼的目标是[多位数乘一位数]。
正剧开始:
星历2016年01月14日 11:06:16, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]一起研究[多位数乘一位数]。
[人叫板老师]指出这些计算分为口算和笔算。
怎样进行口算呢?
<span style="font-size:18px;">7×8+6 = 62, 20×3+98 = 158, 2000×4+1980 = 9980,
4×6+6 = 30, 70×9-120 = 510, (406-385)×3 = 63,
###
# @usage 混合运算
# @author mw
# @date 2016年01月06日 星期三 09:33:22
# @param
# @return
#
###
def calc():
fin = open('input.txt');
fout= open('output.txt', 'a');
for line in fin.readlines():
if line[-1] == '\n':
line = line[:-1];
if line == '':
continue;
elif line.startswith('#'):
print(line);
fout.write(line+'\n');
else:
lines = line.split(sep=' ');
for i in range(len(lines)):
if lines[i]=='':
continue;
result = eval(lines[i]);
lines[i] = lines[i].replace('*','×');
lines[i] = lines[i].replace('//', '÷');
s = '{0} = {1}'.format(lines[i], result);
print(s, end=', ');
fout.write(s + ', ');
print('\n');
fout.write('\n');
fout.close();
fin.close();</span>
那么怎样笔算呢?
<span style="font-size:18px;">function myDraw() {
var config = new PlotConfiguration();
config.init();
config.setPreference();
//config.setSector(1,1,1,1);
//config.axis2D(0, 0, 180);
var vertExp = new VerticalExpression();
var row = 2, col=2, width = 600, height = 400;
var r = 20;
var x = 0, y=20;
quest = [[34,2],[12,4], [312,3], [211,4]];
len = quest.length;
for (var i = 0; i < row; i++) {
for (var j=0; j < col; j++) {
x = width/col*(j+0.5);
y = 20 + height/row*i;
vertExp.mul(quest[i*col+j][0], quest[i*col+j][1], x, y, r);
}
}
}
/**
* @usage 乘法竖式
* @author mw
* @date 2016年01月14日 星期四 09:00:33
* @param
* @return
*
*/
/*
multiplicand multiplier product
*/
this.mul = function(multiplicand, multiplier, x, y, r) {
plot.save()
.setFillStyle('black');
var result = multiplicand * multiplier;
var xBeg = x ? x : 300, yBeg = y ? y :100, r = r ? r : 20;
var maxBit = Math.max(multiplicand, multiplier).toFixed(0).length;
x = xBeg, y = yBeg + r;
var mulPos = x - (maxBit+2) * r;
this.rightAlign(multiplicand, x, y, r);
y += 1.5 * r;
this.rightAlign(multiplier, x, y, r);
plot.setFont('normal normal normal '+r.toFixed(0)+'px'+ ' arial')
.fillText('×', mulPos, y+0.4*r, r);
y += r;
plot.beginPath()
.moveTo(mulPos - r, y)
.lineTo(x + r, y)
.closePath()
.stroke();
y += r;
var multiplierArray = new Array();
var tmp1 = multiplier;
var tmp2 = tmp1 % 10;
while (true) {
multiplierArray.push(tmp2);
tmp1 = (tmp1 - tmp2) / 10;
if (tmp1 <= 0)
break;
tmp2 = tmp1 % 10;
}
var len = multiplierArray.length;
var product = 0;
for (var i = 0; i < len; i++) {
if (multiplierArray[i] == 0) {
if (i == 0) {
product = multiplierArray[i] * multiplicand;
this.rightAlign(product, x, y, r);
y += 1.5*r;
}
}
else {
product = multiplierArray[i] * multiplicand;
this.rightAlign(product, x, y, r);
if (i < len-1) {
y += 1.5*r;
}
}
x -= r;
}
if (len > 1) {
y += r;
plot.beginPath()
.moveTo(mulPos - r, y)
.lineTo(xBeg + r, y)
.closePath()
.stroke();
y += r;
this.rightAlign(result, xBeg, y, r);
}
plot.restore();
}</span>
这些啄木鸟的计算能力太差,只有第三只算对了,小伟撇了撇嘴。
蚱蜢能跳375厘米,好样的。
<span style="font-size:18px;">>>>
99 × 1 = 99
99 × 2 = 198
99 × 3 = 297
99 × 4 = 396
99 × 5 = 495
99 × 6 = 594
99 × 7 = 693
99 × 8 = 792
99 × 9 = 891
def tmp():
for i in range(1, 10):
print('99 × {0} = {1}'.format(i, 99*i));
return
>>>
99 × 1 = 99
这个数和0×100 + 9×10 + 9×1相等。
99 × 2 = 198
这个数和1×100 + 9×10 + 8×1相等。
99 × 3 = 297
这个数和2×100 + 9×10 + 7×1相等。
99 × 4 = 396
这个数和3×100 + 9×10 + 6×1相等。
99 × 5 = 495
这个数和4×100 + 9×10 + 5×1相等。
99 × 6 = 594
这个数和5×100 + 9×10 + 4×1相等。
99 × 7 = 693
这个数和6×100 + 9×10 + 3×1相等。
99 × 8 = 792
这个数和7×100 + 9×10 + 2×1相等。
99 × 9 = 891
这个数和8×100 + 9×10 + 1×1相等。
>>>
def tmp():
for i in range(1, 10):
print('99 × {0} = {1}'.format(i, 99*i));
print('这个数和{0}×100 + 9×10 + {1}×1相等。'.format(i-1, 10-i));
return;</span>
看来第二只啄木鸟是最聪明的, 他算对了。
<span style="font-size:18px;">>>>
0×9+1=1
1×9+2=11
12×9+3=111
123×9+4=1111
1234×9+5=11111
12345×9+6=111111
123456×9+7=1111111
1234567×9+8=11111111
12345678×9+9=111111111
123456789×9+10=1111111111
def tmp():
a = 0;
b = 0;
for i in range(10):
a = a * 10 + i;
b = a * 9 + i+1;
print('{0}×9+{1}={2}'.format(a, i+1, b));
return;</span>
小伟看到了关于数字编码的知识:
<span style="font-size:18px;">>>>
丁小琪的学号是20090403282
王奕飞的学号是20100301011
['丁小琪', '四', 3, '女', 2009, '28', '20090403282']
['王奕飞', '三', 1, '男', 2010, '01', '20100301011']
class Code():
def __init__(self):
self.array = [];
def put(self, info):
#info样式
#['丁小琪', '四', 3, '女', 2009, '28']
#['王奕飞', '三', 1, '男', 2010, '01']
self.array.append(info);
def show(self):
for i in range(len(self.array)):
print(self.array[i]);
def genCode(self, info):
s = '';
a = 0;
s += str(info[4]);
a = chineseToNumber(info[1]);
if a < 10:
s+='0';
s+=str(a);
if info[2] < 10:
s+='0';
s+=str(info[2]);
s+=info[-1];
if (info[3] == '女'):
s+='2';
else:
s+='1';
print('{0}的学号是{1}'.format(info[0], s));
info.append(s);
self.put(info);
if __name__ == '__main__':
a = Code();
a.genCode(['丁小琪', '四', 3, '女', 2009, '28']);
a.genCode(['王奕飞', '三', 1, '男', 2010, '01']);
a.show();</span>
本节到此结束,欲知后事如何,请看下回分解。