フェアリーテイルを読む、赤紙を書く No title
C++
#include <stdio.h>
#include <stdlib.h>
int main(void){
    unsigned char header[0x36];
    unsigned char **data;
    unsigned char *temp_data;
    char in_f_name[20] = "./LENNA.bmp", out_f_name[20];
    FILE *in_f, *out_f;
    long start_addr, end_addr;
    int width, height, color_bit;
    int i, j, k;
    if ((in_f=fopen(in_f_name, "rb"))==NULL){
        printf("Error on open file.\n");
    }

    /* header */
    for (int i=0; i<0x36; i++){
        header[i] = fgetc(in_f);
        // printf("%x: %x\n", i, header[i]);
    }
    start_addr = header[0x0A] + header[0x0B] * 0x100;
    end_addr = header[0x02] + header[0x03]*0x100 + header[0x04]*0x10000 + header[0x05]*0x1000000;
    width = header[0x12] + header[0x13] * 0x100;
    height = header[0x16] + header[0x17] * 0x100;
    color_bit = header[0x1C];
    printf("data_addr: 0x%x to 0x%x\n", start_addr, end_addr);
    printf("width: %d\n", width);
    printf("height: %d\n", height);
    printf("color: %xbit\n", color_bit);

    /* color parett*/
    for (int i=0x36; i<start_addr; i++){
        fgetc(in_f);
    }

    /* data */
    data = (char **)malloc(sizeof(char *) * height);
    for(i=0; i<height; i++){
        data[i] = (char *) malloc(sizeof(char)*width);
    }

    // 1D data for 2D data
    temp_data = (char *)malloc(sizeof(char) * (end_addr - start_addr));
    for(i=start_addr; i<end_addr; i++){
        temp_data[i-start_addr] = fgetc(in_f);
    }

    free(temp_data);
    free(data);

}
フェアリーテイルを読む、赤紙を書く No title
C++
#include <stdio.h>
#include <stdlib.h>
int main(void){
    unsigned char header[0x36];
    unsigned char **data;
    unsigned char *temp_data;
    char in_f_name[20] = "./LENNA.bmp", out_f_name[20];
    FILE *in_f, *out_f;
    long start_addr, end_addr;
    int width, height, color_bit;
    if ((in_f=fopen(in_f_name, "rb"))==NULL){
        printf("Error on open file.\n");
    }

    /* header */
    for (int i=0; i<0x36; i++){
        header[i] = fgetc(in_f);
        // printf("%x: %x\n", i, header[i]);
    }
    start_addr = header[0x0A] + header[0x0B] * 0x100;
    end_addr = header[0x02] + header[0x03]*0x100 + header[0x04]*0x10000 + header[0x05]*0x1000000;
    width = header[0x12] + header[0x13] * 0x100;
    height = header[0x16] + header[0x17] * 0x100;
    color_bit = header[0x1C];
    printf("data_addr: 0x%x to 0x%x\n", start_addr, end_addr);
    printf("width: %d\n", width);
    printf("height: %d\n", height);
    printf("color: %xbit\n", color_bit);

    /* color parett*/
    for (int i=0x36; i<start_addr; i++){
        fgetc(in_f);
    }

    /* data */
    data = (char **)malloc(sizeof(char *) * height);
    for(int i=0; i<height; i++){
        data[i] = (char *) malloc(sizeof(char)*width);
    }
    temp_data = (char *)malloc(sizeof(char) * (end_addr - start_addr));
    for(int i=start_addr; i<end_addr; i++){
        temp_data[i-start_addr] = fgetc(in_f);
    }

    free(temp_data);
    free(data);

}
anonymous No title
C++
//迷路(改良ver) はぎさんのやり方を参考にしました
#include <iostream>
#include <random>
#include <ctime>
#include <vector>
#include <stdio.h>

using namespace std;

class Labyrinth {
    private: 
        int xSize;
        int ySize;
        int directionsArray[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; //コンパイル時warnigが出るが動作には問題なし
        vector<vector<bool> > maze;

    public:
        Labyrinth(int xSize, int ySize);
        bool JudgeEdge(int x_index, int y_index);
        bool judgeDirections(int x_index, int y_index, int direction);
        bool searchDigable();
        vector<int> getMovableDirections(int x_index, int y_index);
        vector<int> getRestartPoint(); 
        vector<int> digRoad(int x_index, int y_index, int digableDirection); 
        void digMaze();
        void print(); 
        ~Labyrinth();
};

//コンストラクタ
Labyrinth::Labyrinth(int xSize, int ySize) {
    srand(time(NULL));
    this->xSize = xSize;
    this->ySize = ySize;
    //迷路の土台を生成
    maze.resize(xSize, vector<bool>(ySize));
    for (int i = 0; i < xSize; i ++) {
        for (int j = 0; j < ySize; j ++) {
            maze[i][j] = false;
        }
    }
    maze[1][1] = true; //スタート地点
}

//引数によって与えられた座標が壁であるかを判定する
bool Labyrinth::JudgeEdge(int x_index, int y_index) {
    int edge_array[4] = {0, ySize - 1, xSize - 1, 0}; // 上, 右, 下, 左の順番
    for (int i = 0; i < 4; i ++) {
        if (i % 2 == 0 && x_index == edge_array[i]) {
            return false;
        } else if (i % 2 == 1 && y_index == edge_array[i]) {
            return false;
        }
    }
    return true;
}

//リスタート地点の取得
vector<int> Labyrinth::getRestartPoint() {
    vector<int> restart_point;
    vector<vector <int> > restart_points;
    for (int i = 1; i < xSize - 1; i ++) {
        for (int j = 1; j < ySize - 1; j ++) {
            if (maze[i][j]) {
                if (getMovableDirections(i, j).size() > 0) {
                    //リスタート地点の座標が入ったらforを抜ける
                    restart_point.push_back(i); //0番目にはx座標
                    restart_point.push_back(j); //1番目にはy座標
                    restart_points.push_back(restart_point);
                    restart_point.clear();
                    break;
                }
            }
        }
    }
    if (restart_points.size() > 0) {
        //x, yの要素番号は一対一対応であるのでxだけ求めれば良い
        int restart_point_index = rand() % restart_points.size();
        restart_point.push_back(restart_points[restart_point_index][0]); //x座標にpush_back
        restart_point.push_back(restart_points[restart_point_index][1]); //y座標にpush_back
        return restart_point;
    }

    restart_point.clear();
    return restart_point;
}

//上下左右に対してその方向に進めるかを判定する
bool Labyrinth::judgeDirections(int x_index, int y_index, int direction) {
    //指定した座標がまだ掘られていない場所かつ壁ではなければ通る
    if (maze[x_index + directionsArray[direction][0]][y_index + directionsArray[direction][1]] == false &&
        JudgeEdge(x_index + directionsArray[direction][0], y_index + directionsArray[direction][1])) {
        return true;
    }

    return false;
}

//judgeDirectionsで返された値からさらにその先へ進めるかの判定->進めたらその方向を返す
vector<int> Labyrinth::getMovableDirections(int x_index, int y_index) {
    vector<int> digable_directions;
    int more_directions[4][3] = {{3, 0, 1}, {0, 1, 2}, {1, 2, 3}, {2, 3, 0}}; //三方向の判定->4パターンあり, 時計回りの順番で判定
    int judge_count = 0; 
    for (int i = 0; i < 4; i ++) {
        for (int j = 0; j < 3; j ++) {
            if (judgeDirections(x_index, y_index, i)) { 
                if (maze[x_index + directionsArray[i][0] + directionsArray[more_directions[i][j]][0]][y_index + directionsArray[i][1] + directionsArray[more_directions[i][j]][1]] == false) {
                    judge_count ++;
                }
            }
        }
        if (judge_count == 3) {
            digable_directions.push_back(i);
        }
        judge_count = 0;
    }    

    return digable_directions;
}

bool Labyrinth::searchDigable() {
    //迷路全体の調査
    for (int i = 1; i < xSize - 1; i ++) {
        for (int j = 1; j < ySize - 1; j ++) {
            if (maze[i][j]) {
                for (int k = 0; k < 4; k ++) {
                    if (getMovableDirections(i, j).size() != 0) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}

//迷路を作っていく
void Labyrinth::digMaze() {
    int x_index = 1;
    int y_index = 1;
    while(searchDigable() != false) {
        vector<int> directions = getMovableDirections(x_index, y_index);
        if (directions.size() > 0) {
            int digableDirection = rand() % directions.size();
            vector<int> next_point = digRoad(x_index, y_index, directions[digableDirection]);
            //次の座標の設定
            if (next_point.size() > 0) {
                x_index = next_point[0];
                y_index = next_point[1];
            }
        }  else if (directions.size() == 0) {
            vector<int> restart_point = getRestartPoint();
            if (restart_point.size() > 0) {
                x_index = restart_point[0];
                y_index = restart_point[1];
            }
        }
        directions.clear();
    }
    //ゴール地点の生成
    if (maze[xSize - 2][ySize - 2] == false) {
        maze[xSize - 2][ySize - 2] = true;
    }
}

//引数の示す方向に道を作る
vector<int> Labyrinth::digRoad(int x_index, int y_index, int digableDirection) {
    vector<int> next_point;
    for (int i = 0; i < 4; i ++) {
        next_point.push_back(x_index + directionsArray[i][0]);
        next_point.push_back(y_index + directionsArray[i][1]);
        if (i == digableDirection && JudgeEdge(next_point[0], next_point[1]) && maze[next_point[0]][next_point[1]] == false) {
            maze[next_point[0]][next_point[1]] = true;
            return next_point;
        }
        next_point.clear();
    }

    return next_point;
}

//表示関数
void Labyrinth::print() {
    //"◇" : スタート地点, "☆" : ゴール地点
    const char *wall = "■";
    const char *hole = "□";
    const char *start = "◇";
    const char *goal = "☆";
    for (int i = 0; i < xSize; i++) {
        for (int j = 0; j < ySize; j++) {
            printf("%s ", maze[i][j] == false ? (i == 0 && j == 1 ? start : (i == xSize - 1 && j == ySize - 2) ? goal : wall) : hole);
        }
        printf("\n");
    }
}

Labyrinth::~Labyrinth() { //デストラクタ
    vector<vector<bool> >().swap(maze);
}


int main() {
    Labyrinth obj(15, 15);
    obj.digMaze();
    obj.print();

    return 0;
}
anonymous No title
C++
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Script to reflect OpenCV extrinsic parameters to the object.
/// * Detail
///     The object attached this script will be translated based on the attitude of the parent object.
/// * Coordinate
///     Assume that Unity coordinate and OpenCV coordinate share X / Z axises (Y axis is inversed).
///     
/// OpenCVとUnity場の座標軸が反転しているから
/// Y軸を反転させる OpenCV(1,2,3)→Unity(1,-2,3)であるとする
/// 外部パラメータを対応させる

public class OpenCVTranslate : MonoBehaviour
{
    // OpenCVでは回転ベクトル=外部パラメータの行列は、
    // 変換後→前の座標系への右回転を表したもの
    // いまは、カメラの位置を対応させるため、変換前→後の行列が欲しい・・・左回転すると考える
    // Unityでは左回転が正方向であるから、+vベクトル分だけ回転させればいい

    public float RotationX;
    public float RotationY;
    public float RotationZ;

    public float TranslationX;
    public float TranslationY;
    public float TranslationZ;

    void Start()
    {
        
    }

    void Update()
    {
        // 外部パラメータの回転成分に関わる話
        //var rod = new Vector3(RotationX, RotationY, -RotationZ); //先生のコード出力する時点でマイナスになっているかも だからUnity上で反転させないOpenCVでの回転ベクトル(X,Y,Z)はUnity上では(X,-Y,Z)で表される
        //var rod = new Vector3(RotationX, RotationY, RotationZ); //先生のコード出力する時点でマイナスになっているかも だからUnity上で反転させないOpenCVでの回転ベクトル(X,Y,Z)はUnity上では(X,-Y,Z)で表される
        var rod = new Vector3(RotationX, -RotationY, RotationZ); //OpenCVでの回転ベクトル(X,Y,Z)はUnity上では(X,-Y,Z)で表される
        this.transform.localRotation = Quaternion.AngleAxis(rod.magnitude * 180 / Mathf.PI, rod); //回転量を定義している 後→前を前→後で座標変わって結局+で表される

        // 外部パラメータの並進移動に関わる話
        // OpenCVから取得できる並進ベクトルは、(後→前)変換後の座標系原点から変換前の座標系原点までの距離を回転後の座標系において表現したもの
        var xdir = this.transform.localRotation * Vector3.right;
        var ydir = this.transform.localRotation * Vector3.up;
        var zdir = this.transform.localRotation * Vector3.forward;
        this.transform.localPosition = xdir * TranslationX - ydir * TranslationY + zdir * TranslationZ; //並進させるのは反対の動きをするようにしてY軸は座標系がOpenCVとUnityで反対だから+に動かすことになる
        //this.transform.localPosition = -xdir * TranslationX + ydir * TranslationY - zdir * TranslationZ; //並進させるのは反対の動きをするようにしてY軸は座標系がOpenCVとUnityで反対だから+に動かすことになる

    }
}
anonymous No title
C++
cout<<"test";
anonymous No title
C++
#include "M5CoreInk.h"
#include <LovyanGFX.hpp>

Ink_Sprite InkPageSprite(&M5.M5Ink);
static LGFX_Sprite sprite;

void setup() {
  M5.begin();
  M5.M5Ink.isInit();
  M5.M5Ink.clear();
  InkPageSprite.creatSprite(0, 0, 200, 200, false);

  // スプライト作成
  sprite.setColorDepth(2);
  sprite.createPalette();
  sprite.createSprite(200, 200);
  sprite.clear(TFT_WHITE);

  // 描画テスト
  sprite.drawLine(0, 0, 199, 199, TFT_BLACK);
  pushSprite();

  delay(1000);

  // 描画テスト
  sprite.drawLine(0, 0, 199, 0, TFT_BLACK);
  pushSprite();

  delay(1000);

  // 描画テスト
  sprite.clear(TFT_WHITE);
  sprite.drawLine(0, 10, 199, 10, TFT_BLACK);
  pushSprite();
}

void loop() {
  delay(10000);
}

void pushSprite() {
  InkPageSprite.clear();
  for (int y = 0; y < 200; y++) {
    for (int x = 0; x < 200; x++) {
      uint16_t c = sprite.readPixel(x, y);
      if (c == 0x0000) {
        InkPageSprite.drawPix(x, y, 0);
      } else {
        InkPageSprite.drawPix(x, y, 1);
      }
    }
  }
  InkPageSprite.pushSprite();
}
NinoX No title
C++
import notification , clipboard , keyboard , datetime
import tweepy
import base64 , json
import time , glob
import os , sys , re
import random , console , sound

# ルーム番号
roomid = "2881" 
# パスツイ分
passtime = "29"

username = clipboard.get()
password  = ""
path1 = "/"
path2 = ".pa"
times = str(datetime.datetime.now())
file = glob.glob("*.pa")

def tweet_trim(tweet):
#tweet = tweet_filter(tweet)
    itemlist = itemlist1 = ["@[a-zA-Z0-9_]+",
             "[0-9]{1,2}:[0-5][0-9]",
             "[0-9]{1,2}時[0-59]分",
             "([0-9]|[0-2][0-9])時",
             "[0-5][0-9]分",
             "[1-9]{1,2}/[0-9]{1,2}",
             "[0-9]{1,2}月([1-3][0-9]|[0-9])日",]
    for i in itemlist:
        tweet = re.sub(i,"",tweet)
    tweet = tweet.replace(" ","")
    tweet = tweet.replace(" ","")
    tweet = re.findall(r"\d+",tweet)
    return tweet

text1 = "⓪①②③④⑤⑥⑦⑧⑨"
text2 = "⓿❶❷❸❹❺❻❼❽❾"
text3 = "0123456789"
text4 = "0123456789"
text5 = "𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡"

consumerkey = "qXB67caV4OujUrfqqSMQYZlFV"
consumersecret = "DpaGn0iawPjylujhj4VFxheA8aO578Ik080KDs3vZyHO0PdslY"
accesstoken = "1239524723035230208-oMi7WkXjHUvQm0qZDMD86fwEftVoL2"
accesstokensecret = "RpQFgDrjnV7aL8Q89cfN7HidEi4WIm401EKi1BuSsUXGl"

Auth = tweepy.OAuthHandler(consumerkey,consumersecret)
Auth.set_access_token(accesstoken,accesstokensecret)
Api = tweepy.API(Auth)

now   = datetime.datetime.now()
minute = now.minute

if("/" in str(username)):
    username = username.split("/")
    username = username[3].split("?")
    username = username[0]
else:
    print("tweetする方のプロフィールコピーしてください")
    sys.exit()

for a in range(400):  
    for i in range(400) :
        for i, status in enumerate(tweepy.Cursor(Api.user_timeline,id=username,tweet_mode="extended").items(1)):
            tweet = status.full_text
            tweettime = status.created_at
        start = time.time()
        a = 0
        for i in text1:
            if(i in tweet):
              tweet = tweet.replace(i,text3[a])
            a = a + 1
        a = 0
        for i in text2:
            if(i in tweet):
                tweet = tweet.replace(i,text3[a])
            a = a + 1
        a = 0
        for i in text4:
            if(i in tweet):
                tweet = tweet.replace(i,text3[a])
            a = a + 1
        a = 0
        for i in text5:
            if(i in tweet):
                tweet = tweet.replace(i,text3[a])
            a = a + 1

        tweet = tweet_trim(tweet)
        tweettime = re.findall(r"\d+",str(tweettime))
        count = len(tweet)

        if(passtime in tweettime):
            print("Passward!")
        else:
            print("Loading...[{0}]".format(datetime.datetime.now()))
            time.sleep(0.000000000000000000000000000000000000000000000000000000001)
            break

        if(len(tweet) == 0):
             print("I can not find the password.")
             sys.exit()
        if(roomid in tweet and len(tweet) >= 2):
            room_id_index = tweet.index(roomid)
            if(room_id_index == 0):
                password = str(tweet[1])
                keyboard.insert_text(password)
                keyboard.insert_text("\n")
                sound.play_effect("digital:PhaserDown3",volume = 100 )
                print("Password:"+password)
                e = time.time() - start
                print(e)
                sys.exit()
            elif(room_id_index == 1):
                password = str(tweet[0])
                keyboard.insert_text(password)
                keyboard.insert_text("\n")
                sound.play_effect("digital:PhaserDown3",volume = 100 )
                print("Password:"+password)
                e = time.time() - start
                print(e)
                sys.exit()
        elif(len(tweet) >= 1):
            password = str(tweet[0])
            keyboard.insert_text(password)
            keyboard.insert_text("\n")
            sound.play_effect("digital:PhaserDown3",volume = 100 )
            print("Password:"+password)
            e = time.time() - start
            print(e)
            sys.exit()
        else:
            password = tweet[0]
            keyboard.insert_text(password)
            keyboard.insert_text("\n")
            print("Password:"+password)
            sound.play_effect("digital:PhaserDown3",volume = 100 )
            e = time.time() - start
            print(e)
            sys.exit()
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);
}

//自然対数01
int main() {
	double s, i;
	s = 0;

	for (i = 0; i <= 20; i++) {
		s += 1 / fact(i);
	}

	printf("%lf",s);
}

//自然対数02
int main() {
	double s, p, i;
	s = 1 , p = 1;

	for (i = 1; i <= 20; i++) {
		p = p / i;
		s += p;
	}

	printf("%lf",s);
}

//組み合わせ01
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);
}
りゅうちゃん@hパラメータ 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の乱数--
	srand(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;
}
りゅうちゃん@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);
}
Don't you submit code?
Submit