156-练习9和10 循环练习和字符串与字符的处理
9,财务处的小云老师最近就在考虑一个问题:如果每个老师的工资额都知道,最少需要准备多少张人民币,才能在给每位老师发工资的时候都不用老师找零呢?
这里假设老师的工资都是正整数,单位元,人民币一共有100元、50元、10元、5元、2元和1元六种。
int num = Convert.ToInt32(Console.ReadLine());
int count100 = num / 100;
int remain = num % 100;
int count50 = remain / 50;
remain = remain % 50;
int count10 = remain / 10;
remain = remain % 10;
int count5 = remain / 5;
remain = remain % 5;
int count2 = remain / 2;
remain = remain % 2;
Console.WriteLine("100的准备" + count100);
Console.WriteLine("50的准备" + count50);
Console.WriteLine("10的准备" + count10);
Console.WriteLine("5的准备" + count5);
Console.WriteLine("2的准备" + count2);
Console.WriteLine("1的准备" + remain);
10,输入一个字符串,判断其是否是C#的合法标识符。
string str = Console.ReadLine();
bool isRight = true;
if ((str[0] >= 'a' && str[0] <= 'z') || (str[0] >= 'A' && str[0] <= 'Z') || str[0] == '_' || str[0] == '@')
{
}
else
{
isRight = false;
}
for (int i = 1; i < str.Length; i++)
{
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '_' || (str[i] >= '0' && str[i] <= '9'))
{
}
else
{
isRight = false;
}
}
if (isRight == false)
{
Console.WriteLine("不是合法标识符");
}
else
{
Console.WriteLine("是合法标识符");
}
Console.ReadKey();
浙公网安备 33010602011771号