Việt - Nhật 's class
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
Latest topics
» Oblivion - Phim Club
week8 full I_icon_minitime06/02/14, 11:10 am by sshin_conan

» các bạn/anh/chị cho hỏi đề thi giải tích 1
week8 full I_icon_minitime03/05/13, 09:47 pm by ictk56

» Đề nghị sát nhập 2 diễn đàn
week8 full I_icon_minitime18/02/12, 11:01 am by ngoanhtuan_hn

» Hội nghị sinh viên Việt Nam Nhật Bản tuyển thành viên
week8 full I_icon_minitime17/02/12, 11:43 pm by michiosatoo

» mình có câu này, mong các bạn dịch giúp!!!
week8 full I_icon_minitime16/11/11, 06:17 pm by asakurayo

» nho forum chut
week8 full I_icon_minitime15/11/11, 11:29 am by asakurayo

» CS 1.6 MAP MAKER
week8 full I_icon_minitime15/11/11, 07:55 am by asakurayo

» ubuntu-win
week8 full I_icon_minitime12/10/11, 05:46 pm by darklord226

» diễn đàn hedspi k56
week8 full I_icon_minitime11/10/11, 09:41 pm by lakazai

Similar topics

week8 full

+5
haidang001
Woodyx
xlKD
myname2
chikclik
9 posters

Go down

week8 full Empty Re: week8 full

Bài gửi by chikclik 10/04/11, 12:02 pm

Thành thật xin lỗi Chikclik, edit bài, xóa nhầm mất bài 1. Khi nào onl thì edit lại hộ Koltec nhé.
By Koltec So good

=====================

Code:
#include

int main()
{int a,b,d,dem1;
char c,tong;

while(1)
{

printf("\t\tTen tac gia : Nguyen Trung Lam\n");
printf("\t\tTen chuong trinh chuyen co so\n\n");
printf("\t 1.Nhap so\n");
printf("\t 2.chuyen sang he nhi phan\n");
printf("\t 3.chuyen sang he 16\n");
printf("\t 4.chuyen sang he 8\n");
printf("\t 5.thoat\n");

scanf("%d",&a);
switch (a) {

case 1:printf("nhap so\n");
scanf("%d",&b);d=b;continue;
case 2:/*chuyen sang he nhi phan*/
if(b>=0) { tong=1;
          while(b>=2){b=b/2;tong =tong+1;}
          int A[tong];
          for(dem1 =1;dem1<=tong;dem1++){A[dem1]=d%2;d=d/2;}
          for(dem1 =1;dem1<=tong;dem1++){printf("%d",A[tong-dem1+1]);}
          printf("\n");}
else printf("dung nhap so am chu\n");continue;
case 3:printf("%x\n",b);continue;
case 4:printf("%o\n",b);continue;
case 5:printf("thoat that a Yes(y) No(N):");c=getch();printf("%c\n",c);getch();break;


}
printf("Chuc quy vi mot buoi toi that thu vi \n\n");


if (c=='Y'||c=='y') break;

}
return 0;
}

===================

Code:
#include
#include
//nkiem tra so truoc
int nhaptruoc(int truoc,int m)
{
    while (1)
    {
        scanf("%d",&truoc);

        if (m%2==1) {if
((truoc%2==0)&&(truoc<6)&&(truoc>0)) break; else
printf("sai luat!hay~~nhap lai!");} else
        {if ((truoc%2==1)&&(truoc<6)&&(truoc>0)) break; else printf("sai luat!hay~~nhap lai!");}
    }
    return truoc;
}
//kiem tra so sau
int nhapsau(int truoc,int sau)
{

    while (1)
    {
        scanf("%d",&sau);
        if (truoc%2==1) {if
((sau%2==0)&&(sau<6)&&(sau>0)) break; else
printf("sai luat!hay~~nhap lai\n");} else
        {if ((sau%2==1)&&(sau<6)&&(sau>0)) break;else printf("sai luat!hay~~nhap lai\n");}
    }
    return sau;
}

typedef struct
{
    char ten1[40],ten2[40];
    int diem1,diem2,turn1,turn2,LUOT;
} thongtin;
//in thong tin
void inthongtin(thongtin s)
{
    printf("\t\t\t\tGAME TUNG SUC XAC\n");
    printf("\t\t\t\tTURN THU %d\n",s.LUOT);
    printf("\tPlayer1\t\t\t\t|\tPlayer2        \n");
    printf("Nick name:\t%-20.20s\t|Nick name:\t%-20.20s\n",s.ten1,s.ten2);
    printf("Diem:\t\t%-d\t\t\t|Diem:\t\t%-d\n",s.diem1,s.diem2);
    //printf("turn thu:%d\t\t\t|turn thu:%d\n",s.turn1,s.turn2);
    printf("\n\n");
}
int main()
{
    int m,n,dem=0,truoc,sau,demluot,dich;
    thongtin tt,s;
    demluot=0;
    tt.diem1=0;
    tt.diem2=0;
    srand((unsigned)time(NULL));
    printf("PLAYER1's name:");gets(tt.ten1);
    printf("PLAYER2's name:");gets(tt.ten2);
    printf("\n");
    printf("Enter numbers win:");scanf("%d",&dich);
    printf("Nguoi choi 1 di truoc!\n");
    while (1)
    {
        //test nguoi choi 1
        printf("\tPLAY1's turn:\n");
        printf("So ban chon:");
        truoc=nhaptruoc(truoc,dem);
        m=rand()%(truoc)+1;printf("So random la:%d\n",m);
        tt.diem1+=m;
        if (tt.diem1==dich) {printf("GAME OVER!PLAYER 1 WON\a\a\a\a\a\a\a"); break;} else
        {if (tt.diem1>dich) {tt.diem1-=dich;printf("Ban phai quay ve vi tri so %d",tt.diem1);}}
        //test nguoi choi 2
        printf("\tPLAYER2's turn:\n");
        printf("So ban chon:");
        dem=nhapsau(truoc,sau);
        n=rand()%(dem)+1;printf("So random la:%d\n",n);
        tt.diem2+=n;
        if (tt.diem2==dich) {printf("GAME OVER!PLAYER 2 WON\a\a\a\a\a\a\a"); break;} else
        {if (tt.diem2>dich) {tt.diem2-=dich;printf("Ban phai quay ve vi tri so %d",tt.diem2);}}
        //in ra turn
        ++demluot;
        tt.LUOT=demluot;
        s=tt;
        inthongtin(s);
        if (demluot==2*dich) {printf("Da qua luot choi!\n");printf("KET QUA HOA\\n\a\a\a\a\a\a");break;}
    }
    return 0;
}

========================

mình chỉ test trên codeblock.chưa test tren ubuntu.có ji góp ý nhé!

Edited by Koltec.
PS: edit bài thôi, đừng post nhiều thế Chikclik nhé. S_have fun! So good
chikclik
chikclik

Tổng số bài gửi : 12
Points : 20
Join date : 21/03/2011

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by myname2 10/04/11, 09:35 pm

dùng nhiều thứ chưa học quá :-S
myname2
myname2

Tổng số bài gửi : 66
Points : 90
Join date : 27/09/2010
Age : 31
Đến từ : Hà Nội

https://facebook.com/tuanhai

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by xlKD 10/04/11, 10:06 pm

Tg? se-ri CIntro nay la cua anh Sang giu~ ban quyen =))
xlKD
xlKD

Tổng số bài gửi : 53
Points : 62
Join date : 27/09/2010
Age : 31

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by Woodyx 10/04/11, 11:14 pm

Em cũng theo dõi seri của anh sáng hàng tuần.
Tuần này nghe lâu quá hen.
Siêu nhân nào mới nổi zậy?
Woodyx
Woodyx

Tổng số bài gửi : 26
Points : 35
Join date : 27/09/2010
Age : 31
Đến từ : Hà nội pro

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by chikclik 10/04/11, 11:41 pm

bạn Sáng đi công tác tại Phú Thọ rồi.chắc là đang vui vẻ trên đấy rồi.
chikclik
chikclik

Tổng số bài gửi : 12
Points : 20
Join date : 21/03/2011

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by haidang001 11/04/11, 01:32 am

Đang cày cuốc trò gì gì trên face của myname2 vs mấy đứa em, quên hết cả ae.
Thank chikclik lâp hộ threat.

Koltec bổ sung vài phần còn thiếu:

Đề bài: gồm 3 bài
Bài 1: acb (anh có bồ So good )
Code:

    Cai tieng chuong trinh tinh lai suat tiet kiem. Viet lai chuong trinh do voi menu sau:
    TAI KHOAN TIEN GUI ACB.
        1. Gui tien
        2. Lai suat
        3. Chi tiet lai suat
        4. Thoat.

Bài 2: basen
Code:

    Viet chuong trinh chuyen doi he co so voi menu sau:
        CT Chuyen doi he co so.
        Tac gia: ABC.

        1. Nhap so (he 10).
        2. So o he nhi phan.
        3. So o he thap luc phan.
        4. So o he tam.
        5. Thoat.

Bài 3: smallgame
Code:

    You are requested to write a game for 2 player. The goal is to reach to a given number (exp 100 - inputted from users) from the a starting number (inputted).
    Who play first is determined by a random number is even or not. The game is play by turn, in each turn players can choose a positive number less than 5 - and depend on number selected by the other in previous turn. If the previous is odd then the next is even and inversely.
    Who reach the destination first.


    Interface expected.

    ICT GAME CENTER - SMART STRATEGY
    start: 5 <-
    destination: 100 <-
    who play first (randomly): 2
    P2 - turn
    Choose a number: 4
    Now the value is 9
    P1 - turn
    Choose a number: 6 <invalid - greater than 5>
    Choose a number: 2<invalid - even as previous slected>
    Choose a number: 3
    Now the value is 12 . . .
    . . .
    P1 has won the game.! Congratulation.

Phần 2: Solution
Tham khảo bài Chikclik.

Phần 3: (bonus)
Đây là phiên bản tự xướng của Koltec.

Bài 2': basen v2.0
Code:

/*Base converter v2.0*/

/*Copyright (c) haidang001 (tm) (@yahoo.com)*/
/*S_have fun! :)*/

/*Viet chuong trinh chuyen doi he co so voi menu sau:
  CT Chuyen doi he co so.
  Tac gia: ABC.

  1. Nhap so (he 10).
  2. So o he nhi phan.
  3. So o he thap luc phan.
  4. So o he tam.
  5. Thoat.*/

#include <stdio.h>

char ans[100], bin[100];
int bquit = 0, t, i, inpbase = 0, outbase = 0, inp[1000], out[1000], x, success;

void init()
{
  ans[0] = 'a';
  inp[0] = 0;
} //End init

void mainmenu()
{
  printf("\n\t\tBase converter v2.0\n");
  printf("\tCopyright (c) haidang001 (tm) (@yahoo.com)\n");
  printf("\t\t  S_have fun! :)\n\n");

  printf("1: Input number\n");
  printf("2: Show result\n");
  printf("3: Setting\n");
  printf("4: Show Decimal\n");
  printf("5: Quit\n\n");
} //End mainmenu

void printinp()
{
  for (i = inp[0]; i >= 1; i--)
    printf("%d ", inp[i]);
} //End printinp()

void printout()
{
  for (i = out[0]; i >= 1; i--)
    printf("%d ", out[i]);
}//End printout()

void input() //Input number
{
  if (inpbase < 2)
    {
      printf("Base of input number is not set\n");
      return;
    };
  inp[0] = -1;
  while (inp[0] <= 0)
    {
      printf("Number of digit of input number: ");
      scanf("%d", &inp[0]);
      getchar();
    };

  while (1)
    {
      printf("Now, enter %d digit of input number as base %d number(each digit seperated by at least one space or one enter character.\n", inp[0], inpbase);
      success = 1;
      for (i = inp[0]; i >= 1; i--)
    {
      scanf("%d", &inp[i]);
      getchar();
      if ((inp[i] < 0) || (inp[i] >= inpbase))
        success = 0;
    };

      if (success == 1)
    break;
    };

  while ((inp[0] > 0) && (inp[inp[0]] == 0))
    inp[0]--;
     
  printf("\nYour input number is (base %d): ", inpbase);
  printinp();
  printf("\n");

} //End input

void getx()
{
  x = 0;
  for (i = inp[0]; i >= 1; i--)
      x = x * inpbase + inp[i];
}//End getx()

void getout()
{
  printf("x = %d\n", x);
  t = x;
  out[0] = 0;
  while (t > 0)
    {
      out[++out[0]] = t % outbase;
      t = t / outbase;
    };
     
}//End getout()

void decimal() // Quick show Decimal
{
  if (inpbase < 2)
    {
      printf("Base of input number is not set\n");
      return;
    };

  if (inp[0] <= 0)
    {
      printf("Input number is not set\n");
      return;
    };
 
  getx();
  printf("Your inputed number show as Decimal number: %d\n", x);
  return;
};



void show() //Show result
{
 
  if (inpbase < 2)
    {
      printf("Base of input number is not set\n");
      return;
    };

  if (inp[0] <= 0)
    {
      printf("Input number is not set\n");
      return;
    };

  if (outbase < 2)
    {
      printf("Base of output number is not set\n");
      return;
    };

  getx();
  getout();

  printf("%-25s: %d\n", "Base of input number", inpbase);
  printf("%-25s: ", "Input number");
  printinp();
  printf("\n%-25s: %d\n", "Base of output number", outbase);
  printf("%-25s: ", "Output number");
  printout();
  printf("\n");
 
} //End show();

void setting() //Setting
{
  ans[0] = 'a';

  while (ans[0] != '3')
    {
      printf("1: Set base of input number. Current value: %d\n", inpbase);
      printf("2: Set base of ouput number. Current value: %d\n", outbase);
      printf("3: Return to main menu\n\n");

      ans[0] = 'a';
      while ((ans[0] < '1') || (ans[0] > '3'))
    {
      printf("Enter your choose: ");
      gets(ans);
    };
      printf("\n");

      switch (ans[0])
    {
    case '1': //Base of input number
      inpbase = 0;
      while (inpbase < 2)
        {
          printf("Input base of input number: ");
          scanf("%d", &inpbase);
          getchar();
        };
      break;

    case '2': //Base of ouput number
      outbase = 0;
      while (outbase < 2)
        {
          printf("Input base of ouput number: ");
          scanf("%d", &outbase);
          getchar();
        };
      break;
    };
    };
} //End setting

int quit()
{
  ans[0] = 'a';
  while ((ans[0] != 'Y') && (ans[0] != 'N'))
    {
      printf("Are you sure want to Quit program? (Y/N)");         
      gets(ans);
      ans[0] = toupper(ans[0]);
    };
  if (ans[0] == 'Y')
    return 1;
  else
    return 0;
} //End quit



main()
{
  init();
 
  while (1)
    {
      mainmenu();
      ans[0] = 'a';
     
      while ((ans[0] < '1') || (ans[0] > '5'))
    {
      printf("Enter your choose: ");
      gets(ans);
    };
      printf("\n");

      switch (ans[0])
    {
    case '1': //Input number; Positive only
      input();
      break;

    case '2': //Show result
      show();
      break;

    case '3': //Setting
      setting();
      break;

    case '4': //Quick Decimal
      decimal();
      break;

    case '5': //Quit
      bquit = quit();
      break;
    };

      if (bquit)
    break;
     
      printf("\nPress Enter to return to main menu . . .");
      gets(ans);           
    };

  printf("\nThank for using program!\n");
  printf("S_have fun! :)\n");
  return 0;
 
};//End main()

Bài 3': smallgame v2.0

Cứ vào solo vs insane thì biết So good).
Tự compile rồi tự xướng luôn nhé.

smallgame v2.0
Code:
/*Copyright (c) haidang001 (tm) (@yahoo.com)*/
/*S_have fun! :)*/
/*You are requested to write a game for 2 player. The goal is to reach to a given number (exp 100 - inputted from users) from the a starting number (inputted).
  Who play first is determined by a random number is even or not. The game is play by turn, in each turn players can choose a positive number less than 5 - and depend on number selected by the other in previous turn. If the previous is odd then the next is even and inversely.
  Who reach the destination first.


  Interface expected.

  ICT GAME CENTER - SMART STRATEGY
  start: 5 <-
  destination: 100 <-
  who play first (randomly): 2
  P2 - turn
  Choose a number: 4
  Now the value is 9
  P1 - turn
  Choose a number: 6
  Choose a number: 2
  Choose a number: 3
  Now the value is 12 . . .
  . . .
  P1 has won the game.! Congratulation.*/

#include
#include
#include

#define targetmax 1000

int start = 5, finish = 30, mode = 2, bquit = 0, v[2][3] = {{0, 2, 4}, {1, 3, 5}}, f[targetmax + 1][2], s[targetmax + 1][2];
char ans[100], *who[3];

void init()
{
  who[1] = "Computer";
  who[2] = "Human";

  int i, j;
  for (i = start; i <= finish; i++)
    for (j = 0; j <= 1; j ++)
      f[i][j] = -1;

  for (i = 0; i <= 5; i++)
    for (j = 0; j <= 1; j++)
      {
    f[finish + i][j] = 0;
    s[finish + i][j] = 0;
      };
}//End init()

int getf(int x, int y)
{
  int i, nx, ny;
 
  if (f[x][y] > -1)
    return f[x][y];
 
  f[x][y] = 0;
  s[x][y] = 0;
  for (i = 0; i <= 2; i++)
    if (x + v[y][i] <= finish)
      {
    s[x][y]++;
    nx = x + v[y][i];
    ny = 1 - y;
    getf(nx, ny);
    if (f[nx][ny] < s[nx][ny])
      f[x][y]++;
      };

  return f[x][y];
}

void mainmenu()
{
  printf("\n\t\tSMALL GAME v2.0\n");
  printf("\tCopyright (c) haidang001 (tm) (@yahoo.com)\n");
  printf("\t\t S_have fun! :)\n\n");

  printf("1: Human Vs Human\n");
  printf("2: Human Vs Computer\n");
  printf("3: Computer Vs Human\n");
  printf("4: Setting\n");
  printf("5: Quit\n\n");
}//End mainmenu()

void hvh()
{
  int p, x, value, prev;
 
  printf("Start number: %d\n", start);
  printf("Target number: %d\n", finish);

  srand((unsigned)time(NULL));
  p = rand() % 2 + 1;

  printf("P%d plays first\n", p);
  printf("\nP%d-turn\n", p);
  while (1)
    {
      printf("Choose a number: ");
      scanf("%d", &prev);
      getchar();
     
      if ((prev < 0) || (prev > 5))
    continue;
      else
    break;
    };
 
  value = start + prev;
  printf("Now value is %d\n", value);

  while (value < finish)
    {
      p = 3 - p;
      printf("\nP%d-turn\n", p);
     
      while (1)
    {
      printf("Choose a number: ");
      scanf("%d", &x);
      getchar();
     
      if ((x < 0) || (x > 5))
        continue;
      if ((x - prev) % 2 == 0)
        continue;
      if (value + x > finish)
        continue;
      break;
    };
     
      value +=  x;
      printf("Now value is %d\n", value);
      prev = x;
    };
 
  printf("\nP%d win!! Conratulation . . .", p);
  getchar();
} //End hvh()

void setting() //Setting
{
  printf("Computer mode 's setting: \n");
  printf("\t1: Easy\n");
  printf("\t2: Normal (default)\n");
  printf("\t3: Insane\n\n");
  ans[0] = 'a';
  while ((ans[0] < '1') || (ans[0] > '3'))
    {
      printf("Enter your choose (current %d): ", mode);
      gets(ans);
    };

  switch (ans[0])
    {
    case '1':
      mode = 1;
      break;

    case '2':
      mode = 2;
      break;

    default:
      mode = 3;
      break;
    };
} //End setting

int quit()
{
  ans[0] = 'a';
  while ((ans[0] != 'Y') && (ans[0] != 'N'))
    {
      printf("Do you really want to quit game? (Y/N)");
      gets(ans);
      ans[0] = toupper(ans[0]);
    };
  if (ans[0] == 'Y')
    return 1;
  else
    return 0;
} //Quit

void easy(int p) //p = 1 => computer turns first
{
  int x, value, prev;
 
  printf("Start number: %d\n", start);
  printf("Target number: %d\n", finish);
  srand((unsigned)time(NULL));

  printf("%s turns first\n", who[p]);
  printf("\n%s-turn\n", who[p]);
 
  if (p == 1)
    {
      prev = rand() % 5 + 1;     
      printf("Choose a number: %d\n", prev);
    }
  else
    {
      while (1)
    {
      printf("Choose a number: ");
      scanf("%d", &prev);
      getchar();
     
      if ((prev < 0) || (prev > 5))
        continue;
      else
        break;
    };
    };
 
  value = start + prev;
  printf("Now value is %d\n", value);

  while (value < finish)
    {
      p = 3 - p;
      printf("\n%s-turn\n", who[p]);

      if (p == 1) //Computer
    {
      if ((finish - value <= 5) && (((finish - value - prev) % 2 + 2) % 2 == 1))
        x = finish - value;
      else
        {
          x = v[prev % 2 == 0][rand() % 3];
          if (value + x > finish)
        x = v[prev % 2 == 0][0];
        };
      printf("Choose a number: %d\n", x);
    }
      else
    while (1)
      {
        printf("Choose a number: ");
        scanf("%d", &x);
        getchar();
     
        if ((x < 0) || (x > 5))
          continue;
        if ((x - prev) % 2 == 0)
          continue;
        if (value + x > finish)
          continue;
        break;
      };
     
      value +=  x;
      printf("Now value is %d\n", value);
      prev = x;
    };
 
  printf("\n%s win!! Conratulation . . .", who[p]);
  getchar();
} //End easy()

void normal(int p) //p = 1 => computer turns first
{
  int i, nv, x, y, value, prev, t, max;
 
  printf("Start number: %d\n", start);
  printf("Target number: %d\n", finish);
  srand((unsigned)time(NULL));

  printf("%s turns first\n", who[p]);
  printf("\n%s-turn\n", who[p]);
 
  if (p == 1)//First turn
    {
      max = 0;
      for (i = 0; i <= 5; i++)
    if (start + i <= finish)
      {
        t = getf(start + i, i % 2 == 0);
        if (t >= max)
          {
        max = t;
        prev = i;
          };
      };
      printf("Choose a number: %d\n", prev);
    }
  else
    {
      while (1)
    {
      printf("Choose a number: ");
      scanf("%d", &prev);
      getchar();
     
      if ((prev < 0) || (prev > 5))
        continue;
      else
        break;
    };
    };
 
  value = start + prev;
  printf("Now value is %d\n", value);//End firstturn

  while (value < finish) //Turn repeation
    {
      p = 3 - p;
      printf("\n%s-turn\n", who[p]);

      if (p == 1) //Computer
    {
      if ((finish - value <= 5) && (((finish - value - prev) % 2 + 2) % 2== 1))
        x = finish - value;
      else
        {
          max = 0;
          y = (prev % 2 == 0);
          for (i = 0; i <= 2; i++)
        {
          nv = value + v[y][i];
          if (nv <= finish)
            {
              getf(nv, 1 - y);
              if (f[nv][1-y] >= max)
            {
              max = f[nv][1-y];
              x = v[y][i];
            };
            };
        };
        };
      printf("Choose a number: %d\n", x);
    }
      else
    while (1)
      {
        printf("Choose a number: ");
        scanf("%d", &x);
        getchar();
     
        if ((x < 0) || (x > 5))
          continue;
        if ((x - prev) % 2 == 0)
          continue;
        if (value + x > finish)
          continue;
        break;
      };
     
      value +=  x;
      printf("Now value is %d\n", value);
      prev = x;
    };
 
  printf("\n%s win!! Conratulation . . .", who[p]);
  getchar();
} //End normal()

void insane(int p) //p = 1 => computer turns first
{
  int i, nv, y, x, value, prev, nx, ny;
  float fmax;
 
  printf("Start number: %d\n", start);
  printf("Target number: %d\n", finish);
  srand((unsigned)time(NULL));

  printf("%s turns first\n", who[p]);
  printf("\n%s-turn\n", who[p]);
 
  if (p == 1)//First turn
    {
      fmax = 0;
      for (i = 0; i <= 5; i++)
    if (start + i <= finish)
      {
        nx = start + i;
        ny = (i % 2 == 0);
        getf(nx, ny);
        if ((fmax == 0) || (s[nx][ny] == 0) || (fmax < ((float)f[nx][ny] / s[nx][ny])))
          {
        fmax = (s[nx][ny] == 0) ? 0 : ((float)f[nx][ny] / s[nx][ny]);
        prev = i;
          };
      };
      printf("Choose a number: %d\n", prev);
    }
  else
    {
      while (1)
    {
      printf("Choose a number: ");
      scanf("%d", &prev);
      getchar();
     
      if ((prev < 0) || (prev > 5))
        continue;
      else
        break;
    };
    };
 
  value = start + prev;
  printf("Now value is %d\n", value);//End firstturn

  while (value < finish) //Turn repeation
    {
      p = 3 - p;
      printf("\n%s-turn\n", who[p]);

      if (p == 1) //Computer
    {
      if ((finish - value <= 5) && (((finish - value - prev) % 2 + 2) % 2== 1))
        x = finish - value;
      else
        {
          fmax = 0;
         
          y = (prev % 2 == 0);
          for (i = 0; i <= 2; i++)
        {
          nv = value + v[y][i];
          if (nv <= finish)
            {
              nx = nv;
              ny = 1 - y;
              getf(nx, ny);
              if ((fmax == 0) || (s[nx][ny] == 0) || (fmax < ((float)f[nx][ny] / s[nx][ny])))             
            {
              fmax = (s[nx][ny] == 0) ? 0 : ((float)f[nx][ny] / s[nx][ny]);
              x = v[y][i];
            };
            };
        };
        };
      printf("Choose a number: %d\n", x);

    }
      else
    while (1)
      {
        printf("Choose a number: ");
        scanf("%d", &x);
        getchar();
     
        if ((x < 0) || (x > 5))
          continue;
        if ((x - prev) % 2 == 0)
          continue;
        if (value + x > finish)
          continue;
        break;
      };
     
      value +=  x;
      printf("Now value is %d\n", value);
      prev = x;
    };
 
  printf("\n%s win!! Conratulation . . .", who[p]);
  getchar();
} //End insane()


main()
{
  init();

  while (1)
    {
      mainmenu();
 
      ans[0] = 'a';
      while ((ans[0] < '1') || (ans[0] > '5'))
    {
      printf("Select a number: ");
      gets(ans);
    };
      printf("\n");

      switch (ans[0])
    {
    case '1': //Human Vs Human
      hvh();
      break;
     
    case '2': //Human Vs Computer
      switch (mode)
        {
        case 1:
          easy(2);
          break;

        case 2:
          normal(2);
          break;

        default:
          insane(2);
          break;
        };
      break;

    case '3': //Com vs human
      switch (mode)
        {
        case 1:
          easy(1);
          break;

        case 2:
          normal(1);
          break;

        case 3:
          insane(1);
          break;
        };
      break;

    case '4': //Setting
      setting();
      break;

    case '5': //Quit
      bquit = quit();
      break;
    };

      if (bquit)
    break;
    };
 
  printf("\nThank for playing!\n");
  printf("S_have fun! :)\n");
  return 0;
}


3 thư viện sử dụng trong bài (đề phòng lỗi html)
Code:

stdio.h
time.h
stdlib.h
Vì code khá dài (khoảng hơn 500 lines lận), nên khó tránh được sai sót. Có gì ae góp ý giúp Koltec để hoàn thiện.
Thank for reading So good.
haidang001
haidang001

Tổng số bài gửi : 91
Points : 176
Join date : 25/09/2010
Age : 31

http://haidang001.tk

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by Woodyx 11/04/11, 08:31 am

HIX! Toàn cái chưa học. Đọc cũng chẳng hiểu mấy.
Tuần này die òy Sad
Woodyx
Woodyx

Tổng số bài gửi : 26
Points : 35
Join date : 27/09/2010
Age : 31
Đến từ : Hà nội pro

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by chikclik 11/04/11, 09:44 am

học hành vất vả.kết quả chẳng ra ji.chán
chikclik
chikclik

Tổng số bài gửi : 12
Points : 20
Join date : 21/03/2011

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by myname2 11/04/11, 10:09 am

Bài 3 code của Lâm với Sáng cao siêu quá :-S Tớ chỉ nông dân thôi, mọi người góp ý nhé Very Happy
Bai3.c
Code:

#include<stdio.h>
#include <stdlib.h>
#include <time.h>


int main()
{
    int dice, xuatphat, dich, diem, luot, so, sotruoc;

    printf("Tro choi voi con so v1.0\n");//introduction
    printf("Tac gia: myname2\n\n");

    printf("Nhap so bat dau: ");//input
    scanf("%d", &xuatphat);
    printf("Nhap so dich: ");
    scanf("%d", &dich);

    diem = xuatphat;
    luot = 1;
    srand ( time ( NULL ));
    dice = 1 + rand () % 2;
    printf("\nChuong trinh se chon ngau nhien nguoi choi truoc...\n");

    switch(dice)//game
    {
        case '1'://player 1 first
        {
            printf("Ban so 1 se choi truoc!\n\n");

            printf("Luot 1, moi ban so 1 nhap so: ");
            while (1)
            {
                scanf("%d", &so);
                if ((so > 0) && (so < 5)) break;
                    else printf("Nhap sai luat, moi nhap lai: ");
            }
            diem = diem + so;
            sotruoc = so;
            luot++;
            printf("Diem hien tai la: %d\n\n", diem);

            while (diem < dich)
            {
                printf("Luot %d, moi ban so %d nhap so: ", luot, (luot % 2 == 1)? 1: 2);
                while (1)
                {
                    scanf("%d", &so);
                    if ((so >= 0) && (so < 5) && ((so + sotruoc) % 2 == 1)) break;
                        else printf("Nhap sai luat, moi nhap lai: ");
                }
                    sotruoc = so;

                diem = diem + so;
                luot++;
                printf("Diem hien tai la: %d\n\n", diem);
            }
            printf("Ban so %d da thang!!!\n", (luot % 2 == 0)?1:2);
        }
        default://player 2 first
        {
            printf("Ban so 2 se choi truoc!\n\n");

            printf("Luot 1, moi ban so 2 nhap so: ");
            while (1)
            {
                scanf("%d", &so);
                if ((so > 0) && (so < 5)) break;
                    else printf("Nhap sai luat, moi nhap lai: ");
            }
            diem = diem + so;
            sotruoc = so;
            luot++;
            printf("Diem hien tai la: %d\n\n", diem);

            while (diem < dich)
            {
                printf("Luot %d, moi ban so %d nhap so: ", luot, (luot % 2 == 1)? 2: 1);
                while (1)
                {
                    scanf("%d", &so);
                    if ((so >= 0) && (so < 5) && ((so + sotruoc) % 2 == 1)) break;
                        else printf("Nhap sai luat, moi nhap lai: ");
                }
                    sotruoc = so;

                diem = diem + so;
                luot++;
                printf("Diem hien tai la: %d\n\n", diem);
            }
            printf("Ban so %d da thang!!!\n", (luot % 2 == 0)?2:1);
        }
    }

return 0;

}


Chú thích: Có thể dùng chương trình con nhưng chưa học nên dài ra thế đây :">

@Anh em: Còn bai2 đổi cơ số, tó có thắc mắc là có phải đổi cơ số cho số âm và số thập phân hay không, đầu bài hình như chí nói là số :-S Và đổi theo cách của Lâm có được ko? Túc đỏi cơ số 8 và 16 thì dùng luôn tham số cảu lệnh printf, và đổi nhị phân có nhất thiết phải dùng mảng ko :-S
myname2
myname2

Tổng số bài gửi : 66
Points : 90
Join date : 27/09/2010
Age : 31
Đến từ : Hà Nội

https://facebook.com/tuanhai

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by Woodyx 11/04/11, 10:11 am

Mấy cái bài trên dùng mảng à? :shock:

==============

Hey! Hải xồm. Bài chuyển đổi cơ số cậu có cách nào khác ngoài dùng mảng ko? bounce

============

....

Edited by koltec. S_have fun! So good
Woodyx
Woodyx

Tổng số bài gửi : 26
Points : 35
Join date : 27/09/2010
Age : 31
Đến từ : Hà nội pro

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by chikclik 11/04/11, 12:55 pm

bai2 ko phải do mình làm.ông lớp B làm thôi.theo mình thì dùng mảng là hợp lý.
chikclik
chikclik

Tổng số bài gửi : 12
Points : 20
Join date : 21/03/2011

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by myname2 11/04/11, 06:46 pm

Theo tớ trinh sát mấy hôm nay thì chả có cách nào mà ko dùng mảng cả :-<
myname2
myname2

Tổng số bài gửi : 66
Points : 90
Join date : 27/09/2010
Age : 31
Đến từ : Hà Nội

https://facebook.com/tuanhai

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by truonggiang.bka 11/04/11, 08:00 pm

a e xem ho bai t voi nhe
y tuong rat don gian
chu yeu la copy paste nen co ve tiet kiem thoi gian (^_^)
con dung va du chua thi chua biet!

======================

#include
#include
int main()
{
printf("Bai tap: Game don gian \n\n ");

int xuatphat,dich,a,b,l;
int tong=0,c;

printf("Nhap diem xuat phat: ");
scanf("%d",&xuatphat);
printf(" Nhap dich: ");
scanf("%d",&dich);
printf("chon nguoi choi truoc: \n");
tong=tong+xuatphat;

do{
srand((unsigned) time(NULL));
a=rand()%3;
}while(a==0);
printf("Nguoi %d choi truoc\n ",a);
l=fabs(a-3);

printf("**P%d - turn \n",a);
do {
printf(" Chon mot so:");
scanf("%d",&b);
}while(b<=0 || b>5);
tong=tong+b;
printf("Now value: %d\n",tong);

while(1)
{
printf("**P%d - turn\n",l);
do {
printf(" Chon mot so:");
scanf("%d",&c);
}while(c<=0 || c>5 ||(b+c)%2==0);
tong=tong+c;
printf("Now value: %d\n",tong);
if (tong==dich)
{
printf("nguoi choi %d thang\n",l);
break;
}
if ((100-tong)>0 && (100-tong)<=5)
{
printf("Nguoi choi %d thang",a);
break;;
}

printf("**P%d - turn \n",a);
do{
printf(" Chon 1 so:");
scanf("%d",&b);
}while(b<=0 || b>5 || (b+c)%2==0);
tong=tong+b;
printf("Now value: %d\n",tong);
if (tong==dich)
{
printf("nguoi choi %d thang\n",a);
break;
}
if ((100-tong)>0 && (100-tong)<=5)
{
printf("Nguoi choi %d thang",l);
break;;
}

}

return 0;
}
[code]


Edited by koltec. S_have fun! So good
truonggiang.bka
truonggiang.bka

Tổng số bài gửi : 5
Points : 6
Join date : 04/10/2010

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by haidang001 11/04/11, 09:00 pm

Woodyx đã viết:Mấy cái bài trên dùng mảng à? :shock:

==============

Hey! Hải xồm. Bài chuyển đổi cơ số cậu có cách nào khác ngoài dùng mảng ko? bounce


myname2 đã viết:Theo tớ trinh sát mấy hôm nay thì chả có cách nào mà ko dùng mảng cả :-<

Đây là cách không dùng đến mảng của bài 2. Ae tham khảo qua rồi cho ý kiến.

basenv1.1
Code:

/*Copyright (c) haidang001 (tm) (@yahoo.com)*/
/*S_have fun! :)*/

/*Viet chuong trinh chuyen doi he co so voi menu sau:
  CT Chuyen doi he co so.
  Tac gia: ABC.

  1. Nhap so (he 10).
  2. So o he nhi phan.
  3. So o he thap luc phan.
  4. So o he tam.
  5. Thoat.*/

#include <stdio.h>

main()
{

  char ans[100];
  int x, quit = 0, neg = 0, t, i, j;

  ans[0] = 'a';
  while (1)
    {
      printf("\n\t\tBase converter v1.0\n");
      printf("\tCopyright (c) haidang001 (tm) (@yahoo.com)\n");
      printf("\t\t  S_have fun! :)\n\n");

      printf("1: Input number (decimal)\n");
      printf("2: Show Binary\n");
      printf("3: Show Hexadecimal\n");
      printf("4: Show Octal\n");
      printf("5: Show Decimal\n");
      printf("6: Quit\n\n");

      ans[0] = 'a';
      while ((ans[0] < '1') || (ans[0] > '6'))
    {
      printf("Enter your choose: ");
      gets(ans);
    };
      printf("\n");

      switch (ans[0])
    {
    case '1': //Input number;
      printf("Enter number: ");
      scanf("%d", &x);
      getchar();
     
      neg = 0;
      if (x < 0)
        {
          neg = 1;
          x = -x;
        };
     
      break;

    case '2': //Binary
      if (x == 0)
        {
          printf("Number shows as Binary number: 0\n");
          break;
        };
     
      printf("Number shows as Binary number: %c", neg?'-':' ');
      t = x;

      i = 30;
      while ((1 << i) > t)
        i--;
      t -= (1 << i);
      printf("1");
      for (j = i - 1; j >= 0; j--)
        if (1 << j <= t)
          {
        t -= (1 << j);
        printf("1");
          }
        else
          printf("0");
      printf("\n");
      break;

    case '3': //Hexadecimal
      printf("Number shows as Hexadecimal number: %c%X\n", neg?'-':' ', x);
      break;

    case '4': //Octal
      printf("Number shows as Octal number: %c%o\n", neg?'-':' ', x);
      break;

    case '5': //Decimal
      printf("Orginal entered number is (Decimal): %c%d\n",neg?'-':' ', x);
      break;

    case '6': //Quit
      ans[0] = 'a';
      while ((ans[0] != 'Y') && (ans[0] != 'N'))
        {
          printf("Are you sure want to Quit program? (Y/N)");         
          gets(ans);
          ans[0] = toupper(ans[0]);
        };
      if (ans[0] == 'Y')
        quit = 1;
      else
        quit = 0;
    };

      if (quit)
    break;
      printf("\nPress Enter to return to main menu . . .");
      gets(ans);
    };

  printf("\nS_have fun! :)\n");
  return 0;
}
haidang001
haidang001

Tổng số bài gửi : 91
Points : 176
Join date : 25/09/2010
Age : 31

http://haidang001.tk

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by truonggiang.bka 11/04/11, 10:00 pm

bai chuyen co so con mot cach nua ko can dung mang
chi khoang 5 - 6 thoi
thao tac tren bit
nhung hoi kho hieu mot chut
truonggiang.bka
truonggiang.bka

Tổng số bài gửi : 5
Points : 6
Join date : 04/10/2010

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by huy_d_t 11/04/11, 11:11 pm

chuyen sang he nhi phan co 1 cach ko dung mang, nhung phai dung ct con de quy :-S
huy_d_t
huy_d_t

Tổng số bài gửi : 112
Points : 142
Join date : 26/09/2010
Đến từ : Đại dâm tặc

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by haidang001 11/04/11, 11:12 pm

truonggiang.bka đã viết:bai chuyen co so con mot cach nua ko can dung mang
chi khoang 5 - 6 thoi
thao tac tren bit
nhung hoi kho hieu mot chut
Uk, đúng là có cách ko dùng mảng, xử lý bit, có cả cách ko dùng mảng cũng k xử lý bit, cũng ko cần ct đệ quy (chỉ nhân chia thông thường So good ).

Code day:

dec2bin
Code:

/*dec2bin*/
/*Quick Decimal to Binary converter*/

/*Copyright (c) haidang001 (tm) (@yahoo.com)*/
/*S_have fun! :)*/

#include <stdio.h>

main()
{
  int x, s = 1;
 
  printf("Decimal input: ");
  scanf("%d", &x);
  printf("Binary output: ");

  if (x == 0) printf("0");

  while (s <= x)
    s = s * 2;
  s = s / 2;
 
  while (s > 0)
    {
      if (s <= x)
    {
      x -= s;
      printf("1");
    }
      else
    printf("0");
      s = s / 2;
    };
 
  printf("\n\nS_have fun! :)\n");
  return 0;
}
haidang001
haidang001

Tổng số bài gửi : 91
Points : 176
Join date : 25/09/2010
Age : 31

http://haidang001.tk

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by myname2 12/04/11, 12:03 am

<< là dịch bit phải ko?
@Huy: ct con thì ai chả biết, nhưng mà còn vượt khung hơn cả mảng, nhất là xài đệ quy
@Sáng: thuật toán cuối cùng là thuật toán gì vậy :-S
myname2
myname2

Tổng số bài gửi : 66
Points : 90
Join date : 27/09/2010
Age : 31
Đến từ : Hà Nội

https://facebook.com/tuanhai

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by Tung_tobe 12/04/11, 12:20 am

Hơhơ cái chuyển từ thập sang nhị chả hiểu j hết @@
Tung_tobe
Tung_tobe

Tổng số bài gửi : 100
Points : 124
Join date : 27/09/2010

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by chikclik 12/04/11, 12:50 am

oạch.cái bài chuyển cơ số lằng nhằng thế.
chikclik
chikclik

Tổng số bài gửi : 12
Points : 20
Join date : 21/03/2011

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by Woodyx 12/04/11, 09:09 am

Đọc đi đọc lại thấy cách dùng mảng vẫn là hay và dễ hiểu nhất!!! cheers
Woodyx
Woodyx

Tổng số bài gửi : 26
Points : 35
Join date : 27/09/2010
Age : 31
Đến từ : Hà nội pro

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by hieupro1269 12/04/11, 03:12 pm

Đây là cách của mình,sử dụng những gì đã học Very Happy
Cốt yếu trong cách này là mã "\r",trong bảng mã ASCII nó là mã lùi con trỏ về đầu dòng.(Cái này trong môn thầy Khánh So good))
Thuật toán rất đơn giản nhưng do trình bày kém nên nhìn hơi rối,anh em thông cảm,đây là code nháp nên làm ko cẩn thận Very Happy.
Code:
#include
void main()
{
  int i,t,a,so,du,nguyen=1,tmp;
  printf("enter:");
  scanf("%d",&so);
  tmp=so;
  for (;nguyen!=0;)
    {
      nguyen=tmp/2;
      du=tmp%2;
      tmp=nguyen;i++; //xac dinh so ki tu cua so nhi phan
    }
  t=i;tmp=so;
  for (;t!=0;t--)
    {
      nguyen=tmp/2;
      du=tmp%2;
      tmp=nguyen;
      a=t;
      printf("\r");  // \r trong bang ma ASCII la ma lui ve dau dong
      for(;a>0;a--) printf(" ");
      printf("%d",du);
     
    }
}
hieupro1269
hieupro1269

Tổng số bài gửi : 31
Points : 37
Join date : 04/10/2010
Age : 32

Về Đầu Trang Go down

week8 full Empty Re: week8 full

Bài gửi by Sponsored content


Sponsored content


Về Đầu Trang Go down

Về Đầu Trang

- Similar topics

 
Permissions in this forum:
Bạn không có quyền trả lời bài viết