This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(void) | |
{ | |
char keyword[11]; | |
char word[32]; | |
int counter = 0; | |
memset(keyword, '\0', sizeof(keyword)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 末尾再帰 tailRecursion.c | |
再帰的な関数recurを徐々に非再帰的にしていく | |
*/ | |
#include <stdio.h> | |
// 真に再帰的な関数recur | |
void recur(int n) | |
{ | |
if (n > 0) { | |
recur(n - 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); // スタック初期化の関数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
template <typename Type> Type square(Type x) | |
{ | |
return x * x; | |
} | |
int main() | |
{ | |
int a; | |
double b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 配列の全要素の最小値を求める関数テンプレートと明示的な特殊化 */ | |
#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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |