結果

問題 No.987 N×Mマス計算(基本)
ユーザー giru_yukikogiru_yukiko
提出日時 2020-02-15 20:26:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,483 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 75,512 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 03:16:55
合計ジャッジ時間 1,464 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

using namespace std; 

void swap(int *a, int *b){
	*b=*a-*b;
	*a-=*b;
	*b+=*a;
}

int sosu_judge(int N){
	/*素数ならば1
	  素数でなければ0を返す
	*/
	int i,j;

	if(N==2)   return 1;
	if(N%2==0) return 0;

	for(i=3;i<N && N%i!=0;i+=2);

	if(i>=N) return 1;
	
	return 0;
}

int factorial(int N){  //Nの階乗を求める関数
	int ans=1;

	while(N--) ans*=(N+1);
	return ans;
}

void q_sort(int a[], int first, int last){
    int i,j;
    int x,t;

    x = a[(first + last) / 2];
    i = first; j=last;

    while(1){
        while( a[i] < x) i++;
        while( x < a[j]) j--;
        
        if( i >= j) break;
        
        swap(&a[i],&a[j]);
        i++; j--;
    }
    if(first < i-1) q_sort(a, first,i-1 );
    if(last > j+1)  q_sort(a, j+1,  last);
}

int main(){
    int N,M;
    long A[100],B[100];
    long C[100][100];
    char mark;
    int i,j;

    cin>>N>>M;

    cin>>mark;
    for(i=0;i<M;i++) cin>>B[i];
    for(i=0;i<N;i++) cin>>A[i];

    if(mark=='+'){
        for(i=0;i<N;i++){
            for(j=0;j<M;j++){
                C[i][j]=A[i]+B[j];
            }
        }
    }
    if(mark=='*'){
        for(i=0;i<N;i++){
            for(j=0;j<M;j++){
                C[i][j]=A[i]*B[j];
            }
        }
    }
    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
            cout<<C[i][j]<<" ";
        }
        cout<<"\n";
    }
    return 0;
}


0