anonymous No title
C++
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <stdlib.h>
using namespace std;
vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}
int main(int argc,char** argv,char** envp){
    string input = string("../data/") + argv[1] + ".csv";
    ifstream inputfs(input);
    if(!inputfs.fail()){
        string str;
        while(getline(inputfs,str)){
            cout << str << endl;
        }
        return 0;
    }
    ifstream tagfs("../data/tag.csv");
    ifstream geotagfs("../data/geotag.csv");
    string tag_line,geotag_line;
    
    if(tagfs.fail()){
        cerr << "Failed to open tag.csv" << endl;
        return -1;
    }
    if(geotagfs.fail()){
        cerr << "Failed to open geotag.csv" << endl;
    }
    cout << "file open" << endl;
    //list<string> result;
    vector<string> result;
    result.reserve(10000);
    while(getline(tagfs,tag_line)){
        //todo
        vector<string> tag_sp = split(tag_line,',');
        string tag_id = tag_sp[0];
        string tag = tag_sp[1];
        if(tag==argv[1]){
            cout << "pie" << endl;
            while (getline(geotagfs,geotag_line)){
                vector<string> geotag_sp = split(geotag_line,',');
                string geotag_id = geotag_sp[0];
                if(tag_id==geotag_id){
                    
                    string data = geotag_line.substr(11);
                    cout << data << endl;
                    result.push_back(data);//Segmentaion Fault
                    break;
                }
            }
        }
    }
    cout << "poyo" << endl;
    sort(result.begin(),result.end());
    //result.sort();
    ofstream ofs(input);
    if(ofs.fail()){
        cout << "fout.open failed" << endl;
        return -1;
    }
    for(auto itr = result.begin();itr !=result.end();++itr){
        cout << *itr << endl;
        ofs << *itr << endl;
    }
    
}


anonymous No title
C++
#include <bits/stdc++.h>

using namespace std;

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    // 二次元配列
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (s[i] == s[j] && i != j) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
            ans = max(ans, dp[i + 1][j + 1]);
        }
    }

    string ans_string;
    int x = n, y = n;
    while (x > 0 && y > 0) {
        if (dp[x][y] == dp[x - 1][y]) {
            x--;
        } else if (dp[x][y] == dp[x][y - 1]) {
            y--;
        } else {
            x--, y--;
            ans_string = s[x] + ans_string;
        }
    }
    cout << ans_string << '\n';
    cout << ans << '\n';
}

int main() {
    solve();
    return 0;
}
anonymous No title
C++
# include <Siv3D.hpp>

// シーンの名前
enum class State
{
    MainCtrl,
    PoseCtrl,
    Break
};

// シーン管理クラス
using MyApp = SceneManager<State, Data>;

// メインシーン
class MainCtrl : public MyApp::Scene{
private:
    Webcam webcam[2] = { Webcam(0),Webcam(1) };//Webcam宣言
    WebcamInfo webcamInfo;
    Image image;
    DynamicTexture texture;

    int useCam = 0;//Webcam変更用変数

public:
    MainCtrl(const InitData& init)
        : IScene(init) {
         webcam[0].setResolution(Size(640, 480));
         if (!webcam[0].start())
         {
             throw Error(U"Webcam 0 not available.");
         }
         webcam[1].setResolution(Size(640, 480));
         if (!webcam[1].start())
         {
             throw Error(U"Webcam 1 not available.");
         }
        const Size resolution = webcam[1].getResolution();
        Window::Resize(resolution);
    }

    void update() override
    {
        if (webcam[useCam].hasNewFrame())
        {
            webcam[useCam].getFrame(image);

            texture.fillIfNotBusy(image);
        }
    }

    void draw() const override
    {
        if (texture)
        {
            texture.draw();
        }
        for (const auto& info : System::EnumerateWebcams())
        {
            Print << U"[{}] {} `{}`"_fmt(info.index, info.name, info.uniqueName);
        }
    }
};


void Main()
{
    // 背景色を設定
    Scene::SetBackground(ColorF(0, 0, 0));

    // シーンと遷移時の色を設定
    MyApp manager;
    manager
        .add<MainCtrl>(State::MainCtrl)
        .setFadeColor(ColorF(1.0));

    while (System::Update())
    {
        if (!manager.update())
        {
            break;
        }
    }
}
anonymous No title
C++
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#define GENE 20 //個数
#define BIT 8 //箱の数
#define MAX 30 //量の最大値
#define GENERATION 30 // 世代数
#define CROSSOVER 0.2 // 交伹率
#define MUTATION 0.05 // 突然変異率

//構造体の定義
struct Gene
{
	int quantitiy[BIT]; //量
	int price[BIT]; //価格
	int bit[BIT]; //入れるか入れないか
	int sum_price; //価格の合計値
	int sum_quantity; //量の合計値
}gene[GENE], gene2;

struct Elite
{
	int sum_price;
	int sum_quantity;
}elite;

int generation_count;

void input()
{
	for (int i = 0; i < GENE; i++)
	{
		FILE *file;
		errno_t error;
		error = fopen_s(&file, "data.txt", "r");

		for (int j = 0; j < BIT; j++)
		{
			fscanf_s(file, "%d,%d", &gene[i].quantitiy[j], &gene[i].price[j]);

			//遺伝子の初期化
			gene[i].bit[j] = rand() % 2;
			//printf("%2d,%2d,%2d\n", gene[i].quantitiy[j], gene[i].price[j], gene[i].bit[j]);
		}
		fclose(file);
		//printf("**************************\n");
	}
	return;
}

void calculation()
{
	for (int i = 0; i < GENE; i++)
	{
		gene[i].sum_price = 0;
		gene[i].sum_quantity = 0;

		for (int j = 0; j < BIT; j++)
		{
			if (gene[i].bit[j] == 1)
			{
				gene[i].sum_price += gene[i].price[j];
			}
			if (gene[i].bit[j] == 1)
			{
				gene[i].sum_quantity += gene[i].quantitiy[j];
			}
		}
		//printf("%2d, %2d\n",gene[i].sum_quantity, gene[i].sum_price);
	}
	//printf("**************************\n");
}

void evalution()
{
	for (int  i = 0; i < GENE; i++)
	{

		if (gene[i].sum_quantity > MAX)
		{
			gene[i].sum_price = -1 * gene[i].sum_price;
		}
		//printf("%2d, %2d\n", gene[i].sum_quantity, gene[i].sum_price);
	}
	//printf("**************************\n");
}

void sort()
{

	//printf(" 量 価格\n");
	for (int i = 0; i < GENE; ++i)
	{
		for (int j = i+1; j<GENE; ++j)
		{
			if (gene[i].sum_price < gene[j].sum_price)
			{
				gene2 = gene[i];
				gene[i] = gene[j];
				gene[j] = gene2; 
			}
		}
		//printf("%2d, %2d\n", gene[i].sum_quantity, gene[i].sum_price);
	}

	for (int i = 0; i < GENE; i++)
	{
		if (gene[i].sum_price < 0)
		{
			gene[i].sum_price = -1 * gene[i].sum_price;
		}
	}

	for (int i = 0; i < 4; i++)
	{
		gene[GENERATION-i] = gene[i];
	}

	elite.sum_price = gene[0].sum_price;
	elite.sum_quantity = gene[0].sum_quantity;

	printf(" elite  %3d  %3d\n", elite.sum_quantity, elite.sum_price);

	for (int i = 0; i < BIT; i++)
	{
		printf("%d ", gene[0].bit[i]);
	}
	printf("\n");
}

void crosscover()
{
	int point /*交叉する位置*/, random_gene1 /*1つ目の親個体*/, random_gene2 /*2つ目の親個体*/, bit2 /*入れ物*/;

	for (int i = 0; i < (int)(GENE * CROSSOVER); i++)
	{
		point = rand() % (BIT - 2) + 2; // 交叉する位置をランダムで選択
		random_gene1 = rand() % (GENE - 1) + 1; // 1つ目の親個体

		do
		{
			random_gene2 = rand() % (GENE - 1) + 1; //2つ目の親個体
		} while (random_gene2 == random_gene1); //random_gene1とrandom_gene2が同じだったらrandom_gene2を選択し直し

		// 交叉
		for (int j = point; j < BIT; j++)
		{
			bit2 = gene[random_gene1].bit[j];
			gene[random_gene1].bit[j] = gene[random_gene2].bit[j];
			gene[random_gene2].bit[j] = bit2;
		}
	}
}

void mutation()
{
	int random_bit/*突然変異させる遺伝子*/, random_gene/*突然変異させる個体*/, mutation_bit/*突然変異後の値*/;

	for (int i = 0;i < (int)(GENE * MUTATION);i++) 
	{
		random_bit = rand() % (BIT - 2) + 1; // 突然変異させる遺伝子をランダムで選択
		random_gene = rand() % (GENE - 1) + 1; // 突然変異させる個体をランダムで選択

		do
		{
			mutation_bit = rand() % (BIT - random_bit) + random_bit;

		} while (gene[random_gene].bit[random_bit] == mutation_bit); // 元の遺伝子とは違うものが出るまで繰り返し

		gene[random_gene].bit[random_bit] = mutation_bit;

	}
}

int main()
{
	srand((unsigned)time(NULL)); // 乱数の初期化
	input();
	calculation();
	evalution();
	printf("初期値  \n");
	sort();

	for (int i = 0; i < GENERATION; i++)
	{
		printf("第%2d世代\n", i+1);
		crosscover();
		mutation();
		calculation();
		evalution();
		sort();
	}

	return 0;
}
anonymous No title
C++
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#define GENE 20 //個数
#define BIT 8 //箱の数
#define MAX 30 //量の最大値
#define GENERATION 40 // 世代数
#define CROSSOVER 0.2 // 交伹率
#define MUTATION 0.05 // 突然変異率

//構造体の定義
struct Gene
{
	int quantitiy[BIT]; //量
	int price[BIT]; //価格
	int bit[BIT]; //入れるか入れないか
	int sum_price; //価格の合計値
	int sum_quantity; //量の合計値
}gene[GENE], gene2;

struct Elite
{
	int sum_price;
	int sum_quantity;
}elite;

int generation_count;

void input()
{
	for (int i = 0; i < GENE; i++)
	{
		FILE *file;
		errno_t error;
		error = fopen_s(&file, "data.txt", "r");

		for (int j = 0; j < BIT; j++)
		{
			fscanf_s(file, "%d,%d", &gene[i].quantitiy[j], &gene[i].price[j]);

			//遺伝子の初期化
			gene[i].bit[j] = rand() % 2;
			//printf("%2d,%2d,%2d\n", gene[i].quantitiy[j], gene[i].price[j], gene[i].bit[j]);
		}
		fclose(file);
		//printf("**************************\n");
	}
	return;
}

void calculation()
{
	for (int i = 0; i < GENE; i++)
	{
		gene[i].sum_price = 0;
		gene[i].sum_quantity = 0;

		for (int j = 0; j < BIT; j++)
		{
			if (gene[i].bit[j] == 1)
			{
				gene[i].sum_price += gene[i].price[j];
			}
			if (gene[i].bit[j] == 1)
			{
				gene[i].sum_quantity += gene[i].quantitiy[j];
			}
		}
		//printf("%2d, %2d\n",gene[i].sum_quantity, gene[i].sum_price);
	}
	//printf("**************************\n");
}

void evalution()
{
	for (int  i = 0; i < GENE; i++)
	{

		if (gene[i].sum_quantity > MAX)
		{
			gene[i].sum_price = -1 * gene[i].sum_price;
		}
		//printf("%2d, %2d\n", gene[i].sum_quantity, gene[i].sum_price);
	}
	//printf("**************************\n");
}

void sort()
{

	//printf(" 量 価格\n");
	for (int i = 0; i < GENE; ++i)
	{
		for (int j = i+1; j<GENE; ++j)
		{
			if (gene[i].sum_price < gene[j].sum_price)
			{
				gene2 = gene[i];
				gene[i] = gene[j];
				gene[j] = gene2; 
			}
		}
		//printf("%2d, %2d\n", gene[i].sum_quantity, gene[i].sum_price);
	}

	for (int i = 0; i < GENE; i++)
	{
		if (gene[i].sum_price < 0)
		{
			gene[i].sum_price = -1 * gene[i].sum_price;
		}
	}

	elite.sum_price = gene[0].sum_price;
	elite.sum_quantity = gene[0].sum_quantity;

	printf(" elite  %3d  %3d\n", elite.sum_quantity, elite.sum_price);
}

void crosscover()
{
	int point /*交叉する位置*/, random_gene1 /*1つ目の親個体*/, random_gene2 /*2つ目の親個体*/, bit2 /*入れ物*/;

	for (int i = 0; i < (int)(GENE * CROSSOVER); i++)
	{
		point = rand() % (BIT - 2) + 2; // 交叉する位置をランダムで選択
		random_gene1 = rand() % (GENE - 1) + 1; // 1つ目の親個体

		do
		{
			random_gene2 = rand() % (GENE - 1) + 1; //2つ目の親個体
		} while (random_gene2 == random_gene1); //random_gene1とrandom_gene2が同じだったらrandom_gene2を選択し直し

		// 交叉
		for (int j = point; j < BIT; j++)
		{
			bit2 = gene[random_gene1].bit[j];
			gene[random_gene1].bit[j] = gene[random_gene2].bit[j];
			gene[random_gene2].bit[j] = bit2;

		}
	}
}

void mutation()
{
	int random_bit/*突然変異させる遺伝子*/, random_gene/*突然変異させる個体*/, mutation_bit/*突然変異後の値*/;

	for (int i = 0;i < (int)(GENE * MUTATION);i++) 
	{
		random_bit = rand() % (BIT - 2) + 1; // 突然変異させる遺伝子をランダムで選択
		random_gene = rand() % (GENE - 1) + 1; // 突然変異させる個体をランダムで選択

		do
		{
			mutation_bit = rand() % (BIT - random_bit) + random_bit;

		} while (gene[random_gene].bit[random_bit] == mutation_bit); // 元の遺伝子とは違うものが出るまで繰り返し

		gene[random_gene].bit[random_bit] = mutation_bit;

	}
}

int main()
{
	srand((unsigned)time(NULL)); // 乱数の初期化
	input();
	calculation();
	evalution();
	printf("初期値  \n");
	sort();

	for (int i = 0; i < GENERATION; i++)
	{
		printf("第%2d世代\n", i+1);
		crosscover();
		mutation();
		calculation();
		evalution();
		sort();
	}

	return 0;
}
anonymous C++,TSP
C++
#include <stdio.h> // printf等の入出力関数を使うため
#include <stdlib.h> // randとsrandを使うため
#include <time.h> // timeを使うため
#include <math.h> // sin, cos等の数学関数を使うため

// 以下,定数の定義
#define GENE 50 // 個体数
#define BIT 20 // 遺伝子数(都市の数)
#define GENERATION 200 // 世代数
#define CROSSOVER 0.4 // 交伹率
#define MUTATION 0.4 // 突然変異率
#define INVERSE 0.4 // 逆位率
#define SELECT 0.2 // 淘汰率
#define L 4 // 表示する座標系の範囲
#define PAI 3.1415926536 // πの定義

// 以下,構造体の定義
struct Gene 
{
	char city_name[BIT]; // 都市の巡回順
	int bit[BIT]; // 遺伝子
	double distance; // 全都市を巡回し終わった時の総距離
}gene[GENE] /*個体*/, gene2 /*ソートで使うための入れ物*/;

struct Elite 
{
	char city_name[BIT];
	double distance;
}elite[GENERATION]; // 各世代の最も総距離が短い個体

// 以下,変数の定義
int generation_count = 0; // 世代数をカウントする
double city_x[BIT]; // 都市のX座標
double city_y[BIT]; // 都市のY座標

// 以下,関数の定義 都市の座標,都市の名前,遺伝子の初期化
	void initial_data()
	{
		// 円用
		double angle;

		for (int i = 0;i < BIT;i++)
		{
			angle = (double)i * 2.0 * PAI / (double)BIT;

			city_x[i] = (double)L / 2 + (double)L / 2 * cos(angle);

			city_y[i] = (double)L / 2 + (double)L / 2 * sin(angle);
		}

		for (int i = 0;i < GENE;i++) 
		{
			// 遺伝子の初期化
			for (int j = 1;j < BIT;j++) 
			{

				gene[i].bit[j] = rand() % (BIT - j) + j;

			}
		}
	}

	// 遺伝子型から表現型へ
	void generate_gene(void)
	{
		char city_name2; // 右詰の作業で使うための入れもの

		for (int i = 0;i < GENE;i++) 
		{
			// ASCII文字コードを使ってアルファベットを都市数分入力する
			for (int j = 0;j < BIT;j++) {

				gene[i].city_name[j] = 65 + j;

			}
			// 右詰
			for (int j = 1;j < BIT;j++) 
			{
				city_name2 =
					gene[i].city_name[gene[i].bit[j]];

				for (int k = gene[i].bit[j]; k>j; k--) 
				{
					gene[i].city_name[k] = gene[i].city_name[k - 1];
				}

				gene[i].city_name[j] = city_name2;
			}
		}
	}

	// 距離の計算
	void distance(void)
	{
		double x, x2, y, y2;

		for (int i = 0;i < GENE;i++)
		{

			gene[i].distance = 0.0; // gene[i].distanceの初期化
			for (int j = 0;j < BIT - 1;j++)
			{
				x = city_x[gene[i].city_name[j] - 65];

				y = city_y[gene[i].city_name[j] - 65];
				x2 = city_x[gene[i].city_name[j + 1] -65];

				y2 = city_y[gene[i].city_name[j + 1] -65];

				gene[i].distance += sqrt(pow((double)x2 - (double)x, 2) + pow((double)y2 - (double)y, 2));
			}

			x = x2;
			y = y2;
			x2 = city_x[gene[i].city_name[0] - 65];
			y2 = city_y[gene[i].city_name[0] - 65];
			gene[i].distance += sqrt(pow((double)x2 -(double)x, 2) + pow((double)y2 - (double)y, 2));
		}
	}

	// ソート
	void sort(int generation)
	{
		for (int i = 0;i < GENE - 1;i++) 
		{
			for (int j = i + 1;j < GENE;j++) 
			{
				// gene[i]とgene[j]を交換
				if (gene[i].distance > gene[j].distance) 
				{
					gene2 = gene[i]; // gene[i]を一時的にgene2に退避させておく

					gene[i] = gene[j]; //gene[i]にgene[j]を移す

					gene[j] = gene2; // gene2に退避させておいたgene[i]をgene[j]に移す
				}

			}

		}
		for (int i = 0;i < BIT;i++) 
		{
			elite[generation].city_name[i] = gene[0].city_name[i];
		}

		elite[generation].distance = gene[0].distance;
	}

	// 交叉
	void crossover(void)
	{
		int point /*交差する位置*/, random_gene1 /*1つ目の親個体*/, random_gene2 /*2つ目の親個体*/, bit2 /*入れ物*/;

		for (int i = 0;i < (int)(GENE * CROSSOVER);i++) 
		{
			point = rand() % (BIT - 2) + 2; // 交伹する位置をランダムで選択
			random_gene1 = rand() % (GENE - 1) + 1; // 1つ目の親個体

				do
				{
					random_gene2 = rand() % (GENE - 1) + 1; //2つ目の親個体
				} while (random_gene2 == random_gene1); //random_gene1とrandom_gene2が同じだったらrandom_gene2を選択し直し

						// 交伹
						for (int j = point;j < BIT;j++) 
						{
							bit2 = gene[random_gene1].bit[j];
							gene[random_gene1].bit[j] =gene[random_gene2].bit[j];

							gene[random_gene2].bit[j] = bit2;
						}

		}

	}
	// 突然変異
	void mutation(void)
	{
		int random_bit/*突然変異させる遺伝子*/, random_gene/*突然変異させる個体*/, mutation_bit/*突然変異後の値*/;

		for (int i = 0;i < (int)(GENE * MUTATION);i++) {
			random_bit = rand() % (BIT - 2) + 1; // 突然変異させる遺伝子をランダムで選択
			random_gene = rand() % (GENE - 1) + 1; // 突然変異させる個体をランダムで選択

				do 
				{
					mutation_bit = rand() % (BIT - random_bit) + random_bit;

				}while (gene[random_gene].bit[random_bit] == mutation_bit); // 元の遺伝子とは違うものが出るまで繰り返し

				gene[random_gene].bit[random_bit] = mutation_bit;

		}

	}
	// 逆位
	void inverse(void)
	{
		int random_bit1/*逆位の範囲の最初の遺伝子*/, random_bit2/*逆位の範囲の最後の遺伝子*/, random_gene/*逆位させる個体*/, center, NAME[BIT];
		char city_name2;

		for (int i = 0;i < (int)(GENE * INVERSE);i++) {

			random_bit1 = rand() % (BIT - 2) + 1; // 逆位始めの遺伝子をランダムで選択

			random_bit2 = rand() % (BIT - (random_bit1 + 1)) + random_bit1 + 1; // 逆位終わりの遺伝子をランダムで選択

			center = (random_bit2 - random_bit1 + 1) / 2; // 逆位の範囲÷2(小数点以下切り捨て)

			random_gene = rand() % (GENE - 1) + 1; // 逆位させる個体をランダムに選択

				// 逆位
				for (int j = 0;j < center;j++) 
				{
					city_name2 = gene[random_gene].city_name[random_bit1 + j];

					gene[random_gene].city_name[random_bit1 + j] = gene[random_gene].city_name[random_bit2 - j];

					gene[random_gene].city_name[random_bit2 - j] = city_name2;
				}

			for (int j = 0;j < BIT;j++)
			{
				NAME[j] = 65 + j;
			}

			// 都市順から遺伝子へ変換
			for (int j = 0;j < BIT;j++) 
			{
				for (int k = j;k < BIT;k++) 
				{
					if (gene[random_gene].city_name[j] == NAME[k]) 
					{
						gene[random_gene].bit[j] = k;
						break;
					}

				}
				// 右詰
				for (int k = gene[random_gene].bit[j];k > 0;k--) 
				{
					NAME[k] = NAME[k - 1];
				}
			}
		}
	}
	// 淘汰
	void select(void)
	{
		for (int i = 0;i < (int)(GENE * SELECT);i++) 
		{

			gene[i + (int)(GENE * (1.0 - SELECT))] = gene[i];

		}
	}

	// 世代数と巡回順を表示する
	void print(void)
	{
		printf("%3d世代目:%2.7f ", generation_count + 1, elite[generation_count].distance);



		for (int i = 0;i < BIT;i++) 
		{
			printf("%c", elite[generation_count].city_name[i]);
		}

		printf("%c\n", elite[generation_count].city_name[0]);
	}
	
	/* 一定時間ごとに実行
	void timer(int value) 
	{
		if (generation_count < GENERATION - 1) 
		{
			generation_count++;
			print();
		}
	}*/

	// メイン関数
	int main(int argc, char* argv[])
	{
		srand((unsigned)time(NULL)); // 乱数の初期化
		initial_data();
		generate_gene();
		distance();
		sort(0);

		for (int i = 1;i < GENERATION;i++)
		{
			crossover();
			mutation();
			generate_gene();
			inverse();
			distance();
			sort(i);
			select();
			sort(i);

			if (generation_count < GENERATION - 1)
			{
				generation_count++;
				print();
			}

		}

		printf("  世代数  距離       巡回順\n");
		print();

		return 0;
	}
anonymous No title
C++
#include <stdio.h>
#include <string.h>

#define N 10

struct STUDENT
{
	int num;
	float height;
	float weight;
	char name[256];
}stdlist[N];

void file_read()
{
	FILE *file;
	errno_t error;
	error = fopen_s(&file, "meibo.txt", "r");

	printf("*学生データ*\n");
	printf(" 学生番号   身長  体重  名前\n");

	for (int i = 0; i < N; i++)
	{
		fscanf_s(file, "%d,%f,%f,%s", &stdlist[i].num, &stdlist[i].height, &stdlist[i].weight, stdlist[i].name, 256);
		printf("%d |%3.1f |%3.1f |%8s\n", stdlist[i].num, stdlist[i].height, stdlist[i].weight, stdlist[i].name);
	}

	fclose(file);
	return;
}

void sort()
{
	float tmp;
	int tmp2;
	char word[10][20];

	printf("\n*身長降順*\n");
	printf(" 学生番号   身長  体重  名前\n");

	for (int i = 0; i < N; ++i) 
	{
		for (int j = i + 1; j < N; ++j) 
		{
			if (stdlist[i].height < stdlist[j].height)
			{
				tmp = stdlist[i].height;
				stdlist[i].height = stdlist[j].height;
				stdlist[j].height = tmp;

				tmp2 = stdlist[i].num;
				stdlist[i].num = stdlist[j].num;
				stdlist[j].num = tmp2;

				tmp = stdlist[i].weight;
				stdlist[i].weight = stdlist[j].weight;
				stdlist[j].weight = tmp;

				strcpy_s(word[0], stdlist[i].name);
				strcpy_s(stdlist[i].name, stdlist[j].name);
				strcpy_s(stdlist[j].name, word[0]);
			}
		}
		printf("%d| %3.1f| %3.1f |%8s\n", stdlist[i].num, stdlist[i].height, stdlist[i].weight, stdlist[i].name);
	}

	printf("\n*体重降順*\n");
	printf(" 学生番号   身長  体重  名前\n");

	for (int i = 0; i < N; ++i)
	{
		for (int j = i + 1; j < N; ++j)
		{
			if (stdlist[i].weight < stdlist[j].weight)
			{
				tmp = stdlist[i].height;
				stdlist[i].height = stdlist[j].height;
				stdlist[j].height = tmp;

				tmp2 = stdlist[i].num;
				stdlist[i].num = stdlist[j].num;
				stdlist[j].num = tmp2;

				tmp = stdlist[i].weight;
				stdlist[i].weight = stdlist[j].weight;
				stdlist[j].weight = tmp;

				strcpy_s(word[0], stdlist[i].name);
				strcpy_s(stdlist[i].name, stdlist[j].name);
				strcpy_s(stdlist[j].name, word[0]);
			}
		}
		printf("%d |%3.1f |%3.1f |%8s\n", stdlist[i].num, stdlist[i].height, stdlist[i].weight, stdlist[i].name);
	}

	return;
}

int main()
{
	file_read();
	sort();

	return 0;
}
anonymous No title
C++
// キューの大きさ
#define QUEUE_LENGTH 16

// 通常のキュー
QueueHandle_t xQueue;

TaskHandle_t taskHandle;

void task1(void *pvParameters) {
  while (1) {
    uint32_t data;
    if (xQueueReceive(xQueue, &data, 0) == pdTRUE) {
      // キューを受信するまで待つ
      Serial.printf("data = %d\n", data);
    }
    delay(1);
  }
}

void setup() {
  Serial.begin(115200);
  delay(100);

  // キュー作成
  xQueue = xQueueCreate(QUEUE_LENGTH, sizeof(uint8_t));

  // Core1の優先度1で通知受信用タスク起動
  xTaskCreateUniversal(
    task1,
    "task1",
    8192,
    NULL,
    1,
    &taskHandle,
    APP_CPU_NUM
  );
}

int i = 0;
void loop() {
  i++;
  if (i % 10 == 0) {
    uint32_t data = i;
    uint8_t ret;

    // キューを送信
    ret = xQueueSend(xQueue, &data, 0);
  }

  delay(100);
}
anonymous No title
C++
/*
 copy folder and its contents.
 dest: destination directory
 source: source directory
 hwnd: window handle of caller. Security attribute is the same of hwnd owner.
 return: 0 if succeeded. otherwise non zero value.
*/
int copy_folder(const String& path_dest, const String& path_source, HWND hwnd) {
    SHFILEOPSTRUCT tSHFile = { 0 };
    tSHFile.hwnd = (hwnd == NULL) ? ::GetDesktopWindow() : hwnd;
    tSHFile.wFunc = FO_COPY;
    tSHFile.fFlags = FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI;
    tSHFile.fAnyOperationsAborted = TRUE;
    tSHFile.hNameMappings = NULL;
    tSHFile.lpszProgressTitle = _T("");

    // add \0\0 to the tail of folder name.
    // std::vector is used because std::string's operand+ can not add \0 (\0 is ignored).
    std::vector<TCHAR> pfrom(path_source.size() + 2);
    _tcscpy_s(pfrom.data(), path_source.size() + 2, path_source.c_str());
    pfrom[pfrom.size() - 1] = _T('\0');
    tSHFile.pFrom = pfrom.data();

    std::vector<TCHAR> pto(path_dest.size() + 2);
    _tcscpy_s(pto.data(), path_dest.size() + 2, path_dest.c_str());
    pto[pto.size() - 1] = _T('\0');
    tSHFile.pTo = pto.data();

    return SHFileOperation(&tSHFile);
}
anonymous No title
C++
#include<bits/stdc++.h>
#include<time.h>
using namespace std;
bool hlflag;
static int field[8][8][8];
static bool piece[512];
static int xlength,ylength,usefnum,usepnum,useppow,clistnum;
static int zlength;
static int clist[20000][4][3];
static vector<int> useclist[8][8][8];
static stack<int> puthis[4];
static int lputhis[5];
static vector<int> reachnum;
static void putpiece(int z,int y,int x,int nowhave){
    field[z][y][x] = nowhave;
    puthis[0].push(z);
    puthis[1].push(y);
    puthis[2].push(x);
    puthis[3].push(nowhave);
    piece[nowhave] = false;
}
static void deletepiece(){
    lputhis[4] = lputhis[3];
    for(int i = 0;i<4;i++){
        lputhis[i] = puthis[i].top();
        puthis[i].pop();
    }
    field[lputhis[0]][lputhis[1]][lputhis[2]] = -1;
    piece[lputhis[3]] = true;
}
static void shitazyunbi(){
    for(int i = 0;i<512;i++){
        piece[i] = true;
    }
    for(int i = 0;i<5;i++){
        lputhis[i] = -1;
    }
    usefnum = xlength*ylength*zlength;
    usepnum = 1;
    useppow = 0;
    while(usepnum<usefnum){
        usepnum += usepnum;
        useppow++;
    }
    for(int i = 0;i<useppow*2;i++){
        reachnum.push_back(0);
    }
}
static void makeclist(){
    int nowlistnum = 0;
    for(int i1 = 0;i1<zlength;i1++){
        for(int i2 = 0;i2<ylength;i2++){
            for(int i3 = 0;i3<xlength;i3++){
                if(i3<xlength-3){
                    for(int i4 = 0;i4<4;i4++){
                        clist[nowlistnum][i4][0] = i1;
                        clist[nowlistnum][i4][1] = i2;
                        clist[nowlistnum][i4][2] = i3+i4;
                        useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                    }
                    nowlistnum++;
                    if(i2<ylength-3){
                        for(int i4 = 0;i4<4;i4++){
                            clist[nowlistnum][i4][0] = i1;
                            clist[nowlistnum][i4][1] = i2+i4;
                            clist[nowlistnum][i4][2] = i3+i4;
                            useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                        }
                        nowlistnum++;
                        for(int i4 = 0;i4<4;i4++){
                            clist[nowlistnum][i4][0] = i1;
                            clist[nowlistnum][i4][1] = i2+3-i4;
                            clist[nowlistnum][i4][2] = i3+i4;
                            useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                        }
                        nowlistnum++;
                        if(i1<zlength-3){
                            for(int i4 = 0;i4<4;i4++){
                                clist[nowlistnum][i4][0] = i1+i4;
                                clist[nowlistnum][i4][1] = i2+i4;
                                clist[nowlistnum][i4][2] = i3+i4;
                                useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                            }
                            nowlistnum++;
                            for(int i4 = 0;i4<4;i4++){
                                clist[nowlistnum][i4][0] = i1+3-i4;
                                clist[nowlistnum][i4][1] = i2+i4;
                                clist[nowlistnum][i4][2] = i3+i4;
                                useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                            }
                            nowlistnum++;
                            for(int i4 = 0;i4<4;i4++){
                                clist[nowlistnum][i4][0] = i1+i4;
                                clist[nowlistnum][i4][1] = i2+3-i4;
                                clist[nowlistnum][i4][2] = i3+i4;
                                useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                            }
                            nowlistnum++;
                            for(int i4 = 0;i4<4;i4++){
                                clist[nowlistnum][i4][0] = i1+i4;
                                clist[nowlistnum][i4][1] = i2+i4;
                                clist[nowlistnum][i4][2] = i3+3-i4;
                                useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                            }
                            nowlistnum++;
                        }
                    }
                }
                if(i2<ylength-3){
                    for(int i4 = 0;i4<4;i4++){
                        clist[nowlistnum][i4][0] = i1;
                        clist[nowlistnum][i4][1] = i2+i4;
                        clist[nowlistnum][i4][2] = i3;
                        useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                    }
                    nowlistnum++;
                    if(i1<zlength-3){
                        for(int i4 = 0;i4<4;i4++){
                            clist[nowlistnum][i4][0] = i1+i4;
                            clist[nowlistnum][i4][1] = i2+i4;
                            clist[nowlistnum][i4][2] = i3;
                            useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                        }
                        nowlistnum++;   
                        for(int i4 = 0;i4<4;i4++){
                            clist[nowlistnum][i4][0] = i1+3-i4;
                            clist[nowlistnum][i4][1] = i2+i4;
                            clist[nowlistnum][i4][2] = i3;
                            useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                        }
                        nowlistnum++;          
                    }
                }
                if(i1<zlength-3){
                    for(int i4 = 0;i4<4;i4++){
                        clist[nowlistnum][i4][0] = i1+i4;
                        clist[nowlistnum][i4][1] = i2;
                        clist[nowlistnum][i4][2] = i3;
                        useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                    }
                    nowlistnum++;
                    if(i3<xlength-3){
                        for(int i4 = 0;i4<4;i4++){
                            clist[nowlistnum][i4][0] = i1+i4;
                            clist[nowlistnum][i4][1] = i2;
                            clist[nowlistnum][i4][2] = i3+i4;
                            useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                        }
                        nowlistnum++;
                        for(int i4 = 0;i4<4;i4++){
                            clist[nowlistnum][i4][0] = i1+3-i4;
                            clist[nowlistnum][i4][1] = i2;
                            clist[nowlistnum][i4][2] = i3+i4;
                            useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                        }
                        nowlistnum++;
                    }
                }
            }
        }
    }
    if(hlflag){
        for(int i1 = 0;i1<3;i1++){
            for(int i2 = 0;i2<3;i2++){
                for(int i4 = 0;i4<4;i4++){
                    clist[nowlistnum][i4][0] = 0;
                    clist[nowlistnum][i4][1] = i1+(i4%2);
                    clist[nowlistnum][i4][2] = i2+(i4/2);
                    useclist[clist[nowlistnum][i4][0]][clist[nowlistnum][i4][1]][clist[nowlistnum][i4][2]].push_back(nowlistnum);
                }
                nowlistnum++;
            }
        }
    }
    clistnum = nowlistnum;
}
static vector<int> binkai(int a){
    vector<int> ret; 
    for(int i = 0;i<useppow;i++){
        ret.push_back(-1);
    }
    int cnt = 0;
    while(a>0){
        ret[cnt]=a%2+a%2-1;
        a/=2;
        cnt++;
    }
    return ret;
}
static int firstcheck(int nowhave){
    int wlist = -1;
    for(int i1 = clistnum-1;i1>-1;i1--){
        int nowlist = i1;
        vector<int> binnhave = binkai(nowhave);
        vector<int> sum(useppow);
        for(int i = sum.size()-1;i>-1;i--){
            sum[i] = 0;
        }
        bool spaceflag = false;
        for(int i2 = 0;i2<4;i2++){
            int cpiece = field[clist[nowlist][i2][0]][clist[nowlist][i2][1]][clist[nowlist][i2][2]];
            if(cpiece != -1){
                vector<int> tmp = binkai(cpiece);
                for(int i3 = 0;i3<useppow;i3++){
                    sum[i3] += tmp[i3];
                }
            }else{
                if(spaceflag){
                    break;
                }
                spaceflag = true;
            }
        }
        if(!spaceflag){
            continue;
        }
        for(int i2 = 0;i2<useppow;i2++){
            if(sum[i2] == 3){
                reachnum[i2+i2+1]++;
                if(binnhave[i2] == 1){
                    wlist = nowlist;
                }
            }
            if(sum[i2] == -3){
                reachnum[i2+i2]++;
                if(binnhave[i2] == -1){
                    wlist = nowlist;
                }
            }
        }
    }
    return wlist;
}
static vector<int> recheck(int z,int y,int x){
    vector<int> kaeriti(useppow*2);
    for(int i1 = useclist[z][y][x].size()-1;i1>-1;i1--){
        int nowlist = useclist[z][y][x][i1];
        vector<int> sum(useppow);
        for(int i = sum.size()-1;i>-1;i--){
            sum[i] = 0;
        }
        bool spaceflag = false;
        for(int i2 = 0;i2<4;i2++){
            int cpiece = field[clist[nowlist][i2][0]][clist[nowlist][i2][1]][clist[nowlist][i2][2]];
            if(cpiece != -1){
                vector<int> tmp = binkai(cpiece);
                for(int i3 = 0;i3<useppow;i3++){
                    sum[i3] += tmp[i3];
                }
            }else{
                if(spaceflag){
                    break;
                }
                spaceflag = true;
            }
        }
        if(!spaceflag){
            continue;
        }
        for(int i2 = 0;i2<useppow;i2++){
            if(sum[i2] == 3){
                kaeriti[i2+i2+1] +=1;
            }
            if(sum[i2] == -3){
                kaeriti[i2+i2] +=1;
            }
        }
    }
    return kaeriti;
}
static bool ittezumedesuka(int nowhave){
    int tmpi = nowhave;
    int powi5 = 1;
    for(int i5 = 0;i5<useppow;i5++){
        if(reachnum[i5+i5] != 0 && reachnum[i5+i5+1] != 0){
            return true;
        }
        if(reachnum[i5+i5+1] != 0 && ((tmpi & powi5) == powi5)){
            return true;
        }
        if(reachnum[i5+i5] != 0 && ((tmpi & powi5) == 0)){
            return true;
        }
        powi5 += powi5;
    }
    return false;
}
static bool iswin(int nowhave,int nowdepth){
    if(nowdepth == 0)return false;
    for(int i1 = zlength-1;i1>-1;i1--){
        for(int i2 = ylength-1;i2>-1;i2--){
            for(int i3 = xlength-1;i3>-1;i3--){            
                if(field[i1][i2][i3] != -1){
                    continue;
                }
                vector<int> deadreach = recheck(i1,i2,i3);
                putpiece(i1,i2,i3,nowhave);
                vector<int> newreach = recheck(i1,i2,i3);
                for(int i4 = 0;i4<useppow*2;i4++){
                    reachnum[i4] = reachnum[i4] + newreach[i4] - deadreach[i4];
                }
                int tmpi = 0;
                while(true){
                    int powi5 = 1;
                    for(int i5 = 0;i5<useppow;i5++){
                        if(reachnum[i5+i5] != 0 && reachnum[i5+i5+1] != 0){
                            goto endloop1;
                        }
                        if(reachnum[i5+i5+1] != 0 && ((tmpi & powi5) != 0)){
                            tmpi += powi5;
                        }  
                        if(reachnum[i5+i5] != 0 && ((tmpi & powi5) == 0)){
                            tmpi += powi5;
                        }
                        powi5 += powi5;
                    }
                    if(tmpi>usepnum-1)break;
                    if(piece[tmpi]){
                        if(!iswin(tmpi,nowdepth - 1)){
                            deletepiece();
                            for(int i4 = 0;i4<useppow*2;i4++){
                                reachnum[i4] = reachnum[i4] - newreach[i4] + deadreach[i4];
                            }             
                            return true;
                        }
                    }
                    tmpi++;
                }
                endloop1:;
                deletepiece();
                for(int i4 = 0;i4<useppow*2;i4++){
                    reachnum[i4] = reachnum[i4] - newreach[i4] + deadreach[i4];
                }
            }
        }
    }
    return false;
}
int main(){
    int hltmpflag;
    cin >> zlength >> ylength >> xlength >> hltmpflag;
    if(hltmpflag == 0){
        hlflag = false;
    }else{
        hlflag = true;
    }
    int nokori = 0;
    shitazyunbi();
    for(int i1 = 0;i1 < zlength;i1++){
        for(int i2 = 0;i2 < ylength;i2++){
            for(int i3 = 0;i3<xlength;i3++){
                cin >> field[i1][i2][i3];
                if(field[i1][i2][i3] == -1){
                    nokori++;
                }else{
                    piece[field[i1][i2][i3]] = false;
                }
            }
        }
    }
    int youhave;
    clock_t startt,endt;
    cin >> youhave;
    makeclist();
    int winlist = firstcheck(youhave);
    for(int i = 0;i<nokori;i++){
        bool iwillwin;
        if(i == 0){
            startt = clock();
            if(ittezumedesuka(youhave)){
                iwillwin = true;
                lputhis[3] = youhave;
                for(int i1 = 0;i1<4;i1++){
                    if(field[clist[winlist][i1][0]][clist[winlist][i1][1]][clist[winlist][i1][2]] == -1){
                        for(int i2 = 0;i2<3;i2++){
                            lputhis[i2] = clist[winlist][i1][i2];
                        }
                    }
                }
            }else iwillwin = false;
            endt = clock();
        }else if(i == 1){
            startt = clock();
            if(iswin(youhave,i)){
                iwillwin = true;
                vector<int> deadreach = recheck(lputhis[0],lputhis[1],lputhis[2]);
                putpiece(lputhis[0],lputhis[1],lputhis[2],youhave);
                vector<int> newreach = recheck(lputhis[0],lputhis[1],lputhis[2]);
                for(int i4 = 0;i4<useppow*2;i4++){
                    reachnum[i4] = reachnum[i4] + newreach[i4] - deadreach[i4];
                }
                int tmpi = 0;
                while(true){
                    int powi5 = 1;
                    for(int i5 = 0;i5<useppow;i5++){
                        if(reachnum[i5+i5] != 0 && reachnum[i5+i5+1] != 0){
                        }
                        if(reachnum[i5+i5+1] != 0 && ((tmpi & powi5) == powi5)){
                            tmpi += powi5;
                        }  
                        if(reachnum[i5+i5] != 0 && ((tmpi & powi5) == 0)){
                            tmpi += powi5;
                        }
                        powi5 += powi5;
                    }
                    if(piece[tmpi]){
                        lputhis[3] = tmpi;
                        deletepiece();
                        for(int i4 = 0;i4<useppow*2;i4++){
                            reachnum[i4] = reachnum[i4] - newreach[i4] + deadreach[i4];
                        }
                        break;
                    }
                    tmpi++;
                }
            }else{
                iwillwin = false;
            }
            endt = clock();
        }else if(i%2 == 0){
            startt = clock();
            iwillwin = iswin(youhave,i);
            endt = clock();
        }else{
            startt = clock();
            iwillwin = iswin(youhave,i);
            endt = clock();
        }
        cout << "depth = " << i + 1 << " ";
        printf("%f", (double)(endt - startt) / CLOCKS_PER_SEC);
        cout << "sec" << endl;
        if(iwillwin && i%2 == 0){
            cout << "win " << endl;
            cout << "put " << lputhis[3] << " (" << lputhis[0] << "," << lputhis[1] << "," << lputhis[2] << ") ";
            cout << "give " << lputhis[4] << endl;
            return 0;
        }else if(iwillwin || i%2 == 0){
            if(i%2 == 0){
                cout << "notwin" << endl;
            }else{
                cout << "notlose" << endl;
                cout << "put " << lputhis[3] << " (" << lputhis[0] << "," << lputhis[1] << "," << lputhis[2] << ") ";
                cout << "give " << lputhis[4] << endl;
            }
        }else{
            cout << "lose" << endl;
            return 0;
        }
        cout << endl;
    }
    return 0;
}
Don't you submit code?
Submit
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら