Mô Phỏng thuật toán sắp xếp đổi chổ trực tiếp

:conan:
Mô tả: Nhập n, khởi tạo mảng gồm n số nguyên có giá trị từ 1 tới 9

in ra dãy chưa sắp xếp

thực hiện thuật toán sắp xếp và mô tả cách đổi giá trị

Code
[AH]
Mã:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
void gotoxy(int x, int y);
void sapxep(int a[], int n);
void taomang(int a[] , int n);
void xuatmang(int a[], int n);
void hoanvi(int &a , int &b , int c , int d);
int main()
{
    int n, m;
    scanf("%d",&n);
    int a[n];
    taomang(a,n);
    xuatmang(a,n); 
    gotoxy(0,8);
    xuatmang(a,n);
    sapxep(a,n);
    printf("\n\n\t\t\t    ");
    printf("Tac Gia:");
    char *_="%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c";
    int __=3**_+5;
    printf("\n\n\t\t\t");
    printf(_,__+59,__-32,__-19,__-4,__-21,__-40,__+17,__-7,__-21,__-44,__-19,__-17,__-9,__-15,__-2,__+58);
    printf("\n\n");
    getch();
}
void taomang(int a[] , int n)
{
    
    srand((int)time(NULL));
    for(int i = 0 ; i < n ; i ++)
        a[i]=rand() % 9 + 1 ;
}
void xuatmang(int a[], int n)
{
    for(int i = 0 ; i < n ; i ++)
        printf("%d",a[i]);
}
void sapxep(int a[], int n)
{
    for (int i = 0 ; i < n-1 ; i ++)
        for ( int j = i+1 ; j < n ; j ++)
            if ( a[i] > a[j] )
                hoanvi(a[i],a[j],i,j);
    printf("\n\nDone!!!");
}
void gotoxy(int x, int y)
{
    static HANDLE  h = NULL;
    if(!h)
        h = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD c = {x,y};
    SetConsoleCursorPosition(h,c);
}
void hoanvi(int &a , int &b , int c, int d)
{
    int tmp,tmp1,tmp2,tmp3;
    for(int i = 7 ; i >= 4 ; i-- )
    {
        Sleep(50);
        gotoxy(c,i+1);
            printf(" ");
        gotoxy(c,i);
            printf("%d",a);
        tmp = i;
    }
    for(int i = 1 ; i <= d-c ; i ++)
    {
        Sleep(50);
        gotoxy(c+i-1,tmp);
            printf(" ");
        gotoxy(c+i,tmp);
            printf("%d",a);
        tmp1 = c+i;
    }
    for(int i = 1 ; i <= 4 ; i ++)
    {
        Sleep(50);
        gotoxy(tmp1,tmp+i-1);
            printf(" ");
        gotoxy(tmp1,tmp+i);
            printf("%d",a);
        gotoxy(d,8+i-1);
            printf(" ");
        gotoxy(d,8+i);
            printf("%d",b);    
        tmp2 = 8+i;    
    }    
    for(int i = 1 ; i <= d-c ; i ++)
    {
        Sleep(50);
        gotoxy(d-i+1,tmp2);
            printf(" ");
        gotoxy(d-i,tmp2);
            printf("%d",b);
        tmp3 = d-i;
    }
    for(int i = tmp2 ; i >= 8 ; i-- )
    {
        Sleep(50);
        if(i != tmp2)
        {
            gotoxy(tmp3,i+1);
                printf(" ");
        }
        gotoxy(tmp3,i);
            printf("%d",b);
    }
    int temp = a;
    a = b;
    b = temp;
}
[/AH]
Muốn bước mô tả nhanh hay chậm có thể thay đổi giá trị trong hàm Sleep, đơn vị tính phần nghìn giây
Mã:
Sleep()
 

Sửu Nguyễn

⭐️⭐️⭐️⭐️⭐️
CAnh sau này dậy anh nhé
Anh hơn tuổi em nhưng nhận em làm thấy được không nhỉ :D :luffy:
 

taplamhacker

♥ Thanh Trâm ♥
:nherang: a Sửu tải cái cfree 5.0 về copy zô chạy đi thấy điều bất ngờ đó :cll:
 
bác nào giúp e với

Help me!!!
I want code...help me please!!!


Problem B: Mysterious Treasure
The planet of Nine Dragons is famous not only for its beautiful scene but also for the legend about the
secret treasures. As an astronaut, you have found an old map guiding you to the secret cave where the
treasures are hidden. Unfortunately, the door of the cave is locked and is only opened at certain times of
the day.
A day in this planet is very long as it has 10
9
minutes. The door of the cave is opened at the n
th
minutes
(from midnight) if n! = 1 ×2 ×… nis divisible by n
3
(i.e., n! mod n
3
= 0).
Given n, your task is to write a program to determine if the door of the cave is opened at the n
th
minute.
Input
The input file consists of several data sets. The first line of the input file contains the number of data
sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.
Each data set consists of one line containing the integer n(1< n< 10
9
).
Output
For each data set write in one line “YES” if the door is opened at the given n
th
minute or “NO”
otherwise.
Sample Input Sample Output
2
6
12
NO
YES








Problem C: Prime Concatenation
Given two positive integers nand d, your task is to write a program to find the smallest positive integer
mwith at least 2ddigits, satisfying the following conditions:
• m≥ n
• mis a concatenation of two prime numbers, each number has at least ddigits.
For example, given d= 2, n= 1112, then the smallest mis 1113 which is the concatenation of two 2-digit primes 11 and 13.
Input
The input file consists of several data sets. The first line of the input file contains the number of data
sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.
Each data set consists of one line containing two space-separated positive integers nand d(1≤ n≤ 10
9
và 1 ≤ d≤ 5).
Output
For each data set write in one line the desired number m.
Sample Input Sample Output
3
1112 2 1113
10 1 22
2011 2 2311
 
Top