りゅうちゃん@hパラメータ No title
C++
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int a[100], n, i,s,h,z,x;
    float j;
    srand(100);
    printf("Input n=?\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        a[i]=rand()%100;
        printf("a[%d]=%d\n",i,a[i]);

    }
    s=0;
    z=0;
    x=0;
    for(i=1;i<=n;i++){
        s=s+a[i];
        if(a[i]>z){
            z=a[i];
        }else{
        }

    }
    h = s / n;
    for(i=1;i<=n;i++){
        x=x+((a[i]-h)*(a[i]-h));
    }
    j=sqrt(x/n);
    printf("sum=%d\n",s);
    printf("avarage=%d\n",h);
    printf("max=%d\n",z);
    printf("標準偏差=%f",j);
}
anonymous No title
C++
#include "stdio.h"

//階乗関数
double fact(double k) {
	double y,i;
	y = 1;
	for (i = 1; i <= k;i++) {
		y = y * i;
	}
	return(y);
}

int main() {
	double c, n, r, i;

	//入力
	printf("n=");
	scanf_s("%lf",&n);
	printf("r=");
	scanf_s("%lf",&r);

	c = fact(n) / (fact(r)*fact(n-r));

	printf("%lf",c);
}
anonymous No title
C++
#include "stdio.h"
#include "stdlib.h"
#include "math.h"

int main() {
	double sum, ave, max, sd, devi;
	int count;
	int rand_nums [10];

	//変数初期化
	sum = 0, ave = 0, max = 0, sd = 0, devi = 0;

	//乱数配列 --1から100の乱数--
	for (count = 0; count < 10; count++) {
		rand_nums [count] = rand() % 100 +1;
	}

	//##############################################################

	//合計
	for (count = 0; count < 10; count++) {
		sum += rand_nums [count];
	}

	//平均
	ave = sum / 10;

	//最大
	max = rand_nums[0];
	for (count = 1; count < 10; count++) {
		if (max < rand_nums [count]) {
			max = rand_nums[count];
		}
	}

	//標準偏差
	for (count = 0; count < 10; count++) {
		devi += pow((rand_nums [count] - ave),2);
	}
	sd = sqrt(devi / 10);

	//##############################################################

	//表示
	printf("乱数:");
	for (count = 0; count < 10; count++) {
		printf("%d,", rand_nums [count]);
	}
	printf("\n合計:%lf\n平均:%lf\n最大:%lf\n標準偏差:%lf\n", sum, ave, max, sd);

	return 0;
}
anonymous No title
C++
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"hello"<<endl;
}
anonymous No title
C++
#include <Arduino.h>

#if defined( ARDUINO_M5Stack_Core_ESP32 ) || defined( ARDUINO_M5STACK_FIRE )
  #include "M5Stack.h"
#elif defined( ARDUINO_M5Stick_C )
  #include "M5StickC.h"
#endif

void setup() {
  M5.begin();
  M5.Lcd.fillScreen(RED);
}

void loop() {
}
anonymous No title
C++
#include <LGFX_TFT_eSPI.hpp>
#include "AXP192.h"
#include "utility/Config.h"
#include "utility/SH200Q.h"
#include "utility/MPU6886.h"
#include "utility/Button.h"
#include "utility/CommUtil.h"
#include "RTC.h"
#include "IMU.h"
 
#define BLACK               0x0000
#define NAVY                0x000F
#define DARKGREEN           0x03E0
#define DARKCYAN            0x03EF
#define MAROON              0x7800
#define PURPLE              0x780F
#define OLIVE               0x7BE0
#define LIGHTGREY           0xC618
#define DARKGREY            0x7BEF
#define BLUE                0x001F
#define GREEN               0x07E0
#define CYAN                0x07FF
#define RED                 0xF800
#define MAGENTA             0xF81F
#define YELLOW              0xFFE0
#define WHITE               0xFFFF
#define ORANGE              0xFD20
#define GREENYELLOW         0xAFE5
#define PINK                0xF81F
 
class M5StickCBoth {
  public:
    void begin(bool LCDEnable = true, bool PowerEnable = true, bool SerialEnable = true) {
      if (SerialEnable) {
        Serial.begin(115200);
        Serial.flush();
        delay(50);
        Serial.print("M5StickC initializing...");
      }
      if (PowerEnable) {
        Axp.begin();
      }
      if (LCDEnable) {
        Lcd.begin();
      }
      if (SerialEnable) {
        Serial.println("OK");
      }
      Rtc.begin();
    }
    void update() {
      BtnA.read();
      BtnB.read();
    }
    TFT_eSPI Lcd;
    AXP192 Axp = AXP192();
    const int DEBOUNCE_MS = 10;
    Button BtnA = Button(BUTTON_A_PIN, true, DEBOUNCE_MS);
    Button BtnB = Button(BUTTON_B_PIN, true, DEBOUNCE_MS);
    RTC  Rtc;
    IMU Imu;
    CommUtil I2C = CommUtil();
    MPU6886 Mpu6886;
    SH200Q Sh200Q;
};
 
static M5StickCBoth M5;
 
void setup() {
  M5.begin();
}
 
void loop() {
  M5.Lcd.fillScreen(WHITE);
  delay(1000);
  M5.Lcd.fillScreen(BLACK);
  delay(1000);
}
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;
}
Don't you submit code?
Submit