ページ 11

競技プログラムについて 教えていただけませんか

Posted: 2016年5月20日(金) 05:43
by double-clutch.
[uri]http://judge.u-aizu.ac.jp/onlinejudge/d ... =ITP1_11_A
以上の競技プログラミングにチャレンジしたのですが、間違っているらしいのです。

visual studio 2010 で、ビルドは通って、デバックでも 下の仕様は満たしていると思うのですが、次の判定が返って来ます。

[hr]
WA: Presentation Error
提出されたプログラムは、ほぼ受理される出力を行っていますが、余計な空白や改行を行っていたり、あるいは必要な空白や改行を出力していません。
[hr]

どなたか、教えていただけないでしょうか
自分なりに考えた仕様...
► スポイラーを表示
  
*/
仕様を実装してみたものです。
► スポイラーを表示

Re: 競技プログラムについて 教えていただけませんか

Posted: 2016年5月20日(金) 07:20
by みけCAT
  • fscanfの%uはunsigned intを読み込むためのものです。unsigned char型のオブジェクトへのポインタを渡すと未定義動作になるので、やってはいけません。
  • 出力に改行文字が足りないようです。

Re: 競技プログラムについて 教えていただけませんか

Posted: 2016年5月20日(金) 07:51
by double-clutch.
みけCAT さん

教えていただき ありがとうごいます。
ご指摘の点 改めます。

ありがとうございました。

Re: 競技プログラムについて 教えていただけませんか

Posted: 2016年5月22日(日) 18:58
by double-clutch.
みけCAT さん

ご指摘いただいた点を修正しました。
が、そもそも自分の書いたcodeが間違っていたらしく... 修正しようとしたんですがうまくいかず...
仕方がないので、仕様を簡略化して投稿したら... 正解判定いただけました。

投稿したcodeは次のものです。

コード:

#include <stdio.h>

#define SIZE_MAX 101

struct dice {
int central;
int under;
int right;
int left;
int on;
int rear;
} dice_1;

char str[SIZE_MAX];

int i, j,work;

int main(void) {
    fscanf(stdin, "%d %d %d %d %d %d", &dice_1.central,
                                       &dice_1.under,
                                       &dice_1.right,
                                       &dice_1.left,
                                       &dice_1.on,
                                       &dice_1.rear);

    fscanf(stdin, "%100s", str);

    for (i = 0; str[i]; i++) {
        if (str[i] == 'W') {
            work = dice_1.rear;
            dice_1.rear = dice_1.left;
            dice_1.left = dice_1.central;
            dice_1.central = dice_1.right;
            dice_1.right = work;
        } else if (str[i] == 'E') {
            work = dice_1.rear;
            dice_1.rear = dice_1.right;
            dice_1.right = dice_1.central;
            dice_1.central = dice_1.left;
            dice_1.left = work;
        } else if (str[i] == 'N') {
            work = dice_1.rear;
            dice_1.rear = dice_1.on;
            dice_1.on = dice_1.central;
            dice_1.central = dice_1.under;
            dice_1.under = work;
        } else {
            work = dice_1.rear;
            dice_1.rear = dice_1.under;
            dice_1.under = dice_1.central;
            dice_1.central = dice_1.on;
            dice_1.on = work;
        }
    }
        
    fprintf(stdout, "%d\n", dice_1.central);
    
    return 0;
}
...操作を『左右操作』と『上下操作』に別けて、それぞれ対となる操作は実行しないように
したかったのですが... 技術が及ばず... 将来の宿題にでもしておきます。

お相手ありがとうございました。