// 假设Person类的lies属性表示其回答. //check方法输入参数为bool类型,真表示问的是"你们都说真话",假表示问的是"你们都说假话" Person A = new Person(); Person B = new Person(); public static bool check(bool b) { bool result = (b && A.lies); }public static void Main(string args[]) { bool b = true; bool bResult = check(b); if (bResult) { Console.WriteLine("A说假话,B说真话"); } else { Console.WriteLine("B说假话,A说真话"); } }
问李四,张三说他说的真话对吗? c#表示如下: class Sentenc { string title; bool yesno; } class Man { string name; bool flag; public man(string name,bool flag) { this.name=name; this.flag=flag; } public bool checkture(sentenc s) { bool temp; if(this.flag==true&&s.flag==true||this.flag==false&&s.flag==false) { temp=true; } else { temp=false; } } public static void main(string arg[]) { Man zhangsanMan=new Man("zhangsan",true); Man liSiMan=new Man("lisi",false); Sentence s=new Sentence("zhang san shuo ziji shuo zhenhua?",true); bool flag=liSiman.checktrue(s) if(flag==false) { out.writeline("lisi shuo jiahua,zhangsan shuo zhenhua"); } else { out.writeline("lisi shuo zhenhua,zhangsan shuo jiahua"); }
} }
这跟算法有什么相干?看不出考什么的...不过考OO基础不错...有点闲写个例子...class Person { private bool _isLiar; private string _name; public string Name { get { return _name; } } public string Ask(string question) { if (question == "What's u name?") { if (_isLiar) { return "阿扁"; } else { return _name; } } else { return "I don't know."; } } public Person(string name, bool isLiar) { _name = name; _isLiar = isLiar; } } static string LieDetector(Person p) { if (p.Ask("What's u name?") == p.Name) { return p.Name + " is a honest people, god bless you."; } else { return p.Name + " is a liar, go hell!"; } }static void Main(string[] args) { Person zhang3 = new Person("张三", true); Person li4 = new Person("李四", false); Console.WriteLine(LieDetector(zhang3)); Console.WriteLine(LieDetector(li4)); }
z3 & L4 ==false;
只要问"你们都说真话,是不是?" 或 "你们都说假话,是不是?"你们都说真话,是不是:
private bool Isalltrue( )
{
return(( z3==true) && ( L4==true))
}你们都说假话,是不是:
private bool Isallfalse()
{
return(( z3==false) && ( L4==false))
}
// 假设Person类的lies属性表示其回答.
//check方法输入参数为bool类型,真表示问的是"你们都说真话",假表示问的是"你们都说假话"
Person A = new Person();
Person B = new Person();
public static bool check(bool b)
{
bool result = (b && A.lies);
}public static void Main(string args[])
{
bool b = true;
bool bResult = check(b);
if (bResult)
{
Console.WriteLine("A说假话,B说真话");
}
else
{
Console.WriteLine("B说假话,A说真话");
}
}
c#表示如下:
class Sentenc
{
string title;
bool yesno;
}
class Man
{
string name;
bool flag;
public man(string name,bool flag)
{
this.name=name;
this.flag=flag;
}
public bool checkture(sentenc s)
{
bool temp;
if(this.flag==true&&s.flag==true||this.flag==false&&s.flag==false)
{
temp=true;
}
else
{
temp=false;
}
}
public static void main(string arg[])
{
Man zhangsanMan=new Man("zhangsan",true);
Man liSiMan=new Man("lisi",false);
Sentence s=new Sentence("zhang san shuo ziji shuo zhenhua?",true);
bool flag=liSiman.checktrue(s)
if(flag==false)
{
out.writeline("lisi shuo jiahua,zhangsan shuo zhenhua");
}
else
{
out.writeline("lisi shuo zhenhua,zhangsan shuo jiahua");
}
}
}
{
private bool _isLiar;
private string _name; public string Name { get { return _name; } } public string Ask(string question)
{
if (question == "What's u name?")
{
if (_isLiar)
{
return "阿扁";
}
else
{
return _name;
}
}
else
{
return "I don't know.";
}
} public Person(string name, bool isLiar)
{
_name = name;
_isLiar = isLiar;
}
}
static string LieDetector(Person p)
{
if (p.Ask("What's u name?") == p.Name)
{
return p.Name + " is a honest people, god bless you.";
}
else
{
return p.Name + " is a liar, go hell!";
}
}static void Main(string[] args)
{
Person zhang3 = new Person("张三", true);
Person li4 = new Person("李四", false);
Console.WriteLine(LieDetector(zhang3));
Console.WriteLine(LieDetector(li4));
}