110,528
社区成员
发帖
与我相关
我的任务
分享
// 在 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, 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;
}
// 在 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;
}
// statements_goto_switch.cs
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.");
}
}