Skip to content

Instantly share code, notes, and snippets.

View chomado's full-sized avatar
🎀
Working

ちょまど | Madoka Chiyoda chomado

🎀
Working
View GitHub Profile
#include <stdio.h>
#include <string.h>
int main(void)
{
char keyword[11];
char word[32];
int counter = 0;
memset(keyword, '\0', sizeof(keyword));
@chomado
chomado / tailRecursion.c
Created July 16, 2014 03:55
末尾再帰
/* 末尾再帰 tailRecursion.c
再帰的な関数recurを徐々に非再帰的にしていく
*/
#include <stdio.h>
// 真に再帰的な関数recur
void recur(int n)
{
if (n > 0) {
recur(n - 1);
@chomado
chomado / stackByArray.c
Last active August 29, 2015 14:04
Stack実装 配列を使って. (だから要素数は有限, 静的)
#include <stdio.h>
#include <stdlib.h>
#define MAX 256
/* must keep the length of the stack (in the array implementation) */
typedef struct {
size_t size; // スタックのサイズ(要素数)
int items[MAX]; // スタック本体みたいな感じ.要素が入る配列
} Stack;
void init (Stack *stckPtr); // スタック初期化の関数
@chomado
chomado / p304.cpp
Last active August 29, 2015 14:04
テンプレート練習
#include <iostream>
using namespace std;
template <typename Type> Type square(Type x)
{
return x * x;
}
int main()
{
int a;
double b;
@chomado
chomado / p308.cpp
Created August 4, 2014 01:12
テンプレート練習。明示的な特殊化
/* 配列の全要素の最小値を求める関数テンプレートと明示的な特殊化 */
#include <iostream>
#include <cstring>
using namespace std;
/* 配列a全要素の最小値を求める */
template <typename Type> Type minof(const Type a[], int n)
{
Type min = a[0];
for (int i=1; i<n; i++) {
if (a[i] < min) {
@chomado
chomado / game.cpp
Created August 4, 2014 01:49
P312数当てゲーム。ファイル分割の練習。途中で写経飽きたので途中
#include <ctime>
#include <cstdlib>
#include "util.h"
using namespace std;
static int answer = 0;
void initialize() {
srand(time(NULL));
}
void gen_no() {
answer = rand() % (max_no + 1);
@chomado
chomado / a.h
Last active August 29, 2015 14:04
// doesn't work
#include <string>
#include <iostream>
class Human {
private:
std::string full_name;
int height;
int wight;
public:
Human(std::string name, int h, int w); // コンストラクタ
std::string name() { return full_name; }
class Time {
int h;
int m;
int s;
public:
Time(int hh, int mm, int ss);
int hour() { return h; }
int minute() { return m; }
int second() { return s; }
}
#include <iostream>
int Gcd(int a, int b) // Greatest Common Divisor
{
if (!a || !b) {
return 0;
}
while (a != b) {
if (a < b)
std::swap(a, b);
a -= b;
#include <iostream>
const int first = 100000;
int round_up(int price) // 1000円未満を切り上げ
{
if (price%1000 == 0) {
return price;
}
int complement = 1000 - price%1000; // 補数
return (price + complement);
}