Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

5/28/10

c sudoku program exe

c sudoku program exe


#include
#include
#include
using namespace std;

const int M = 9 + 10;
int a[M][M], t[M];

void err (char c, int n) {
    string s = "soooooooooooooooti";
    if (c == 'c')
        s = "soton ";
    if (c == 'r')
        s = "satr ";
    if (c == 's')
        s = "morabaa ";
    cout << s << n << " eshkal dare\n";
    exit (0);
}

int main () {
    for (int i=1; i<10; i++)
        for (int j=1; j<10; j++)
            cin >> a[i][j];
    //satr
    for (int i=1; i<10; i++) {
        memset (t, 0, sizeof(t));
        for (int j=1; j<10; j++){
            if (t[ a[i][j] ] == 1)
                err ('r', i);
            t[ a[i][j] ] = 1;
        }
    }
  
    //soton
    for (int j=1; j<10; j++) {
        memset (t, 0, sizeof (t));
        for (int i=1; i<10; i++) {
            if (t[ a[i][j] ] == 1)
                err ('c', j);
            t[ a[i][j] ] = 1;
        }
    }
    char c;
    cout << "mikhay morabaha ro ham bebinam? (y/n)\n";
    cin >> c;
    if (c == 'y') {
        for (int x=1; x<10; x += 3)
            for (int y=1; y<10; y +=3) {
                memset (t, 0, sizeof (t));
                for (int i=x; i < x+3; i++)
                    for (int j=y; j < y+3; j++) {
                        if (t[ a[i][j] ] == 1)
                            err('s', x*10 + y);
                        t[ a[i][j] ] = 1;
                    }
            }  
    }
    return 0;
}




Algorithm

#include
#include
#include
using namespace std;

const int M = 9 + 10;
int a[M][M], t[M];

void err (char c, int n) {
    string s = "soooooooooooooooti";
    if (c == 'c')
        s = "soton ";
    if (c == 'r')
        s = "satr ";
    if (c == 's')
        s = "morabaa ";
    cout << s << n << " eshkal dare\n";
    exit (0);
}

int main () {
    for (int i=1; i<10; i++)
        for (int j=1; j<10; j++)
            cin >> a[i][j];
    //satr
    for (int i=1; i<10; i++) {
        memset (t, 0, sizeof(t));
        for (int j=1; j<10; j++){
            if (t[ a[i][j] ] == 1)
                err ('r', i);
            t[ a[i][j] ] = 1;
        }
    }
   
    //soton
    for (int j=1; j<10; j++) {
        memset (t, 0, sizeof (t));
        for (int i=1; i<10; i++) {
            if (t[ a[i][j] ] == 1)
                err ('c', j);
            t[ a[i][j] ] = 1;
        }
    }
    char c;
    cout << "mikhay morabaha ro ham bebinam? (y/n)\n";
    cin >> c;
    if (c == 'y') {
        for (int x=1; x<10; x += 3)
            for (int y=1; y<10; y +=3) {
                memset (t, 0, sizeof (t));
                for (int i=x; i < x+3; i++)
                    for (int j=y; j < y+3; j++) {
                        if (t[ a[i][j] ] == 1)
                            err('s', x*10 + y);
                        t[ a[i][j] ] = 1;
                    }
            }   
    }
    return 0;



}


#include
#include
#include
using namespace std;

const int M = 9 + 10;
int a[M][M], t[M];

void err (char c, int n) {
    string s = "soooooooooooooooti";
    if (c == 'c')
        s = "soton ";
    if (c == 'r')
        s = "satr ";
    if (c == 's')
        s = "morabaa ";
    cout << s << n << " eshkal dare\n";
    exit (0);
}

int main () {
    for (int i=1; i<10; i++)
        for (int j=1; j<10; j++)
            cin >> a[i][j];
    //satr
    for (int i=1; i<10; i++) {
        memset (t, 0, sizeof(t));
        for (int j=1; j<10; j++){
            if (t[ a[i][j] ] == 1)
                err ('r', i);
            t[ a[i][j] ] = 1;
        }
    }
  
    //soton
    for (int j=1; j<10; j++) {
        memset (t, 0, sizeof (t));
        for (int i=1; i<10; i++) {
            if (t[ a[i][j] ] == 1)
                err ('c', j);
            t[ a[i][j] ] = 1;
        }
    }
    char c;
    cout << "mikhay morabaha ro ham bebinam? (y/n)\n";
    cin >> c;
    if (c == 'y') {
        for (int x=1; x<10; x += 3)
            for (int y=1; y<10; y +=3) {
                memset (t, 0, sizeof (t));
                for (int i=x; i < x+3; i++)
                    for (int j=y; j < y+3; j++) {
                        if (t[ a[i][j] ] == 1)
                            err('s', x*10 + y);
                        t[ a[i][j] ] = 1;
                    }
            }  
    }
    return 0;
}



To  download   the exe file code

Click  Downloads

IF you have comments or ideas leave them below

7/14/09

c samples program

In this c sample program compile the following codes and see the output

/*
PROG: butter
LANG: C++
*/

download c_heap_sort
//In the name of God
#include
#include
#include
using namespace std;

const int P = 800 + 10, N = 500 + 10, inf = P * N * 225;
int h[P], nh = 0, ver[P], ind[P], t[30], hh;
vector v[P];

inline void my_swap (int x, int y) {
swap (ver[x], ver[y]);
swap (ind[ ver[x] ], ind[ ver[y] ]);
swap (h[x], h[y]);
}

//x == index
void bobble_up (int x) {
if (x != 1 && h[x] < x ="="" mc =" x;"> h[x*2] && x*2<=nh) mc = x*2; if (h[mc] > h[x*2 + 1] && x*2+1 <= nh) mc = x*2+1; if (mc != x) { my_swap (x, mc); bobble_down (mc); } } //x != index && x == value inline void insert_key (int x) { h[++nh] = x; bobble_up (nh); } inline int extract_min () { int r = h[1]; my_swap(1, nh--); bobble_down(1); return r; } //x == index inline void modifi_key (int x, int val) { h[x] = val; bobble_up (x); bobble_down (x); } int main () { int x; while (cin >> x) {
insert_key (x);
t[hh++] = x;
cerr << x << endl;
}
cerr << "hello\n";
sort (t, t+hh);
/*for (int i=1; i
cerr << h[i] << " ";
cerr << endl;*/
for (int i=0; i
cerr << t[i] << " ";
cerr << endl;
while(nh)
cerr << extract_min () << " ";
cerr << endl;
return 0;
}

copy the code above
The end of the c sample program
for more samples see other posts in the blog
please leave messages and comment below