nz2324nz2324
BAN USER- 0of 0 votes
Answersgive you n numbers.each number is 0 or 1. output all possible arragement of these n numbers.give codes in C or py
- nz2324nz2324 in United States| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
Answerssuppose a matrix A. find a element x in this matrix,x is the smallest in his line but the biggest in his column. Give codes in C
- nz2324nz2324 in United States| Report Duplicate | Flag | PURGE
C
#include <stdio.h>
#define N 3
main(x){
int i;
for (i = 0; i<N;printf("%d",x >> i &1), i++);
printf("\n");
(1 << N)-x && main(x+1);
return 0;
}
or use this function:
void foo(unsigned int n)
{
int i, j;
for (i = 0; i < 1 << n; printf("\n"), i++)
for (j = 0; j < n; printf("%d", i >> j&1), j++);
}
oh ...
- nz2324nz2324 October 25, 2012I am unable to understand this algo..
can you give some codes?
here comes the codes in Python:
import itertools
m, n = 3, 2
for i in itertools.product(*((range(n), )*m)):
print i
for each line:
find the samllest one in this line.
if it is also the biggest one in his column, return it.
return -1 if not found
i did not run a test for codes above.
it is in java. i know nothing about java.
i have one in C, but i think it is so difficult to understand it:
void foo(int *arr,int n,int i)
{
if (i==n) {
for (i = 0; i < n; i++) {
printf("%d\t",arr[i]);
}
printf("\n");
}else{
arr[i]=1;
foo(arr,n,i+1);
arr[i]=0;
foo(arr,n,i+1);
}
thank you fort the reply.
i have not try it out
but it is right.
use curses.h or ncurses.h
#include <curses.h>
int main()
{
initscr();
char c;
noecho();
while((c = getch()) != '\n') {
printw("*");
}
endwin();
return 0;
}
compile:
gcc -lcurses a.c
- nz2324nz2324 December 03, 2012