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.

5/6の進捗~Cの配列など~

Posted at

#multiple_total
引数aの倍数のうち,引数b以下のものの合計値を算出するメソッド

def multiple_total(a, b):
	if	a>0	and	b>=0:
		i=0
		total=0        
		while a*i <= b:
			total += a*i
			i += 1
	else:
		total = 0
	return total

#FizzBuzz
ある整数nが与えられた時条件の文字列を返すメソッド

def fizzbuzz(n):
    if n % 3 == 0 and n % 5 == 0:
	    return 'FizzBuzz'
    elif n % 3 == 0:
        return 'Fizz'
    elif n % 5 == 0:
	    return 'Buzz'
    else:
	    return str(n)#nだけにしない

#Cの配列1
公舎の入居・退去の情報を読み込み、各部屋の入居者数を出力するプログラム

#include <stdio.h>

int main()
{
    int a[100][100];
    int i,j,input;
    int n,m,b[100],sum=0;
    scanf("%d %d",&n,&m);
  
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
  
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++){
        sum=0;
        for(j=0;j<m;j++){
            sum+=a[i][j]*b[j];
        }
        printf("%d\n",sum);
    }
    return 0;
}

#Cの配列2
n 枚のカードを入力として、足りないカードを出力するプログラム

#include<stdio.h>
 
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}

#次回 Pythonのクラス
__init__(self)は,クラスが実際に使われるとき自動で呼ばれる初期化関数(コンストラクタとは__init__という名前の部分)
・引数にselfをもっていてクラスの実体そのもの表す

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?