2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

電脳少女プログラミング2008【一番通りの繁華街】Cで解いてみた

Last updated at Posted at 2025-02-11

paizaさんの、電脳少女プログラミング2088、楽しく解いてます。
レイミ可愛いし、検証中画面もかっこいい。
問題によってC言語で解いたりPythonで解いたりしてますが、
解いてみた投稿でC言語が少ない印象だったので、Cで書いたものを載せてみます。
リンクはこちら 電脳少女プログラミング2088

ichiban.c
#include <stdio.h>
#include <string.h>
int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ!!
    int n;
    int i,j,k;
    int count = 0; //正方形の数
    int sidelen; //辺の長さ
    char str[1000];
    fgets(str, sizeof(str), stdin);
    sscanf(str,"%d", &n);
    //マップを読み込む
    char map[n][n+1];
    memset( map, 0x00, sizeof(map));
    for( i=0; i<n; i++) {
        fgets( str, sizeof(str), stdin);
        sscanf( str, "%s", map[i]);
    }
    //正方形を探す
    for( i=0; i<n; i++) {
        for( j=0; j<n; j++) {
            if( map[i][j] == '.') { //アジトを見つけた
                for( k=j+1; k<n; k++) {
                    if( map[i][k] == '.') { //もうひとつ見つけたので、正方形になる位置にほかのアジトがあるか確認していく
                        sidelen = k-j;
                        if ( i+sidelen<n && map[i+sidelen][j] == '.' && map[i+sidelen][k] == '.') {
                            //正方形を見つけた
                            count++;
                        }
                    }
                }
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

お姉さんなレイミからは、
ちょっとした工夫でもっと効率的になるかもしれない
例えば二重ループの構造を見直してみるのはどうか
って言われました。

島根弁のレイミからはこんな感じ。
2025-02-11.png

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?