Skip to content

Instantly share code, notes, and snippets.

View iporsut's full-sized avatar
🏠
Working from home

Weerasak Chongnguluam iporsut

🏠
Working from home
View GitHub Profile
@iporsut
iporsut / pre_to_post_binary_search_tree.c
Created June 24, 2012 11:11
Pre to Post order Binary Search Tree
#include <stdio.h>
#include <stdlib.h>
typedef struct _btree {
int n;
struct _btree *left;
struct _btree *right;
}BTree;
BTree * createNode() {
@iporsut
iporsut / read_standard_input.c
Created June 24, 2012 16:05
Read Standard Input
#include <stdio.h>
int main() {
int input;
while(!feof(stdin)) {
scanf("%d",&input);
printf("%d\n",input);
}
return 0;
}
@iporsut
iporsut / cipher.c
Created August 14, 2012 08:50
ZOJ Problem Set - 1042 W's Cipher
#include <stdio.h>
#include <string.h>
#define MAX 80
char code1[MAX+1];
int pos1[MAX+1];
int code1_i, pos1_i ,len1;
char code2[MAX+1];
int pos2[MAX+1];
@iporsut
iporsut / zoj_1078.c
Created August 15, 2012 17:37
ZOJ 1078 : Palindrom Numbers
#include <stdio.h>
int base[16];
int palindrom(int len) {
int i,j;
for(i = 0,j = len-1; i < j; ++i, --j) {
if (base[i] != base[j])
return 0;
}
return 1;
@iporsut
iporsut / zoj_1251.c
Created August 16, 2012 10:24
ZOJ 1251 : Box of Bricks
#include <stdio.h>
int stack[50];
int width, i, height, sum, total_move, count = 1;
int main() {
scanf("%d",&width);
while (width != 0) {
for (i = sum = 0; i < width; sum += stack[i++])
scanf("%d",&stack[i]);
@iporsut
iporsut / zoj_1241.c
Created August 16, 2012 10:58
ZOJ 1241 : Geometry Made Simple
#include <stdio.h>
#include <math.h>
int a, b, c, count = 1;
double result;
int main() {
scanf("%d %d %d", &a, &b, &c);
while (a != 0 && b != 0 && c != 0) {
if (c == -1) {
@iporsut
iporsut / zoj_1073.c
Created August 17, 2012 02:02
ZOJ 1073 : Round and Round We Go
#include <stdio.h>
#include <string.h>
char digit[61];
char result[61];
int multiply_by(int n, int len) {
int i, carry = 0, v;
for (i = len-1; i >= 0; --i) {
v = (digit[i]-'0')*n + carry;
@iporsut
iporsut / zoj_2970.c
Created August 17, 2012 03:28
ZOJ 2970: Faster, Higher, Stronger
#include <stdio.h>
#include <string.h>
#define min(A,B) (A < B)?A:B
#define max(A,B) (A > B)?A:B
int main() {
int test, n, v, best;
char type[9];
@iporsut
iporsut / zoj_2165.c
Created August 17, 2012 05:23
ZOJ 2165 : Red and Black
#include <stdio.h>
char tile[20][21];
int count_black(int i, int j, int w, int h) {
int count = 0;
if (tile[i][j] == '.' || tile[i][j] == '@') {
count++;
tile[i][j] = '#';
}
@iporsut
iporsut / zoj_1002.c
Created August 17, 2012 06:49
ZOJ 1002: Fire Net
#include <stdio.h>
#include <string.h>
char square[4][5];
char temp[4][5];
typedef struct _point {
int i;
int j;
}Point;