golang !=EOF

C程序:

/* AOJ0001 List of Top 3 Hills */  

#include   
#include   

int main(void)  
{  
    int a, max1, max2, max3, temp;  

    max1 = max2 = max3 = INT_MIN;  
    while(~scanf("%d", &a)) {  
        if(a > max3) {  
            max3 = a;  

            /* 排序 */  
            if(max3 > max1) {  
                temp = max3;  
                max3 = max2;  
                max2= max1;  
                max1 = temp;  
            } else if(max3 > max2) {  
                temp = max3;  
                max3 = max2;  
                max2 = temp;  
            }  
        }  
    }  

    printf("%d\n%d\n%d\n", max1, max2, max3);  

    return 0;  
}    

按 Ctrl Z终止输入

go程序:

package main

import (
    "fmt"
    "io"
)

func main() {
    var max1, max2, max3, temp, a int
    for {
        _,err:=fmt.Scan(&a)
        if a>max3{max3=a}
        if max3 > max1 {
            temp = max3
            max3 = max2
            max2 = max1
            max1 = temp
        } else if max3 > max2 {
            temp = max3
            max3 = max2
            max2 = temp
        }
        if err==io.EOF{break}
    }
    fmt.Println(max1, max2, max3)
}

按 Ctrl D终止输入

你可能感兴趣的:(golang)