乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      xxx

       My_study_lib 2013-05-07

       [Problem] Write a C function which meets following conditions. (Development time: 4 hours)

       

      Write a C function which removes 999 cards according to the following rules, and returns the sum of numbers in cards which cannot be removed. If there are a number of ways to remove cards, you should choose the way which minimizes the return value.

       

      [Rules]

      If the sum of two cards of the same number is identical with the number in another card, you can remove these three cards.  

      In other words, if there are cards as follows;

      2

      7

      3

      2

      8

      6

      3

      4

       

       

       

       


      As 2+2=4, three cards of 2, 4, 2 can be removed.

      As 3+3=6, three cards of 3, 3, 6 also can be removed.

      Finally, two cards of 7, 8 remained. Therefore, return 15 (7+8 = 15).

      There is no fixed order to remove cards. In the example above, you can remove 2, 4, 2 first or remove 3, 3, 6 first.

       

      [Constraints]

      All cards have the numbers from 1 to 24, inclusive.

      DO NOT use any external libraries and the header file.  

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      [file 1 – ID number.cpp]

       

      // DD NOT INCLUDE ANY FILES

      int test_main(int data[999])

      {

          return 0; //the sum of numbers in remaining cards after removing 3 cards each  

      }

       

       

      [file 2 – main.cpp]

       

      #include <stdio.h>

      #include <stdlib.h>

       

      int test_main(int data[999]);

       

      void build_data(int data[999])

      {

          for (int i = 0; i < 999; i ++)

          {

             data[i] = rand() % 24 + 1;

          }

      }

       

      void main(void)

      {

          int data[999];

       

          for (int l = 0; l < 10; l++)

          {

             build_data(data);

             printf("%d\n", test_main(data));

          }

      }

       

       

       

       

       

      #include <stdio.h>
      
      #include <stdlib.h>
      #include <cmath>
       
      int cmp(int a, int b)
      {
        return a<b;
      }
      void swap(int *a, int *b)
      {
        int tmp = *a;
        *a = *b;
        *b = tmp;
      }
      
      int test_main(int data[999])
      {
        sort(data, data+999, cmp);
       /* for(int i=0; i<999; i++)
        {
          printf("%d ", data[i]);
        }*/
        for(int i=997; i>0; i--)
        {
            if((-25!=data[i-1])&&(-25!=data[i]) && data[i-1] == data[i])
            {
              for(int j=i+1; j<999; j++)
              {
                 if((-25!=data[j])&& (data[i-1]+data[i])== data[j])
                 {
                     data[i-1] = -25;
                     data[i] = -25;
                     data[j] = -25;
                     
                 }
              }
            }
          
        }
        //printf("\n");
        int sum = 0;
        for(int i=0; i<999; i++)
        {
         // printf("%d ", data[i]);
          if(data[i]!=-25)
            sum+=data[i];
        }
       // printf("\n");
        return sum;
      }
      
       
      
      void build_data(int data[999])
      
      {
      
          for (int i = 0; i < 999; i ++)
      
          {
      
             data[i] = rand() % 24 + 1; 
      
          }
      
      }
      
       
      
      int main(void)
      
      {
      
          int data[999];
      
       
      
          for (int l = 0; l < 1; l++)
      
          {
      
             build_data(data);
            // data[0]=2; data[1]=4;data[2]=7;data[3]=3;data[4]=3;data[5]=6; data[6]=2;
            // data[7]=8;data[8]=10;
             printf("%d\n", test_main(data));
      
          }
          return 0;
      
      }
      

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多