Skip to content

Instantly share code, notes, and snippets.

@amoshyc
amoshyc / booking_system_tutor.md
Last active August 29, 2015 14:08
booking_system_tutor.md

題目

CCU飯店共有N間房間( 0<N<300 ),且提供入住房客指定預入住房號的服務, 如果房客指定房間已有人入住,則提供下一間房間給房客, 亦即原指定房號加一。

但是由於房數眾多,辦理入住櫃檯經常會忘記哪個房間已有人入住。 因此,CCU飯店管理人員決定要請資訊部門幫忙研發一套簡單的軟體, 能夠記錄目前有哪些房間,已有人進住。

@amoshyc
amoshyc / maximum_subarray_problem.md
Last active August 29, 2015 14:08
Maximum subarray problem

Maximum subarray problem

Find the contiguous subarray within a one-dimensional array of numbers which has the largest sum.

Input:

−2 1 −3 4 −1 2 1 −5 4

Output:

@amoshyc
amoshyc / maximum_subarray_tutor.md
Last active August 29, 2015 14:09
maximum subarray tutorial

Maximum Subarray Problem

給定一序列,求此序列中哪一個區間的總和最大。請輸出其總和。

※ 這篇教學中所說的區間都是指連續區間。 ※ 區間的長度為 0 也可以,而長度為 0 的區間的總和為 0 ,所以最大的區間和一定大於等於 0

例如:

−2 1 −3 4 −1 2 1 −5 4
@amoshyc
amoshyc / DS_project4.md
Last active August 29, 2015 14:10
DS_project4: eval

DS Project4

Syntax:

./eval options "expression"

Input:

The input expression can be an infix expression or postfix expression after read in the expression.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int min(int a, int b) {
return ((a > b) ? b: a);
}
int calculate_steps(int data[][3], const char* combination) {
int steps = 0;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char input[100][100 + 2];
int idx = 0;
int max_len = 0;
#include <stdio.h>
#include <stdlib.h>
int primes[1000]; /*In fact, there's only 168 primes under 1000.*/
int p_idx = 0;
int is_prime(const int N) {
int i;
for (i=0; i<p_idx && primes[i]*primes[i] <= N; i++)
if (N % primes[i] == 0)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int g;
while (scanf("%d", &g)) {
if (g == 0) break;
char input[110];
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int primes[52*20];
void init_primes() {
int i, j;
for(i=0; i<52*20; i++)
primes[i] = 1;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
const int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const char* day[7] = { "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
int T;