48(2023.12.15)c语言pta

48(2023.12.15)c语言pta_第1张图片

#define _CRT_SECURE_NO_WARNINGS 1
#include 
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int arr[100] = { 0 };
	for (int i = 0;i < n;i++)
	{
		arr[i] = i + 1;
	}
	int start = -1;
	int fx = 1;
	int test = 0;
	for (int i = 0;i < n-k+1;i++)
	{
		for (int j = 0;j < k;j++)
		{
			test = 0;
			while (test == 0)
			{
				if (fx == 1 && start == n - 1)
				{
					fx = 2;
					j = 0;
					test = arr[start];
				}
				else if (fx == 2 && start == 0)
				{
					fx = 1;
					j = 0;
					test = arr[start];
				}
				else if (fx == 1)
				{
					start++;
					test = arr[start];
				}
				else if (fx == 2)
				{
					start--;
					test = arr[start];
				}	
			}
		}
		printf("%d\n", arr[start]);
		arr[start] = 0;
	}
	return 0;
}

48(2023.12.15)c语言pta_第2张图片 

#include 
int main()
{
	long long score;
	int result = -1;
	for (int i = 0;i < 10;i++)
	{
		score = -1;
		while (score > 100 || score < 0)
		{
			scanf("%lld", &score);
			
		}
		if (score >= result)
		{
			result = score;
		}
	}
	printf("%d", result);
	return 0;
}

 48(2023.12.15)c语言pta_第3张图片

#define _CRT_SECURE_NO_WARNINGS 1
#include 
int main()
{
	long long score;
	int result = -1;
	int times = 1;
	for (int i = 0;i < 10;i++)
	{
		score = -1;
		while (score > 100 || score < 0)
		{
			scanf("%lld", &score);
			
		}
		if (score > result)
		{
			result = score;
			times = 1;
		}
		else if (score == result)
		{
			times++;
		}
	}
	for (int i = 0;i < times;i++)
	{
		printf("%d\n", result);
	}
	return 0;
}

 48(2023.12.15)c语言pta_第4张图片

#define _CRT_SECURE_NO_WARNINGS 1
#include 
int main()
{
	long long score;
	int max=-1;
	int min=101;
	float sum;
	for (int i = 0;i < 10;i++)
	{
		score = -1;
		while (score > 100 || score < 0)
		{
			scanf("%lld", &score);
		}
		if (score > max)max = score;
		if (score < min)min = score;
		sum += score;
	}
	sum -= max;
	sum -= min;
	sum /= 8;
	printf("%d\n", min);
	printf("%d\n", max);
	printf("%.1f\n", sum);
	return 0;
}

 48(2023.12.15)c语言pta_第5张图片

#define _CRT_SECURE_NO_WARNINGS 1
#include 
int main()
{
	int a=1, b=1;
	int times = 0;
	int arr[1000] = { 0 };
	int n = 0;
	while (a!=0||b!=0)
	{
		times = 0;
		scanf("%d%d", &a, &b);
		if (a == 0 && b == 0)break;
		int a1, a2, a3, b1, b2, b3;
		a1 = a / 100;
		a2 = (a / 10)-a1*10;
		a3 = a % 10;
		b1 = b / 100;
		b2 = (b / 10)-b1*10;
		b3 = b % 10;
		if (a3 + b3 >= 10)
		{
			times++;
			a2++;
		}
		if (a2 + b2 >= 10)
		{
			times++;
			a1++;
		}
		if (a1 + b1 >= 10)
		{
			times++;
		}
		arr[n] = times;
		n++;
	}
	for (int i = 0;i < n;i++)
	{
		printf("%d\n", arr[i]);
	}
	return 0;
}

 48(2023.12.15)c语言pta_第6张图片

#define _CRT_SECURE_NO_WARNINGS 1
#include 
int main()
{
	int n;
	scanf("%d", &n);
	int number1;
	int number;
	double d1, d2,d3;
	double d6, d4, d5;
	int arr[100] = { 0 };
	for (int i = 0;i < n;i++)
	{
		scanf("%d", &number1);
		arr[i] = number1;
	}
	for (int i = 0;i < n;i++)
	{
		number = arr[i];
		//if (1.0 / number == (1.0 / (number + 1)) + (1.0 / (number * (number * (number + 1)))))printf("yes");
		for (int j = (number +1);j <= (2 * number);j++)
		{
			for (int z = (number * (number + 1));z >= (2 * number);z--)
			{
				d1 = 1.0 * (j + z) / (j * z);
				d3 = 1.0 / number;
				if ((d3) == (d1))
				{
					printf("1/%d=1/%d+1/%d\n", number, z, j);
				}
			}
		}
	}
	return 0;
}

48(2023.12.15)c语言pta_第7张图片 

 

 

你可能感兴趣的:(算法,数据结构)