请编写程序,将用户输入的字符串中的单词逆序输出
例如:
“你我 他” → “他 我你”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
class Program
{
static void Main(string[] args)
{
string a;
char[] b = null;
int num = 0;
Console.WriteLine("in put some words");
a = Console.ReadLine();
b = a.ToCharArray();
for (int i = 0; i < b.Length; i++)
{
Console.Write("{0}",b[i]);
}
Array.Reverse(b);
Console.WriteLine();
for (int i = 0; i < b.Length; i++)
{
Console.Write("{0}",b[i]);
}
Console.WriteLine();
}
}
}
给定字符串“Thequick brown box jumped over the lazy dog. An apple a day keeps the doctor away.Can a fox and a dog be friends?”
统计单词“the”在字符串中出现的次数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharp_7_2
{
class Program
{
static void Main(string[] args)
{
string a;
int num = 0;
Console.WriteLine("输入一串字符:");
a = Console.ReadLine();
a=a.ToLower();
for (int i = 0; i < a.Length-2; i++)
{
char[] c=newchar[3]{a[i],a[i+1],a[i+2]};
string b = new string(c);
if (b.Equals("the"))
{
num++;
}
}
Console.WriteLine(num);
Console.WriteLine();
}
}
}
输入任意字符串,统计其中元音字母('a'、'e'、'i'、'o'、'u')的出现次数和频率统计单词“the”在字符串中出现的次数和频率。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharp_7_3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("输入一字符串:");
string instr;
instr = Console.ReadLine();
instr.ToCharArray();
instr.ToLower();
float[] compute = new float[6] { 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < instr.Length; i++)
{
switch (instr[i])
{
case 'a':
compute[0]++;
break;
case 'e':
compute[1]++;
break;
case 'i':
compute[2]++;
break;
case 'o':
compute[3]++;
break;
case 'u':
compute[4]++;
break;
default:
break;
}
}
for (int i = 0; i < instr.Length - 2; i++)
{
char[] c = new char[3] {instr[i], instr[i + 1], instr[i + 2] };
string b = new string(c);
if (b.Equals("the"))
{
compute[5]++;
}
}
Console.WriteLine("a,e,i,o,u,the 出现的次数与频率分别为:");
for (int i = 0; i < compute.Length; i++)
{
Console.WriteLine("次数:{0,2},频率:{1:p1}", compute[i],compute[i] / instr.Length);
}
Console.WriteLine();
}
}
}