using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x ,y ,z;
x = y = z = 0;
for (x = 1; x <= 100 / 5; x++)
for (y = 1; y <= 100 / 3;y++ )
{
z = 100 - x - y;
if (z % 3 == 0 && 5 * x + 3 * y + z == 100)
goto end;
}
end: Console.WriteLine("Cock={0} Hen={1} Chick = {2}", x, y, z);
Console.Read();
}
}
}
哪里有问题,请高手指导下
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x ,y ,z;
x = y = z = 0;
for (x = 1; x <= 100 / 5; x++)
for (y = 1; y <= 100 / 3;y++ )
{
z = 100 - x - y;
if (z % 3 == 0 && 5 * x + 3 * y + z == 100)
goto end;
}
end: Console.WriteLine("Cock={0} Hen={1} Chick = {2}", x, y, z);
Console.Read();
}
}
}
哪里有问题,请高手指导下
解决方案 »
- log4Net使用SQLLite写日志问题
- 关于SocketAsyncEventArgs
- c#如何调用注入到其他进程的dll中的方法
- 通过什么样的方法可以将窗体文本框的内容显示在水晶报表中呢?在线给分
- 一个2维数组中的一些子元素有值,有些是为空的,那怎么判断这数组中哪些是空的?
- 关于office的考题的编程思路
- c# 求助:如何更新嵌入的xml或其他文件?
- 关于SqlDataAdapter.Fill()的用法一问
- 怎么按F1调用我的xx.chm帮助文件
- C#中的 using Microsoft.Data.Odbc这个的问题!!!!?????(在线等待)
- VS2005无法新建新的项目
- web.config中如何动态分配服务器IP
最好举个小例子,多谢!!
最好举个小例子,多谢!!
using System;
class SwitchTest
{
static void Main()
{
Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large");
Console.Write("Please enter your selection: ");
string s = Console.ReadLine();
int n = int.Parse(s);
int cost = 0;
switch (n)
{
case 1:
cost += 25;
break;
case 2:
cost += 25;
goto case 1;
case 3:
cost += 50;
goto case 1;
default:
Console.WriteLine("Invalid selection.");
break;
}
if (cost != 0)
{
Console.WriteLine("Please insert {0} cents.", cost);
}
Console.WriteLine("Thank you for your business.");
}
}
// 如果找到,返回 pattern 在 s 中第一次出现的位置(0起始)。
// 如果没找到,返回 -1。
static int IndexOf(byte[] s, byte[] pattern)
{
int slen = s.Length;
int plen = pattern.Length;
for (int i = 0, j; i <= slen - plen; i++)
{
for (j = 0; j < plen; j++)
{
if (s[i + j] != pattern[j]) break;
}
if (j == plen) return i;
}
return -1;
}
用 goto 语句改写如下: // 在 s 中查找 pattern 。
// 如果找到,返回 pattern 在 s 中第一次出现的位置(0起始)。
// 如果没找到,返回 -1。
static int IndexOf(byte[] s, byte[] pattern)
{
int slen = s.Length;
int plen = pattern.Length;
for (int i = 0; i <= slen - plen; i++)
{
for (int j = 0; j < plen; j++)
{
if (s[i + j] != pattern[j]) goto next;
}
return i;
next:;
}
return -1;
}节省了在外层循环中判断 if (j == plen) ,可以提高效率,程序结构也更清晰。
改为:
if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100)