看到一個暴強的翻譯,閑的蛋疼,寫個c#版的

來源:互聯網
上載者:User

在豆瓣上看到一篇關於拿破崙的翻譯,文科生的翻譯有幾段相當傳神,不得不佩服漢語的強大。有好事者還用程式語言實現了一下,現已有java、python和html的版本,我也來寫個渺小的C#版本,運行結果和java版是一致的,但是本文的這個稍作抽象(java版的我不覺得有多好,甚至應該說寫得真爛),更符合C#程式員的閱讀習慣。貼代碼先:
【渺小滴C#版(知道運行結果又如何)】

using System;
using System.Collections.Generic;

public abstract class Person
{
    /// <summary>
    /// name
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// Chrysanthemum Damage Per Second
    /// </summary>
    public int CDPM { get; set; }
}

public class Enemy : Person
{

    public Enemy(string name, int cdpm)
    {
        this.Name = name;
        this.CDPM = cdpm;
    }

    public void Shout()
    {
        if (this.CDPM > 0)
        {
            Console.WriteLine(string.Format("{0} says: we are invincible!!!", this.Name));
        }
        else
        {
            Console.WriteLine(string.Format("{0} says: ......", this.Name));
        }
    }

    public bool IsCanBeatNapoleon(Napoleon n)
    {
        if (n == null)
        {
            throw new ArgumentNullException("Napoleon was not initialized...");
        }
        return this.CDPM > n.CDPM;
    }
}

public class Napoleon : Person
{
    private IList<Enemy> enemies = new List<Enemy>();

    private Napoleon()
    {
        this.Name = "Napoleon";
        this.CDPM = 100000;
        enemies.Add(new Enemy("Italy", 100));
        enemies.Add(new Enemy("Egypt", 100));
        enemies.Add(new Enemy("Russia ", 100));
    }

    private void Speak()
    {
        Console.WriteLine("My enemy number: " + enemies.Count);
        IList<Enemy> trueEnemies = new List<Enemy>();
        foreach (Enemy item in enemies)
        {
            if (item.CDPM > CDPM)
            {
                trueEnemies.Add(item);
            }
        }

        Console.WriteLine("The number of enemies who can beat me: " + trueEnemies.Count);

        foreach (Enemy item in enemies)
        {
            do
            {
                item.Shout();
            }
            while (item.IsCanBeatNapoleon(this));
        }
        Console.WriteLine("I am {0},my cdpm is {1}", this.Name, this.CDPM);
        Console.WriteLine("Dispose enemy list...");
        enemies.Clear();
        Console.WriteLine("Enemy list disposed!");
    }

    static void Main(string[] args)
    {
        (new Napoleon()).Speak();
        Console.Read();
    }
}

最後,弱弱問一下,我怎麼覺得程式實現的都和翻譯無關呢? 比文科的翻譯遜色不是一點點。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.