A032:字母頻率
題目 |
字母頻率 輸入英文段落,無論大小寫,求印各字母小寫頻率,未出現者略過不印。 |
Console.WriteLine("{0}({1}) -
{2}({3}) = {4}",
'a',(int)'a','A',(int)'A',(int)'a'-(int)'A');
int[] Num_c = new int[26];
foreach (char item in Console.ReadLine().ToCharArray())
{
char c = item;
if ((int)c < 97) c = Convert.ToChar(((int)c + 32));
Num_c[(int)c - 97]++;
}
for (int i = 0; i < 26;
i++)
{
if (Num_c[i] > 0) Console.WriteLine("{0}, {1}"
, Convert.ToChar(i + 97),
Num_c[i]);
}
A034:五數排序(陣列版)
題目 |
三數排序(陣列版) 輸入三個正整數 a b c d e,將 a b c d e 從小印到大。 |
int[] Input = new int[5], Num = new int[5];
for (int i = 0; i < 5;
i++)
Input[i] = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < 5;
i++)
{
int Max = -999999, n =
-99999;
for (int j = 0; j < 5;
j++)
{
if (Input[j]>Max)
{
Max = Input[j];
n = j;
}
}
Num[i] = Max;//Console.Write(Max
+ " ");
Input[n] = 0;
}
Console.WriteLine();
for (int i = 0; i < 5;
i++)
Console.Write(Num[i] + " ");
A044:百數亂排
題目 |
百數亂排 輸入一個數整數n,並隨機產生n個0到100的整數,再將這些數打亂。 |
int n = Convert.ToInt32(Console.ReadLine());
int[] Sources = new int[n];
List<int> Collect;
Random rand = new Random();
for (int i = 0; i < n;
i++)
Sources[i] = rand.Next(0,
100);
Collect = new List<int>(Sources);
for (int i = 0; i < n;
i++)
{
int x = rand.Next(0, n
- 1);
if (x != i)
{
int temp = Collect[x];
Collect[x] =
Collect[i];
Collect[i] = temp;
}
}
foreach (var item in Sources)
Console.Write(item + " ");
Console.WriteLine();
foreach (var item in Collect)
Console.Write(item + " ");
Console.WriteLine("\n");
A040:費式數列陣列
題目 |
費式數列陣列 費氏數列定義如下 f(0)=0, f(1)=1,
f(n)=f(n-1)+f(n-2);請輸入一個正整數 n (n<20),印出f(n) 到 f(0)。 |
static void Main(string[] args)
{
while (true)
{
Program p = new Program();
int Answer = p.Fees(Convert.ToInt32(Console.ReadLine()));
Console.WriteLine(Answer);
}
}
public int Fees (int n)
{
switch (n)
{
case 0:
return 1;
case 1:
return 1;
default:
return Fees(n - 1) +
Fees(n - 2);
}
}
G007:數列卷積
題目 |
數列卷積 已知 f(0)=1 且
f(n)=f(0)*f(n-1)+f(1)*f(n-2)+f(2)*f(n-3)+f(3)*f(n-4)+...+f(n-1)*f(0)。 |
static void Main(string[] args)
{
while (true)
{
int Index = Convert.ToInt32(Console.ReadLine());
Program p = new Program();
Console.WriteLine(p.Score(Index));
}
}
int Score(int n)
{
switch (n)
{
case 0:
return 1;
case 1:
return 1;
default:
int total = 0;
for (int i = 0; i < n;
i++)
total += Score(i) *
Score((n-1) - i);
return total;
}
}
A033:巴斯卡三角形
題目 |
巴斯卡三角形 輸入一正整數 n , 輸出 f(n) 。 6 |
int[,] a = new int[100, 100];
int num = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < 100;
i++)
{
for (int j = 0; j <= i;
j++)
a[i, j] = 1;
}
for (int i = 2; i <= num;
i++)
{
for (int j = 1; j <= i;
j++)
a[i, j] = a[i - 1, j -
1] + a[i - 1, j];
}
for (int i = 0; i <= num;
i++)
{
Console.Write(" ");
for (int j = 0; j <= i;
j++)
{
Console.Write(a[i, j]);
if (j != i)
Console.Write(" ");
}
Console.WriteLine(); ;
}
沒有留言:
張貼留言