当前位置:首页 » 多媒体相关

(高手请帮忙!!)求教算法!!


有一个int型的数组是1,2,3,4,5,6,7,8,9,10。  
  要遍立这个数组取的数组第三个数(例如,3,6,9)然后把数组中的值向前移,然后再遍立这个只有七个数的数组,再取这个数组的第三个数,依此类推,直到取得最后一个数为止。然后,放在另一个int型的数组中显示。(万分感激!!)  
 

推荐阅读

  • 新发现3gp版本的bug [详细内容]
  • 多款时尚卡片机狂降 本周行情汇总 [详细内容]
  • 进入沃达丰“短名单” 华为欧洲重大突破 [详细内容]
  • N1600的绝对密码bug [详细内容]
  • 两天跌三百 百万像素硬盘DV跌破6K [详细内容]
  • 600万像素不足1500 尼康便携L2促销 [详细内容]
  • 国内手机市场进入“后英雄时代”? [详细内容]
  • 网友回答:
    网友:saucer

    when   这个数组   has   less   than   3   elements,   how   could   再取这个数组的第三个数???

    网友:panyee

    数组怎么操作忘了,   好像是c的东东  
       
      简单点,   用arraylist实现,   你看要不要吧  
       
      int[]   ints   =   new   int[]{1,2,3,4,5,6,7,8,9,10};  
      arraylist   list1   =   new   arraylist();  
      for(int   i   =   0;   i   <   ints.length;   i   ++)  
      {  
      list1.add(ints[i]);  
      }  
      arraylist   list   =   new   arraylist();  
      int   intresult   =   chageit(ref   list1,   ref   list);  
      while(intresult   ==   1)  
      {  
      intresult   =   chageit(ref   list1,   ref   list);  
      }  
      messagebox.show(list.count.tostring());  
       
       
       
       
      private   int   chageit(ref   arraylist   list1,   ref   arraylist   list)  
      {  
      //指示此次有几个数要被删除  
      int   j   =   0;  
      //存储要被删除的数的索引  
      int[]   isub   =   new   int[3]{-1,-1,-1};  
      if(list1.count   >=   3)  
      {  
      for(int   i   =   2;   i   <   list1.count;   i   +=3)  
      {  
       
      list.add(list1[i]); //是3,6,9的,被加到第二个数组中  
      isub[j]   =   (int)list1[i]; //记录要删除的索引号  
      j   ++;  
      if(j   ==   3)  
      break;  
      }  
      for(int   i   =   2;   i   >=   0;   i   --)       //删除list1中指定的数  
      {  
      if(isub[i]   !=   -1)  
      list1.remove(isub[i]);  
      }  
      }  
      else  
      return   -1;  
       
      return   1;  
      }  
       
       
     

    .

    讨论区

    Login