Skip to content

Instantly share code, notes, and snippets.

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

Sky N̂g kenornotes

🏠
Working from home
  • Imonology Inc.
  • Melbourne, Victoria, Australia
View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void getRandNum(int ans[]) {
// 洗牌取亂數
// 準備好 pool 陣列,把0~9依序放入
int pool[10], i;
for(i = 0; i <= 9; i++)
pool[i] = i;
// 初始化亂數種子
#include <stdio.h>
#include <string.h>
//use strtok(string.h) to split token
//reference: http://www.cplusplus.com/reference/cstring/strtok
int main() {
char str[] = "this is token test";
char str2[] = "it will show how to split string";
char * token;
#include <stdio.h>
int func(int price) {
int count = 0;
while(price > 50) {
price = price / 2;
count = count + 1;
}
return count;
}
int main() {
#include <stdio.h>
//return if input is leap year
int leap(int year) {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
//return leap day between base day and target day.
int leapDay(int year, int month, int date) {
int count = 0, i;
//大於等於基準日 2000 / 01 / 01
if(year >= 2000) {
#include <stdio.h>
int main() {
// 輸入學生數量 n
int n;
scanf("%d", &n);
// 輸入 n 個學生成績,並計算成績總和
int grade[n], i, sum = 0;
for(i = 0; i < n; i++) {
scanf("%d", &grade[i]);
sum += grade[i];
#include <stdio.h>
int weight,result = 0;//result 紀錄是否有解,為 0 則無解,為 1 則有解
/*
* combination function:
* s array記錄所有砝碼的重量
* m 表示砝碼的個數
* n 想要取的砝碼個數
*/
void combination(int *s, int m, int n, int pos, int got) {
int i, tmp, sum;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sort(int x[], int n) {
/* 上課教過 */
}
// 亂數取得號碼,放至 drawNum[] 中
void getDrawNum(int drawNum[]) {
/* 見 Judge 2-1 */
#include <stdio.h>
//判定是不是一串1
int isOnes(int n) {
while(n > 0) {
if(n % 10 != 1)
return 0;
n /= 10;
}
return 1;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sort(int x[], int n) {
/* 略 */
}
// 亂數取得號碼,放至 drwaNum[] 中
void getDrawNum(int drawNum[]) {
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//判斷 x 是否為質數
int isPrime(int x) {
int i;
for (i = 2; i < x; i++) {
//出現 1 及 x 本身以外的因數,所以不是質數
if ( x % i == 0 )