ブルーブリッジカップのエクササイズシステムの演習

ブルーブリッジカップのエクササイズシステムの演習

  1. 01ストリング
#include<stdio.h>
int main()
{
 int a,b,c,d,e;
 for(a=0;a<2;a++)
  for(b=0;b<2;b++)
   for(c=0;c<2;c++)
    for(d=0;d<2;d++)
     for(e=0;e<2;e++)
      printf("%d%d%d%d%d\n",a,b,c,d,e);
 return 0;
}

演算結果:

  1. A + B
#include <stdio.h>
 
int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d", a+b);
    return 0;
}

  1. フィボナッチ数列
#include<iostream>
using namespace std;
int main()
{
 int n; 
 int i;
 int F[40];
 F[1]=F[2]=1;
 cin>>n;
 for(i=3;i<=n;i++)
 {
  F[i]=(F[i-1]+F[i-2])%10007;
  
 }
  cout<<F[n];
 } 

演算結果:ここに画像の説明を挿入
4.矩形領域交差

#include<stdio.h>
double max(double t1,double t2)
{
	if(t1>t2)
	return t1;
	else
	return t2;
} 
double min(double t1,double t2)
{
	if(t1<t2)
	return t1;
	else
	return t2;
}
int main()
{
	double x1,x2,x3,x4,y1,y2,y3,y4;
	double ax,by,cx,dy;//设相交的矩形的四个顶点的横纵坐标是ax,by,cx,dy;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	scanf("%lf %lf %lf %lf",&x3,&y3,&x4,&y4); 
	ax=min(max(x1,x2),max(x3,x4));
	cx=max(min(x1,x2),min(x3,x4));
	by=max(min(y1,y2),min(y3,y4));
	dy=min(max(y1,y2),max(y3,y4));
	if(ax>cx&&by<dy)//这样才能保证矩形有重叠的部分
	{
		printf("%.2f\n",(ax-cx)*(dy-by));
	}
	else
	printf("0.00");
	return 0;
} 



元の記事を16件公開 いいね1 訪問数180

おすすめ

転載: blog.csdn.net/weixin_44931542/article/details/105110158