2048等待寫java版本

來源:互聯網
上載者:User

標籤:小代碼 2048 c語言版本

 <html><HEAD></HEAD><BODY> <a href="0.html">-0-</a> <a href="1.html">-1-</a> <a href="2.html">-2-</a> <a href="3.html">-3-</a> <a href="4.html">-4-</a> <a href="5.html">-5-</a> <a href="6.html">-6-</a> <a href="7.html">-7-</a> <a href="8.html">-8-</a> <a href="9.html">-9-</a><textarea rows="50" cols="50">  /***************2048 目前帶向上h和向左的bug隨機數程式運行時判斷相同數刷屏程式運行環境 vs2012或linux**************/#include<time.h>#include <stdio.h>#include <stdlib.h>#include <iostream>using namespace std;int a[5][5]={0};void show(){for(int i=0;i<5;i++){for(int j=0;j<5;j++)cout<<a[i][j]<<" ";cout<<endl;}}void fun(int state){int i=0,j=0,k;for(  i=0;i<5;i++){  for(  j=0;j<4;j++)    {  if (a[i][j]==a[i][j+1])      {         a[i][j]=2*a[i][j];         a[i][j+1]=0;      }           } }if(state==1) {for(i=0;i<5;i++){  for(  j=4;j>0;j--)    {  if (a[i][j]!=0)continue;  else {k=j-1;           while(a[i][k]==0){ k--;           }           if(k>=0){ a[i][j]=a[i][k];a[i][k]=0;}      }           }   }}}void fundown(int state){int i=0,j=0,k;for(  j=0;j<5;j++){  for(  i=0;i<4;i++)    {    if (a[i][j]==a[i+1][j])      {         a[i][j]=2*a[i][j];         a[i+1][j]=0;      }           } }if(state==1) {  for(j=0;j<5;j++)    {       for(i=4;i>0;i--)        {         if (a[i][j]!=0)continue;          else {k=i-1;           while(a[k][j]==0){ k--; }           if(k>=0){ a[i][j]=a[k][j];a[k][j]=0;}          }       }                 }   }}int check(){int s=0,i,j;  for(i=0;i<5;i++)    {     for(j=0;j<5;j++)       {        if(a[i][j]==2048){cout<<"good"<<endl;}        if(a[i][j]==4096){cout<<"good"<<endl;}        if(a[i][j]==0){s=1;}       }    }if(!s){cout<<" no empty";exit(0);}return s;}void randnum(){srand(time(0));int r=rand()%5;if(a[0][r]==0)a[0][r]=2;else if (a[4][r]!=0) a[4][r]=2;  else { for(int i=0;i<5;i++)   for(int j=0;j<5;j++)     a[i][j]=2;}}void play(){char ss=‘c‘;cout<<" enter sxzc"<<endl;cin>>ss;switch(ss){case ‘s‘:fundown(2);break;case ‘x‘:fundown(1);break;case ‘z‘:fun(2);break;case ‘c‘:fun(1);break;}}int main(){ int st=1;  while(st)   {   randnum();   show();   play();    st=check();      system("clear"); } return 0;}int main1(){ show();int state=1;fundown(state);show();return 0;}</textarea><textarea rows="50" cols="50">bug 在於上與左 方向的產生移動資料實現第一步即 20200 向右移動會是 02020的結果??所以還更應該最佳化這個代碼 </textarea><textarea rows="50" cols="50"> gcc -o main main.c fun.h fun.cls -lhd+G(shift+g)10dd10yy:/int a</textarea><textarea rows="50" cols="50"> http://blog.csdn.net/fred1653/article/details/9322583/http://www.2cto.com/os/201508/431266.htmlhttp://wenku.baidu.com/view/4fbb197527284b73f242509f.html檔案結束標誌 eof 還有ueof是完全不同的</textarea><textarea rows="50" cols="50"> /**基數排序位移量版本桶容量版本**/ #include <stdio.h>#include <stdlib.h>#include <iostream>using namespace std;int  a[]={1,3,5,7,9,2,4,6,8,11,13,15,17,22,24,26,28};int len=sizeof(a)/sizeof(a[0]);void show(){int i=0;while(i<len)cout<<a[i]<<" ";cout<<endl;}void sort(int a[]){int b[3][10]={0};//MAXint  max=10;int i=0,j=1;for(i=0;i<len;i++){ while(a[i]>max)  {  max=max*10;  j++; }}// 按位模除處理  max=10;for(i=0;i<j;i++){int n=len-1;int kk=0; while(n--){int xx=a[n]%max;//放入while(b[kk][xx]!=0 ){kk++;}b[kk][xx]=a[n];kk=0;}//轉回原來的位置//迴圈結束自然數組a就排好了max=max*10;}}</textarea><textarea rows="50" cols="50"> </textarea><textarea rows="50" cols="50"> </textarea><textarea rows="50" cols="50"> </textarea><textarea rows="50" cols="50"> </textarea><textarea rows="50" cols="50"> </textarea></BODY></html>


2048等待寫java版本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.