在豆瓣上看到一篇关于拿破仑的翻译,文科生的翻译有几段相当传神,不得不佩服汉语的强大。有好事者还用程序语言实现了一下,现已有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();
}
}
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();
}
}
最后,弱弱问一下,我怎么觉得程序实现的都和翻译无关呢? 比文科的翻译逊色不是一点点。
本文转自JeffWong博客园博客,原文链接:http://www.cnblogs.com/jeffwongishandsome/archive/2010/10/11/1848228.html,如需转载请自行联系原作者