結果

問題 No.397 NO MORE KADOMATSU
コンテスト
ユーザー Mcpu3
提出日時 2018-09-19 15:59:51
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 830 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 153 ms
コンパイル使用メモリ 38,884 KB
最終ジャッジ日時 2026-02-22 01:51:17
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int b1(int n,int *a)
{
    int s=0,t,i,j;
    for(i=0;i<n-1;++i){
        for(j=n-1;j>i;--j){
            if(a[j-1]>a[j]){
                t=a[j-1];
                a[j-1]=a[j];
                a[j]=t;
                ++s;
            }
        }
    }
    return s;
}

void b2(int n,int *a)
{
    int t,i,j;
    for(i=0;i<n-1;++i){
        for(j=n-1;j>i;--j){
            if(a[j-1]>a[j]){
                t=a[j-1];
                a[j-1]=a[j];
                a[j]=t;
                printf("%d %d\n",j-1,j);
            }
        }
    }
}

int main(void)
{
    int n,a1[100],a2[100],s=0,i,j;
    scanf("%d",&n);
    for(i=0;i<n;++i){
        scanf("%d",&a1[i]);
        a2[i]=a1[i];
    }
    printf("%d\n",b1(n,a1));
    b2(n,a2);
    fflush(0);
    return 0;
}
0