【Rust】英単語帳プログラム

コンソールで動作します
データは↓にあります
drive.google.com


Cargo.toml

[dependencies]
rand = "0.8"

main.rs

use std::fs::File;
use std::io::{self,Write,BufRead};
use std::path::Path;
use rand::seq::SliceRandom;
use rand::thread_rng;
fn main() -> io::Result<()> {
    let path = Path::new("高校英語.csv");
    let file = File::open(&path)?;
    let reader = io::BufReader::new(file);
    let mut matrix: Vec<Vec<String>> = Vec::new();
    for line in reader.lines() {
        let line = line?;
        let parts:Vec<&str>=line.split(',').collect();
        matrix.push(vec![parts[0].to_string(),parts[1].to_string(),parts[2].to_string(),parts[3].to_string(),parts[4].to_string()]);
    }
    let rowmax=matrix.len();
    matrix.shuffle(&mut thread_rng());
    let mut row=0;
    loop{
        if rowmax == row {
            println!("全て表示しました 終了します");
            break;
        }
        let mut input = String::new();
        println!("-------------------------------");
        println!("Word:{}",matrix[row][2].to_string());
        println!("-------------------------------");
        print!("終了するには何らかの文字を入力:");
        io::stdout().flush().unwrap();
        io::stdin().read_line(&mut input).expect("Failed to read line");
        if input.trim_end() != "" {
            println!("{}",input);
            println!("終了します");
            break;
        }
        println!("Rank:{}",matrix[row][0].to_string());
        println!("品詞:{}",matrix[row][1].to_string());
        println!("発音:{}",matrix[row][3].to_string());
        println!("意味:{}",matrix[row][4].to_string());
        row+=1;
    }
    Ok(())
}

【Python】宇宙の星の中を進むように見えるプログラム

ChatGPTを利用したものを修正して作成しました
turtleモジュールを使用しています
未インストールの場合はpipなどでインストールする必要があります

SpaceInStars
import turtle
import random
import time
import math

# 画面の設定
win = turtle.Screen()
win.setup(width=800, height=600)
win.bgcolor('black')  # 背景色を黒に設定
win.tracer(0)  # 描画速度を最大にする

# 星の設定
stars = []
stars2 = []
stars3 = []

for _ in range(30):  # 星の数を倍に増やす
    star = turtle.Turtle()
    star.shape('circle')
    star.shapesize(0.0033, 0.0033)  # 星の初期の大きさをさらに小さく(1/30)にする
    star.color(random.uniform(0.5, 1), random.uniform(0.5, 1), random.uniform(0.5, 1))  # 星の色をランダムに設定(明るい色にする)
    star.penup()
    star.speed(0)
    star.goto(0, 0)
    star.setheading(random.randint(0, 360))  # 星の初期方向をランダムに設定
    star.speed = 1  # 星の初期速度を設定
    star.growth_rate = random.uniform(0.01, 0.02)  # 星が大きくなる度合いをランダムに設定
    stars.append(star)
for _ in range(50):  # 星の数を倍に増やす
    star2 = turtle.Turtle()
    star2.shape('circle')
    star2.shapesize(0.00033, 0.00033)  # 星の初期の大きさをさらに小さく(1/30)にする
    star2.color(random.uniform(0.5, 1), random.uniform(0.5, 1), random.uniform(0.5, 1))  # 星の色をランダムに設定(明るい色にする)
    star2.penup()
    star2.speed(0)
    star2.goto(0, 0)
    star2.setheading(random.randint(0, 360))  # 星の初期方向をランダムに設定
    star2.speed = 1  # 星の初期速度を設定
    star2.growth_rate = random.uniform(0.001, 0.008)  # 星が大きくなる度合いをランダムに設定
    stars2.append(star2)
for _ in range(100):  # 星の数を倍に増やす
    star3 = turtle.Turtle()
    star3.shape('circle')
    star3.shapesize(0.00033, 0.00033)  # 星の初期の大きさをさらに小さく(1/30)にする
    star3.color(random.uniform(0.5, 1), random.uniform(0.5, 1), random.uniform(0.5, 1))  # 星の色をランダムに設定(明るい色にする)
    star3.penup()
    star3.speed(0)
    star3.goto(0, 0)
    star3.setheading(random.randint(0, 360))  # 星の初期方向をランダムに設定
    star3.speed = 1  # 星の初期速度を設定
    star3.growth_rate = random.uniform(0.001, 0.002)  # 星が大きくなる度合いをランダムに設定
    stars3.append(star3)

# 星を動かす
i = 0
while True:
    if i < len(stars):
        stars[i].showturtle()  # 星を逐次表示
        i += 1
    for star in stars:
        if star.isvisible():  # 星が表示されている場合のみ動かす
            star.forward(star.speed * 2)  # 星が移動する速度を2倍に上げる
            star.speed += 0.2  # 星の速度を徐々に上げる(加速度を2倍にする)
            distance = math.sqrt(star.xcor()**2 + star.ycor()**2)  # 星と中心との距離を計算
            star.shapesize(0.0033 + distance * star.growth_rate / 20)  # 星の大きさを距離に応じて調整(端に達する時の大きさを1/30にする)
            if star.xcor() > 400 or star.xcor() < -400 or star.ycor() > 300 or star.ycor() < -300:
                star.goto(0, 0)  # 星が端に達したとき、星を中心に戻す
                star.speed = 1  # 星が中心に戻ったとき、速度を初期速度にリセット
                star.shapesize(0.0033, 0.0033)  # 星が中心に戻ったとき、星の大きさをリセット
                star.setheading(random.randint(0, 360))  # 星の初期方向をランダムに設定
    if i < len(stars2):
        stars2[i].showturtle()  # 星を逐次表示
        i += 1
    for star2 in stars2:
        if star2.isvisible():  # 星が表示されている場合のみ動かす
            star2.forward(star2.speed * 1)  # 星が移動する速度
            star2.speed += 0.2  # 星の速度を徐々に上げる(加速度を2倍にする)
            distance = math.sqrt(star2.xcor()**2 + star2.ycor()**2)  # 星と中心との距離を計算
            star2.shapesize(0.0033 + distance * star2.growth_rate / 30)  # 星の大きさを距離に応じて調整(端に達する時の大きさを1/30にする)
            if star2.xcor() > 400 or star2.xcor() < -400 or star2.ycor() > 300 or star2.ycor() < -300:
                star2.goto(0, 0)  # 星が端に達したとき、星を中心に戻す
                star2.speed = 1  # 星が中心に戻ったとき、速度を初期速度にリセット
                star2.shapesize(0.0033, 0.0033)  # 星が中心に戻ったとき、星の大きさをリセット
                star2.setheading(random.randint(0, 360))  # 星の初期方向をランダムに設定
    if i < len(stars3):
        stars3[i].showturtle()  # 星を逐次表示
        i += 1
    for star3 in stars3:
        if star3.isvisible():  # 星が表示されている場合のみ動かす
            star3.forward(star3.speed * 0.5)  # 星が移動する速度を0.5倍に上げる
            star3.speed += 0.2  # 星の速度を徐々に上げる(加速度を2倍にする)
            distance = math.sqrt(star3.xcor()**2 + star3.ycor()**2)  # 星と中心との距離を計算
            star3.shapesize(0.0033 + distance * star3.growth_rate / 50)  # 星の大きさを距離に応じて調整(端に達する時の大きさを1/30にする)
            if star3.xcor() > 400 or star3.xcor() < -400 or star3.ycor() > 300 or star3.ycor() < -300:
                star3.goto(0, 0)  # 星が端に達したとき、星を中心に戻す
                star3.speed = 1  # 星が中心に戻ったとき、速度を初期速度にリセット
                star3.shapesize(0.0033, 0.0033)  # 星が中心に戻ったとき、星の大きさをリセット
                star3.setheading(random.randint(0, 360))  # 星の初期方向をランダムに設定
    win.update()  # 画面を更新
    time.sleep(0.01)

【C言語】コンソール上で五芒星を描く

このプログラムでは楕円上に五芒星を描いていますが幅と高さを同じにすれば円上に五芒星を描いているのと同じになります
コンソール上で丸に見えるようにするには高さを幅の半分にしてください

■参考Webページ
楕円を描く
https://daeudaeu.com/circle/
点/線を描画する
https://daeudaeu.com/figure/
N芒星を描く
https://qiita.com/kaityo256/items/a81a4168429bfed9c7eb


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h> //M_PI 円周率
void drawLineTwoPixels(
  unsigned char *data,
  unsigned int width,
  unsigned int height,
  unsigned int xs,
  unsigned int ys,
  unsigned int xe,
  unsigned int ye
){
  unsigned int x, y;
  unsigned char *p;
  int dx, dy;
  double rad;
  unsigned int length;
  unsigned int l;
  int sigx, sigy;
  dx = xe - xs;
  dy = ye - ys;
  length = sqrt(dx * dx + dy * dy);
  rad = atan2(dy, dx);
  for(l = 0; l < length; l++){
    x = xs + l * cos(rad);
    y = ys + l * sin(rad);
    if((x >=0 && x < width) && (y >= 0 && y < height)){
      p = data + y * width + x;
      p[0] = 2;
    }
  }
}
void drawEllipse(
  unsigned char *data,
  unsigned int width,
  unsigned int height,
  unsigned int rx,
  unsigned int ry,
  unsigned int x1,
  unsigned int y1
){
  unsigned int x, y;
  int dx, dy;
  unsigned char *p;
  for(y = 0; y < height; y++){
    for(x = 0; x < width; x++){
      dx = (int)x - (int)x1;
      dy = (int)y - (int)y1;
      if((double)(dx * dx) / (double)(rx * rx) + (double)(dy * dy) / (double)(ry * ry) <= 1){
        p = data + y * width + x;
        p[0] = 1;
      }
    }
  }
}
int main(){
    unsigned char *data;
    unsigned int width,height;
    printf("width height を入力してください ");
    scanf("%d %d",&width,&height);
    data=(unsigned char*)malloc(sizeof(unsigned char) * width * height);
    memset(data,0,width*height);
    //楕円を作る
    drawEllipse(data,width,height,(int)width/2,(int)height/2,(int)width/2,(int)height/2);
    //n芒星を作る
    unsigned int N=5;   //五芒星
    unsigned int k=2;
    unsigned int r1=width/2;
    unsigned int r2=height/2;
    double s,s1,s2,x1,y1,x2,y2;
    s=2*M_PI/N;
    for(int i=0;i<N;i++){
        s1 = ((i*k) % N)*s - 0.5*M_PI;
        s2 = s1 + s*k;
        x1 = r1*cos(s1)+width/2;
        y1 = r2*sin(s1)+height/2;
        x2 = r1*cos(s2)+width/2;
        y2 = r2*sin(s2)+height/2;
        drawLineTwoPixels(data,width,height,(int)x1,(int)y1,(int)x2,(int)y2);
    }
    unsigned int x, y;
    unsigned int cnt=0;
    for(y=0;y<height;y++){
        for(x=0;x<width;x++){
            if(data[cnt]==1){
                printf(".");
            }else if(data[cnt]==2){
                printf("*");
            }else{
                printf(" ");
            }
            cnt++;
        }
        printf("\n");
    }
    free(data);
    return 0;
}

【VBScript】数値を漢数字に変換する

数値を漢数字に変換するプログラム

Function KanSuuK(num)
    Kingaku=0 '0=漢数字 1=金額漢数字
    If Kingaku=0 Then
        saKeta=Array("","万","億","兆","京","垓","𥝱","穣","溝","澗","正","載","極","恒河沙","阿僧祇","那由他","不可思議","無量大数")
    Else
        saKeta=Array("","萬","億","兆","京","垓","𥝱","穣","溝","澗","正","載","極","恒河沙","阿僧祇","那由他","不可思議","無量大数")
    End If
    If IsNumeric(num) Then sNum=CStr(num)
    j=CInt(Len(sNum) Mod 4)
    If j>0 Then sW=KanSuuKK(Mid(sNum,1,j)) & saKeta(CInt(Fix(Len(sNum)/4)))
    For i=0 To CInt(Fix(Len(sNum)/4))
        iSuu=Mid(sNum,j+1+i*4,4)
        k=CInt(Fix(Len(sNum)/4))-i-1
        If K<0 Then k=0
        sW=sW & KanSuuKK(iSuu) & saKeta(k)
    Next
    KanSuuK=sW
End Function

Function KanSuuKK(num)
    Kingaku=0   '0=漢数字 1=金額漢数字(大字)
    Sangi=0     '0=通常 1=20=廿/30=卅/40=卌
    If Kingaku=0 Then
        saNum=Array("","一","二","三","四","五","六","七","八","九") '〇/零は対象外
        saKeta=Array("","","十","百","千")
    Else
        saNum=Array("","壱","弐","参","肆","伍","陸","漆","捌","玖")
        saKeta=Array("","","拾","陌","阡")
    End If
    If IsNumeric(num) Then sNum=CStr(num)
    If sNum="0" Then
        If Kingaku=0 Then
            KanSuuKK="〇"
            Exit Function
        Else
            KanSuuKK="零"
            Exit Function
        End If
    End If
    For i=Len(sNum) To 1 Step -1
        sW=saNum(CInt(Mid(sNum,Len(sNum)-i+1,1)))
        sSk=""
        If sW<>"" Then sSK=saKeta(i)
        If sW=saNum(2) And sSK=saKeta(2) And Sangi=1 Then
            sSW=sSW & "廿" '卄
        ElseIf sW=saNum(3) And sSk=saKeta(2) And Sangi=1 Then
            sSW=sSW & "卅" '丗
        '↓ANSI(Shift-Jis)不可
        'ElseIf sW=saNum(4) And sSk=saKeta(2) And Sangi=1 Then
        '    sSW=sSW & "卌"
        Else
            If Kingaku=0 And sW=saNum(1) Then
                sSW=sSW & sSK
                If i=1 Then sSW=sSW & sW
            Else
                If saNum(1)<>sW Then
                    If saketa(i)<>"" Then
                        sSW=sSW & sW & sSK
                    Else
                        sSW=sSW & sW
                    End If
                Else
                    sSW=sSW & sW & sSk
                End If
            End If
        End If
    Next
    KanSuuKK=sSW
End Function

WScript.Echo KanSuuK("123456789")

【C++】ガンダムネットワーク大戦 エリア確認アプリケーション

ガンダムネットワーク大戦で使えるエリア確認アプリケーションを作りました
苦労した点はウィンドウを六角形に変形させたことと半透明にすることでした
このアプリケーションは前にC#/VB.netで作ってましたがフレームワークを別途インストールしないといけないという欠点がありました
このプログラムではEXEファイル単体で動きます

■注目関数
○最前面に固定
CreateWindowEx WS_EX_TOPMOSTパラメーター
○六角形にウィンドウを加工
CreatePolygonRgn
SetWindowRgn
○ウィンドウを半透明にする
CreateWindowEx WS_EX_LAYEREDパラメーター
SetLayeredWindowAttributes
○左ドラッグでウィンドウを移動
PostMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, lParam);

#include <windows.h>
#include "resource.h"
#include <objidl.h>
#include <gdiplus.h>
#include <cmath>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")

//六角形と中心線の描画とウィンドウを六角形にする
VOID OnPaint(HWND hwnd, HDC hdc,int height, int width)
{
	//ウィンドウを六角形にする
	static POINT pt[7];
	HRGN hrgn;
	pt[0].x = width / 2 + height / 2 * -std::cos(45);
	pt[0].y = 0;
	pt[1].x = width / 2 + width / 2 * std::cos(45);
	pt[1].y = 0;
	pt[2].x = width;
	pt[2].y = height / 2;
	pt[3].x = width / 2 + width / 2 * std::cos(45);
	pt[3].y = height;
	pt[4].x = width / 2 + width / 2 * -std::cos(45);
	pt[4].y = height;
	pt[5].x = 0;
	pt[5].y = height / 2;
	pt[6].x = width / 2 + width / 2 * -std::cos(45);
	pt[6].y = 0;
	hrgn = CreatePolygonRgn(pt, 7, ALTERNATE);
	SetWindowRgn(hwnd, hrgn, TRUE);

	//枠線(六角形)と中心線の描画
	Graphics graphics(hdc);
	Pen      pen(Color(255, 125, 125, 125), 1);//Gray
	//'縦線
	graphics.DrawLine(&pen, (int)(width / 2), 0, (int)(width / 2), (int)(height));
	//'横線
	graphics.DrawLine(&pen, 0, (int)(height / 2), (int)(width), (int)(height / 2));
	//'右斜線
	graphics.DrawLine(&pen, (int)(width / 2), (int)(height / 2), (int)(width / 2 + width / 2 * -std::cos(45)), 0);
	graphics.DrawLine(&pen, (int)(width / 2), (int)(height / 2), (int)(width / 2 + width / 2 * std::cos(45)), (int)(height));
	//'左斜線
	graphics.DrawLine(&pen, (int)(width / 2), (int)(height / 2), (int)(width / 2 + width / 2 * std::cos(45)), 0);
	graphics.DrawLine(&pen, (int)(width / 2), (int)(height / 2), (int)(width / 2 + width / 2 * -std::cos(45)), (int)(height));
	//'左上線
	graphics.DrawLine(&pen, (int)(width / 2 + width / 2 * -std::cos(45)), 0, 0, (int)(height / 2));
	//'左下線
	graphics.DrawLine(&pen, 0, (int)(height / 2), (int)(width / 2 + width / 2 * -std::cos(45)), (int)(height));
	//'右上線
	graphics.DrawLine(&pen, (int)(width / 2 + width / 2 * std::cos(45)), 0, (int)(width), (int)(height / 2));
	//'右下線
	graphics.DrawLine(&pen, (int)(width / 2 + width / 2 * std::cos(45)), height, (int)(width), (int)(height / 2));
	//'上線
	graphics.DrawLine(&pen, (int)(width / 2 + width / 2 * std::cos(45)), 0, (int)(width / 2 + width / 2 * -std::cos(45)), 0);
	//'下線
	graphics.DrawLine(&pen, (int)(width / 2 + width / 2 * std::cos(45)), (int)(height-1), (int)(width / 2 + width / 2 * -std::cos(45)), (int)(height)-1);

}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
	WPARAM wParam, LPARAM lParam) {
	
	static int sw = 0;
	POINT pt;
	HMENU hmenu, hSubmenu;
	HDC hdc;
	PAINTSTRUCT ps;
	static int width = 0, height = 0;
	static int iXpos = 0, iYpos = 0;
	RECT rect;
	
	switch (message) {
	case WM_MOVE:
		iXpos = LOWORD(lParam);
		iYpos = HIWORD(lParam);
	case WM_SIZE:
		width = LOWORD(lParam);
		height = HIWORD(lParam);
		break;
	case WM_CREATE:
		SetLayeredWindowAttributes(hwnd, RGB(255, 255, 255), 120, LWA_ALPHA);
		InvalidateRect(hwnd, NULL, TRUE);
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCLOSE: //終了
			DestroyWindow(hwnd);
			break;
		case ID_R_90: //90%
			InvalidateRect(hwnd, NULL, TRUE);
			MoveWindow(hwnd, iXpos, iYpos, 778, 440, TRUE);
			break;
		case ID_R_100: //100%
			InvalidateRect(hwnd, NULL, TRUE);
			MoveWindow(hwnd, iXpos, iYpos, 867, 480, TRUE);
			break;
		case ID_R_110: //110%
			InvalidateRect(hwnd, NULL, TRUE);
			MoveWindow(hwnd, iXpos, iYpos, 955, 525, TRUE);
			break;
		case ID_R_125: //125%
			InvalidateRect(hwnd, NULL, TRUE);
			MoveWindow(hwnd, iXpos, iYpos, 1084, 600, TRUE);
			break;
		case ID_R_150: //150%
			InvalidateRect(hwnd, NULL, TRUE);
			MoveWindow(hwnd, iXpos, iYpos, 1300, 720, TRUE);
			break;
		default:
			return (DefWindowProc(hwnd, message, wParam, lParam));
		}
		break;
	case WM_RBUTTONDOWN:
		//右クリックでサブメニューを表示
		pt.x = LOWORD(lParam);
		pt.y = HIWORD(lParam);
		hmenu = LoadMenu((HINSTANCE)GetWindowLong(hwnd,-6 /*GWL_HINSTANCE*/), MAKEINTRESOURCE(IDR_MENU1));
		hSubmenu = GetSubMenu(hmenu, 0);
		ClientToScreen(hwnd, &pt);
		TrackPopupMenu(hSubmenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwnd, NULL);
		DestroyMenu(hmenu);
		break;
	case WM_LBUTTONDOWN:
		//左ドラッグでウィンドウを移動
		PostMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, lParam);
		break;
	case WM_PAINT:
		GetClientRect(hwnd, &rect);
		hdc = BeginPaint(hwnd, &ps);
		OnPaint(hwnd, hdc, rect.bottom, rect.right); //六角形と中心線の描画
		EndPaint(hwnd, &ps);
		break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
int WINAPI WinMain(
	HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow
) {
	HWND hWnd;
	LPCTSTR szclassName = TEXT("GNT_Area_Cpp");
	WNDCLASSEX wcex;

	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR           gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	ZeroMemory((LPVOID)&wcex, sizeof(WNDCLASSEX));

	//ウィンドウクラスを登録
	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = 0;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wcex.lpszMenuName = TEXT("IDR_MENU1");
	wcex.lpszClassName = szclassName;
	wcex.hIconSm = NULL;
	RegisterClassEx(&wcex);

	//ウィンドウ作成
	hWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_LAYERED, szclassName, 0, (WS_BORDER),
		CW_USEDEFAULT, CW_USEDEFAULT,
		867, 480,/*100%*/
		NULL, NULL, hInstance, NULL);
	SetWindowLong(hWnd, GWL_STYLE, 0);

	//ウィンドウ表示
	ShowWindow(hWnd, SW_SHOW);

	//メッセージループ
	MSG msg = {};
	while (GetMessage(&msg, NULL, 0, 0) == 1) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	GdiplusShutdown(gdiplusToken);
	return msg.wParam;
}

【VSCode/C++】「名前空間に"std"メンバー"cout"がありません」のインテリセンスエラー

VSCode】「名前空間に"std"メンバー"cout"がありません」のインテリセンスエラー

VSCode】「名前空間に"std"メンバー"cout"がありません」のインテリセンスエラー

このエラーは「C/C++ Configurations (c_cpp_properties.json)」の設定エラーで発生する

コンパイラパス(compilerPath)」が「C:/MinGW/bin/g++.exe」の時にこのエラーが発生した
このエラーを解消するためには「C 標準(cStandard)」を「c11」と「C++ 標準(cppStandard)」を「c++11」などに一度設定すると直る

なお、初期設定では「C 標準(cStandard)」を「c17」と「C++ 標準(cppStandard)」を「c++17」となっている

C/C++ Configurations」設定はソースペインを右クリックから「コマンドパレット」→「C/C++:構成の編集(UI)」を開き下の方にある「C 標準(cStandard)」を「c11」と「C++ 標準(cppStandard)」を「c++11」にする

【C++】宝さがしゲーム【C++11】


#include <iostream>
#include <random>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iterator>
#include <chrono>
#include <string>
enum digstate{
    stilldig,       // 0
    stilltreasure,  // 1
    dig,            // 2
    digtreasure     // 3
};
void dispgrid(std::vector<int>&grid, const std::vector<std::string>&rows){
    for(int i=0;i<100;i++){
        if(i%10==0){
            std::cout<<std::endl;
            if(i==0) std::cout<<" 0123456789"<<std::endl;
            std::cout<<rows[i/10];
        }
        switch(grid[i]){
            case digstate::stilldig:
                std::cout<<"-";break;
            case digstate::stilltreasure:
                std::cout<<"-";break;
            case digstate::dig:
                std::cout<<"〇";break;
            case digstate::digtreasure:
                std::cout<<"宝";break;
        }
    }
    std::cout<<std::endl;
}
int main(){
    std::vector<int> grid(100);     //表示グリッド
    std::vector<int> digtable(100); //掘る順番
    auto seed=std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
    std::mt19937 mt(seed);
    int treasureNumber; //宝の数
    int playstyle;      //手動か自動か
    std::fill(grid.begin(),grid.end(),0);           //gridは全てゼロ埋め
    std::iota(digtable.begin(),digtable.end(),0);   //digtableは0から99まで連番
    //宝の数を入力
    std::cout<<"宝箱の数[1-100]"<<std::endl;
    std::cin>>treasureNumber;
    if(treasureNumber<1||100<treasureNumber){
        std::cout<<"異常値が入力されました"<<std::endl;
        return EXIT_FAILURE;
    }
    // 宝の位置設定(シャッフル)
    std::shuffle(std::begin(digtable),std::end(digtable),mt);
    for(int i=0;i<treasureNumber;i++){
        grid[digtable[i]]=digstate::stilltreasure;
    }
    std::vector<int>::iterator it=digtable.begin();   //iterator
    int treasureCont=0;
    const std::vector<std::string> rows={"0","1","2","3","4","5","6","7","8","9"};
    //プレイスタイル入力
    std::cout<<"1:Auto 2:Play"<<std::endl;
    std::cin>>playstyle;
    if(playstyle==1){
        // 自動回答なので再抽選(宝箱抽選を使いまわしているので注意)
        std::shuffle(std::begin(digtable),std::end(digtable),mt);
    }else if(playstyle==2){
    }else{
        std::cout<<"異常値が入力されました"<<std::endl;
        return EXIT_FAILURE;
    }
    //グリッド表示
    dispgrid(grid,rows);
    for(;;){
        std::cout<<std::endl;
        int col,row;
        if(playstyle==1){
            //playstayle==auto
            col=*it%10;
            row=*it/10;
            ++it;
        }else{
            //playstayle==play
            std::cout<<"Input:RowNumber ColNumber"<<std::endl;
            std::cin>>row>>col;
        }
        //当たり外れ判定
        if(grid[row*10+col]==digstate::dig || grid[row*10+col]==digstate::digtreasure){
            std::cout<<"already open\n";
        }else if(grid[row*10+col]==digstate::stilldig){
            grid[row*10+col]=digstate::dig;
        }else if(grid[row*10+col]==digstate::stilltreasure){
            grid[row*10+col]=digstate::digtreasure;
            treasureCont++;
            std::cout<<"found a treasure!\n";
        }
        //グリッド表示
        dispgrid(grid,rows);
        //結果表示
        if(treasureCont==treasureNumber){
            std::cout<<std::endl<<"all treasure discovery.congratulations!";
            return EXIT_SUCCESS;  //ゲームオーバー(終了)
        }
    }
}