人民币不含分角,有以下的面值1元,5元,10元,20元,50元,100元,请定义方法算出给定金额使用以上的人民币时候最少需要多少张
class program
{
 static void Main(string []args)
{
int  [] nums={1,5,10,20,50,100};
int count=0;//代表的是数量
int index=0;//代表的是数组下标
Console.WriteLine("请输入给定的人民币");
int money=Convert.ToInt32(Console.WriteLine());
while(money>0)
{
 money-=;
}
}
}
这个题目我的思路是这样的,当输入150的话 就直接用150减去数组的最后一位 就count++记录了一张 然后是50减去100不够了 就把index-- 然后50再减去50 在记录一张 最后 成0了 就不在循环 可是就是知道思路 代码 我 就是写不出来  望赐教

解决方案 »

  1.   

    当前货币A,面值B(100或50或20或10)
    开始:
    C = A mod B;
    D = A - C;
    E = A / B (就是当前面额需要的张数)
    A = A - B * E
    B 的面值修改
    goto 开始
    不能直接相除,否则会产生4舍5入的问题
      

  2.   

     static void Main(string[] args)
            {
                ArrayList list = new ArrayList();
                int x=int.Parse(Console.ReadLine());            for (int i = 1; i < x + 1; i++)
                {
                    for (int j = 1; j < x / 5; j++)
                    {
                        for (int p = 1; p < x / 10; p++)
                        {
                            for (int q = 1; q < x / 100; q++)
                            {
                                if (1 * i + j * 5 + p * 10 + q * 100 == x)
                                {
                                    list.Add(i+j+p+q);
                                }                        }
                        }
                    }
                }
                int temp=0;
                for (int i = 0; i < list.Count; i++)
                {
                    for (int j = i + 1; j < list.Count; j++)
                    {
                        if (int.Parse(list[i]+"") < int.Parse(list[j]+""))
                        {
                            temp = int.Parse(list[i] + "");
                        }
                    }
                }
                Console.WriteLine(temp);
            }
    数字过大的话,那你就慢慢等吧
      

  3.   

    int[] arr={1,5,10,20,50,100};
    int count=0;
    int index=0;
    int money=Console.ReadLine();
    while(money>0){
      for(int i=arr.length-1;i>=index;i--)
       {
         if(arr[i]<=money){
            money-=arr[i];
             index=i;
             count++;
            beark;
           }
        }
    }
      

  4.   

    int[] arr = { 1, 5, 10, 20, 50, 100 };
                int count = 0;
                int money = Convert.ToInt32(Console.ReadLine());
                while (money > 0)
                {
                    for (int index = arr.Length - 1; index < 0; index--)
                    {
                        if (arr[index] <= money)
                        {
                            money -= arr[index];                        if (money < 0)
                            {
                                break;
                            }
                            count++;
                        }                }
                }
      

  5.   

    int[] arr = { 1, 5, 10, 20, 50, 100 };
      int count = 0;
      int money = Convert.ToInt32(Console.ReadLine());
      while (money > 0)
      {
      for (int index = arr.Length - 1; index < 0; index--)
      {
      if (arr[index] <= money)
      {
      money -= arr[index];  if (money < 0)
      {
      break;
      }
      count++;
      }  }
      }
    关于对14楼的答案我觉得有点问题啊 
     for循环里面的index=5 index<0 index-- 
    永远都不成立
    还有就是就算这个方法 把for循环里面改成index>0 index--
    假设是算270的话for循环里面 要从下标为5一直往后减  而第一次减去以后就是170   170不能继续对下标为5行判断  而是马上判断4 就是50   从而感觉到都有点麻烦  明明可以用两张100  的一张50  一张20  现在要用很多张  14楼可以看看
      

  6.   

    还有问题是么?临时写了一个using System;
    using System.Collections.Generic;
    using System.Linq;namespace ConsoleApplication7
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] nums = { 1, 5, 10, 20, 50, 100 };
                int money = 11254, totalCount = 0;            for (int i = nums.Length - 1; i >= 0; i--)
                {
                    int count = money / nums[i];
                    totalCount += count;
                    money %= nums[i];                if(count > 0)
                        Console.WriteLine("{0} {1}", nums[i], count);
                }            Console.ReadKey();
            }
        }
    }