今天刷推,看到了一个推里有介绍几个古早程序员的blog
分别是:
https://www.xiaohui.com/ 程序员小灰
https://www.liuhu.net/ 程序员刘虎
可以看到2000年到2010年之间的互联网的痕迹
打开了一些我以前的思绪

之前我也有个朋友也叫小灰,也是一位很优秀的程序员,在2003~2007年之前,我们之前的联系还是蛮多的

但后来由于时间的变化,沟通工具的变化,个人境遇的变化,渐渐失去的联系

还有很多QQ时代的好友,也是如此

现在偶尔登录QQ,还能看到一个一个曾经聊的火热的网友们

这就是时间的规律,但这也是一代人有一代人的记忆

计算器的Golang实现, 支持 +-*/,并会判断表达式是否合法

package code

import (
"strconv"
"unicode"
)

type Calculator struct {
origin  string
s       string
left    int
signMap map[byte]bool
}

func NewCalculator(s string) Calculator {
signMap := map[byte]bool{
    '+': true,
    '-': true,
    '*': true,
    '/': true,
    '(': true,
    ')': true,
    ' ': true,
}
return Calculator{
    origin:  s,
    s:       s,
    left:    0,
    signMap: signMap,
}
}

func (cal *Calculator) Execuate() int {
stack := NewStack()
num := 0
numFlag := false
emptyFlag := false
sign := '+'
//往前遍历字符串
for len(cal.s) > 0 {
    c := cal.s[0]
    cal.s = cal.s[1:]
    if c == ' ' {
        emptyFlag = true
        continue
    }
    //判断是不是数字,考虑到连续累加
    if unicode.IsDigit(rune(c)) {
        if numFlag {
            //数字之间不能有空格
            if emptyFlag {
                panic(cal.origin + ": express error, empty can not between in numbers")
            }
        } else {
            numFlag = true
        }
        num = num*10 + (int(c) - int('0'))
    } else {
        numFlag = false
        if _, ok := cal.signMap[c]; !ok {
            panic(cal.origin + ": express error, invaild sign:" + string(c))
        }
    }
    emptyFlag = false
    //如果是(,递归处理,直到 碰到)弹出,结果返回
    if c == '(' {
        cal.left++
        num = cal.Execuate()
    }
    //是操作符,或者到了字符串最后,进行sush操作
    if len(cal.s) == 0 || !unicode.IsDigit(rune(c)) {
        switch sign {
        case '+': //直接入stack
            stack.Push(num)
        case '-': //变成负数,再入stack
            num = 0 - num
            stack.Push(num)
        case '*': //取出statck的top元素并弹出,相乘,再入stack
            v, _ := stack.Peek()
            stack.Pop()
            stack.Push(num * v)
        case '/': //取出statck的top元素并弹出,相乘,再入stack
            v, _ := stack.Peek()
            stack.Pop()
            stack.Push(v / num)
        }

        sign = rune(c)
        num = 0
        numFlag = false
    }

    if c == ')' {
        cal.left--
        if cal.left < 0 {
            panic(cal.origin + ": express error, more )")
        }
        break
    }
}

if len(cal.s) == 0 && cal.left > 0 {
    panic(cal.origin + ":" + cal.s + ": express error, more (: " + strconv.Itoa(cal.left))
}
//statck求和,返回
return stack.Sum()
}

While John Gilbert was in hospital, he asked his doctor to tell him about his operation has been successful, but the doctor refused to do so.
The following day, the patient asked for a bedside telephone.
When he was alone, he telephoned the hospital exchange and asked for Doctor Millington.
When the doctor answered the phone, Mr. Gilbert said he was inquiring about a certain patient, a Mr. John Gilbert.
He asked if Mr. Gilbert's operation had been successful and the doctor told him that it had been.
He then asked when Mr. Gilbert would be allowed to go home and the doctor told him that he would have to stay in hospital for another two weeks.
Then Dr. Millington asked the caller if he was a relative of the patient.
"No", the patient answered, "I am Mr. John Gilbert."

My old friend, Harrison, had lived in the Mediterranean for many years before he returned to England.
He had often dreamed of retiring in England and had planned to settle down in the country.
He had no sooner returned than he bought a house and went to live there.
Almost immediately, he began to complain about the weather.
For even though, it was still summer, it rained continually and it was often bitterly cold.
After so many years of sunshine, he got a shock.
He acted as if he had never lived in England before.
In the end, it was more than he could bear.
He had hardly had time to settle down when he sold the house and left the country.
The dream had had for so many years ended there.
Harrison had thought of everything except the weather.

The Olympic Games will be held in our country in four years' time.
As a great many people will be visiting the country, the government will be building new hotels, an immense stadium, and a new "Olympic-Standard" swimming pool.
They will also be building new roads and a special railway line.
The Games will be held just outside the capital and the whole area will be called "Olympic City".
Workers will have completed the new roads by the end of this year.
By the end of next year, they will have finished work on the new stadium.
The fantastic modern buildings have been designed by Kurt Gunter.
Everybody will be watching anxiously as the buildings go up.
we are all excited and are looking forward to the Olympic Games because they had never been held before in this country.