zoukankan      html  css  js  c++  java
  • 看到一个暴强的翻译,闲的蛋疼,写个c#版的

    在豆瓣上看到一篇关于拿破仑的翻译,文科生的翻译有几段相当传神,不得不佩服汉语的强大。有好事者还用程序语言实现了一下,现已有java、python和html的版本,我也来写个渺小的C#版本,运行结果和java版是一致的,但是本文的这个稍作抽象(java版的我不觉得有多好,甚至应该说写得真烂),更符合C#程序员的阅读习惯。贴代码先:
    【渺小滴C#版(知道运行结果又如何)】

    using System;
    using System.Collections.Generic;

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

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

    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();
        }
    }

    最后,弱弱问一下,我怎么觉得程序实现的都和翻译无关呢? 比文科的翻译逊色不是一点点。

  • 相关阅读:
    HDU 5486 Difference of Clustering 图论
    HDU 5481 Desiderium 动态规划
    hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值
    HDU 5478 Can you find it 随机化 数学
    HDU 5477 A Sweet Journey 水题
    HDU 5476 Explore Track of Point 数学平几
    HDU 5475 An easy problem 线段树
    ZOJ 3829 Known Notation 贪心
    ZOJ 3827 Information Entropy 水题
    zoj 3823 Excavator Contest 构造
  • 原文地址:https://www.cnblogs.com/jeffwongishandsome/p/1848228.html
Copyright © 2011-2022 走看看