0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

リバーシの操作(斜め)

Posted at

https://paiza.jp/works/mondai/a_rank_level_up_problems/a_rank_pincerattack_step4
変なところで詰まった。

「置いた後の斜めにひっくり返す処理」で混乱してしまったのだ。

import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        int h, w, y, x;
        String[][] map;

        Scanner sc = new Scanner(System.in);

        h = sc.nextInt();
        w = sc.nextInt();
        y = sc.nextInt();
        x = sc.nextInt();

        map = new String[h][w];

        for(int i=0; i<h; i++){
            String temp = sc.next();
            for(int j=0; j<w; j++){
                map[i][j] = String.valueOf(temp.charAt(j));
            }
        }
        //_____ここまで初期化______
        
        for(int i=-1; i <= 1; i+=2){
            for(int j=1; ; j++){
                
                if(x+(i*j) == -1 || x+(i*j) == w || y+(i*j) == -1 || y+(i*j) == h){
                    break;
                }
                
                if(map[y+(i*j)][x+(i*j)] == "*"){
                    for(int k=) //うーん?
                }
            }
        }
        
        map[y][x] = "*";
        
        //_____ここから表示_______
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                System.out.print(map[i][j]);
            }
            System.out.println("");
        }
    }
}

お手本だとこう。

            if(S[Y-(i*j)][X+(i*j)] == '*'){
                for(int k = min(X+i*j,X); k <= max(X+i*j,X); k++){   //maxとmin...
                    S[Y+X-k][k] = '*';
                }
                break;
            }

C++だとmaxとminが使えるらしいが、C++をよく知らない。
頭回ってないので備忘録としておいておく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?