一题:两个相差一千位以内的数相减,写出这样一个方法并测试两个相差一百位以上的两个数,输出结果。 二题:1920年为润年,写出一个算法,输入年月日20080815这样的格式算出这个人,是多少岁又多少天,如:35岁零108天。 三题:输入一段以字母组成的字符串(如azazaca%),字符串在30位以内,要求以“%”号结束(%不算在内),如果字符串出现除字母和%号以外的字符,提示输入错误,请重新输入,查找出字符串中字母出现的次数,并按照出现次数的大小排列显示出来:如下所示
a 4
z 2
c 1
四题:.将100元换成5元,1元,5角共100张,请给出各种换钱方案,例如0张5元,100张1元,0张5角,或10张5元,10张1元,80张5角
a 4
z 2
c 1
四题:.将100元换成5元,1元,5角共100张,请给出各种换钱方案,例如0张5元,100张1元,0张5角,或10张5元,10张1元,80张5角
想起了《C++百题精解》,现在浮躁啊,MARK,有空再过来
1。 构造int[1000]两个,分别将输入的截断放进去,比如第一个数是1234567890,就9就放在[8]内,0放在[9]内.然后减的时候用维数模拟位数.考虑下借位等问题就好了.2,3个好像没什么难度第四个 循环就可以了吧? 比如先看100张5元能不能等于100元,不能,99张+1张1元呢?99张+1张5毛呢?
都不行98张+2张1元?....类推
String str = "";
while (true)
{
str = Console.ReadLine().ToLower();
if (str.IndexOf('%') != str.Length - 1)
{
Console.WriteLine("重新输入");
continue;
}
Boolean b = false;
for (Int32 j = 0; j < str.Length - 1; j++)
{
if (str[j] < 'a' || str[j] > 'z')
{
b = true;
break;
}
} if (b)
continue;
else
break;
} Int32[] counter = new Int32[26];
Char [] cs = new Char[26];
for (Int32 i = 0; i < 26; i++)
{
counter[i] = 0;
cs[i] = (Char)('a' + i);
} for (Int32 i = 0; i < str.Length - 1; i++)
{
counter[str[i] - 'a']++;
} for (Int32 i = 0; i < 26; i++)
{
for (Int32 j = 0; j < 26 - i -1; j++)
{
if (counter[j] > counter[j + 1])
{
Int32 tempi = counter[j];
Char tempc = cs[j];
counter[j] = counter[j + 1];
cs[j] = cs[j + 1];
counter[j + 1] = tempi;
cs[j + 1] = tempc;
}
}
} for (Int32 i = 0; i < 26; i++)
{
Console.WriteLine(cs[i] + " : " + counter[i]);
}
/// x对应的是5元,y对应的是1元
/// </summary>
protected void test() {
System.Text.StringBuilder sb=new System.Text.StringBuilder();
for (int x = 0; x <= 20; x++) {
for (int y = 0; y <= 100; y++) {
int z = 100 - x - y;
if (5 * x + y + z/2 == 100) {
sb.AppendFormat("x={0},y={1},z={2}<br>", x, y, z);
}
}
}
Response.Write(sb.ToString());
}
{
class Program
{
static void Main(string[] args)
{
string sb = "";
for (int x = 0; x <= 20; x++)
{
for (int y = 0; y <= 100; y++)
{
int z = 100 - x - y;
if (5 * x + y + z / 2 == 100)
{
sb = "x=" + x + ";" + "y=" + y + ";" + "z=" + z;
break;
}
}
}
Console.WriteLine(sb);
Console.ReadKey();
}
}
}
string info=this.textBox2.Text.Trim();
if(info.IndexOf('%')>0)
{
int [] letter=new int[25];
info=info.Substring(0,info.IndexOf('%'));
foreach(char var in info)
{
int index=(int)var-97;
letter[index]=letter[index]+1;
}
string xx=info+"\n";
for(int i=0;i<=24;i++)
{
if(letter[i]>0)
{
xx=xx+(char)(i+97)+""+letter[i].ToString()+"\n";
}
}
MessageBox.Show(xx);
}else
{
MessageBox.Show("请以%结束");
}
{
string info=this.textBox2.Text.Trim();
if(info.IndexOf('%')>0)
{
int [] letter=new int[26];
info=info.Substring(0,info.IndexOf('%'));
foreach(char var in info)
{
int index=(int)var-97;
letter[index]=letter[index]+1;
}
string xx=info+"\n";
for(int i=0;i<=25;i++)
{
if(letter[i]>0)
{
xx=xx+(char)(i+97)+""+letter[i].ToString()+"\n";
}
}
MessageBox.Show(xx);
}else
{
MessageBox.Show("请以%结束");
}
}