一个CUIntArray, 随机填充nSize个1-9的数字,想要知道有多少个数字是不重复的?
比如:
1 3 4 9 3 2 2 3 5 6 7 1 413个数字,8种不重复的

解决方案 »

  1.   

    CUIntArray a;
    CMap<UINT,UINT,UINT,UINT> b;
    UINT uNumber=0,uCount;
    for(int i=0;i<a.GetSzie();i++)
    {
        if(!b.Lookup(a[i],uCount))
        {
            b[a[i]]=1;
        }
        else b[a[i]]=uCount+1;
    }
    POSITION pos = b.GetStartPosition();
    while (pos != NULL)
    {
       b.GetNextAssoc( pos, uNumber, uCount);
       if (uCount == 1)
           uNumber++;
    }
      

  2.   

    这种方法要实现我需要的填充还是不行nnd
    麻烦啊
      

  3.   

    假设你已填充好。(随便ran出来就行)int n = 0;//最后就是n种不重复的数字
    for(i=0;i<9;i++)
    {
       for(j=0;j<13;j++)
       {
           if(a[j] == i)
              n++;
       }
    }
      

  4.   

    To:thisisll(速度八十迈) ( ) 信誉:107 经大哥一说,我倒晕了,他是意思是出现了几种不同的数字?
    我的理解是最少0,最多9,所以我做了上面的做法,不知行否?
      

  5.   

    for(i=0;i<9;i++)
    {
       for(j=0;j<13;j++)
       {
           if(a[j] == i)
              n++;
              break;//刚刚落了一句^_^
       }
    }
      

  6.   

    一个CUIntArray, 随机填充nSize个1-9的数字,想要知道有多少个数字是不重复的?
    比如:
    1 3 4 9 3 2 2 3 5 6 7 1 413个数字,8种不重复的
    =========================================
    请恕小弟眼拙,我怎么看都看不出8种不重复的在哪里?1、2、3、4是重复的,其他就9、5、6、7没有重复,那么这个8怎么出来的呢?楼主,你问题没有描述清楚,俺们怎么回答啊?
      

  7.   

    楼主的意思是不是说,一个数组里面,总共出现了多少种数字呢???像楼主的这个例子,就是出现了12345679这八种数字这样的话,可以定义一个长度为9的数组
    int a[9],每个元素初始化为0a[0]存储1出现的次数,a[1]存储2出现的次数只要遍历你的CUIntArray,找到一个数,就在a数组里面给相对的元素加1
    最后看a[9] 这个数组里面有多少个不为0的元素,不就可以了
      

  8.   

    int n = 0;
    for(int i=1;i<=9;i++)
    {
    for(int j=0;j<13;j++)
    {
    if(a[j] == i)
    {
    n++;
    break;
    }//刚刚落了一句^_^
    }
    }这样才对,晕晕
      

  9.   

    int a[9];
    int noRepeatNum = 0;for(int j = 0; j < nSize; j++ )
    {
       for(int i=0; i <9; i++ )
       {
          if(CUIntArray[j]=i+1)
          { 
            CUIntArray[j]++;
          }
          if(CUIntArray[j] == 0)
          {
            noRepeatNum++;
          }
      }
    }return 9- noRepeatNum;毛毛的想法,看要得不
      

  10.   

    自己狂晕ing
    再发下(答案为8时)
    #include <stdio.h>
    void main()
    {
    int CUIArray[13] = {1 ,3, 4, 9, 3, 2, 2, 3, 5, 6, 7, 1, 4};
    int a[9] ={0};
    int noRepeatNum = 0;
    int i,j,k;
    for( i = 0 ; i< 13; i++)
    {
    for( j = 0; j < 9; j++ )
    {
    if(CUIArray[i] == j+1)
    {
    a[j]++;
    }

    }
    }
    for(k=0;k < 9; k++)
    {
    if(a[k] == 0)  noRepeatNum++;

    }
    printf("No repeated number is %d",9-noRepeatNum);
    }
      

  11.   

    (答案为4时)
    #include <stdio.h>
    void main()
    {
    int CUIArray[13] = {1 ,3, 4, 9, 3, 2, 2, 3, 5, 6, 7, 1, 4};
    int a[9] ={0};
    int noRepeatNum = 0;
    int i,j,k;
    for( i = 0 ; i< 13; i++)
    {
    for( j = 0; j < 9; j++ )
    {
    if(CUIArray[i] == j+1)
    {
    a[j]++;
    }
    }
    }
    for(k=0;k < 9; k++)
    {
    if(a[k] == 1)  noRepeatNum++;

    }
    printf("No repeated number is %d",noRepeatNum);
    }呵呵,出丑了