HDAC

#include<stdio.h>
int main()
{
int m,n,i,s1,s2;scanf("%d",&m);
while(m--)
{scanf("%d",&n);
for(i=3,s1=s2=1;i<=n;i++)
{s1=s1+s2;s2=s1-s2;}
printf("%d\n",s1);
}
return 0;
}


密码

#include<stdio.h>
#include<string.h>
int main()
{
 int M,i,t,a,b,c,d,sum;
 char s[60];
 while(scanf("%d",&M)!=EOF)
 {
  while(M--)
  {
   scanf("%s",s);
   t=strlen(s);
   if(t<8||t>16)
   {
    printf("NO\n");
    continue;
   }
   a=b=c=d=sum=0;
   for(i=0;s[i]!='\0';i++)
   {
    if(s[i]>='A'&&s[i]<='Z')a=1;
    else if(s[i]>='a'&&s[i]<='z')b=1;
    else if(s[i]>='0'&&s[i]<='9')c=1;
    else if(s[i]=='~'||s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$'||s[i]=='%'||s[i]=='^')d=1;
   }
   sum=a+b+c+d;
   if(sum>=3)
    printf("YES\n");
   else
    printf("NO\n");
  }
 }
 return 0;
}


/*//二进制数中1的个数 

#include<stdio.h>
main()
{ 
int N,M,t,s;
scanf("%d",&M);
while(M--)
{
scanf("%d",&N);
s=0;
while(N!=0)
{
t=N%2;
N=N/2;
if(t==1)
s++;
}
printf("%d\n",s);
}
return 0;
}*/


/*#include<stdio.h>//计算进位个数 
int main()
{
int a,b,c,s;
while(scanf("%d%d",&a,&b)!=EOF&&a!=0&&b!=0)
{
s=0;
c=a+b;
if((a/10%10+b/10%10)%10!=c/10%10)
s++;
if((a/100+b/100)%10!=c/100)
s++;
if(c/1000!=0)
s++;
printf("%d\n",s);

}
return 0;
 } 


 



一维数组排序
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[10];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}


sort(a,a+n);
for(int i=0;i<n;i++)
{
printf("%d",a[i]);
if(i!=n-1)
printf(" ");
else
printf("\n");
}
return 0;
}





1722蛋糕
#include<stdio.h>
int max(int a,int b)
{
if(a%b==0)
return b;
else
return max(b,(a%b));
}
int main()
{
int a,b,t;
while(scanf("%d%d",&a,&b)!=EOF)
{
t=max(a,b);
printf("%d\n",a+b-t);人数和减去最大公约数

}
return 0;
}


分拆素数
#include<stdio.h>
#include<math.h>
int su[1000000+11]={1,1};
int main()
{
int i,j,n;
for (int i = 2 ; i <= 1000000 ; i++)素数打表
{
if (su[i]==1)
continue;
for (int j = i*2;j<=1000000;j+=i)
su[j] = 1;
}
while(scanf("%d",&n)!=EOF&&n!=0)
{
int t=0,m;
for(i=3;i<n/2;i+=2)
{     素数一定是奇数
if(su[i]==0&&su[n-i]==0)
t++;
}
printf("%d\n",t);
}
return 0;
}


1222 Wolf and Rabbit
#include<cstdio>
int max(int a,int b)
{
if(b%a==0)
return a;
else
return max(b%a,a);
}
int main()判断两个数是否互质
{
int n,a,b;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&a,&b);
if(max(a,b)==1)
printf("NO\n");
else 
printf("YES\n");
}
return 0;
}


4548美素数
#include<cstdio>
int su[1000000+11]={1,1};
int a[1000000+11];
void su1()
{
int i,j;
for(i=2;i<=1000000;i++)
{
if(su[i]==1)
continue;
for(j=2*i;j<=1000000;j+=i)
su[j]=1;
}
}
void su2()
素数打表
{
int t,i,n;
su1();
for(i=1;i<=1000000;i++)
{
n=i;
int sum=0;
while(n)
{
sum+=n%10;
n=n/10;
}
if(su[i]==0&&su[sum]==0)
a[i]=a[i-1]+1;
else
a[i]=a[i-1];
}
a[i]=a[i-1];
}
int main()
{

int c,b,n;
scanf("%d",&n);
su2();
int k=1;
while(n--)
{
scanf("%d%d",&c,&b);
printf("Case #%d: %d\n",k++,a[b]-a[c-1]);
}
return 0;
}

时间超时#include<cstdio>美素数
int su[1000000+11]={1,1};
int f(int n)
{
	int t;
	int sum=0;
	while(n)
	{
		t=n%10;
		n=n/10;
		sum=sum+t;
	}
	return sum;
}
int main()
{
	int i,j;
	for(i=2;i<=1000000;i++)
	{
		if(su[i]==1)
		continue;
		for(j=2*i;j<=1000000;j+=i)
		su[j]=1;
	}
	int a,b,n;
	scanf("%d",&n);
	for(j=1;j<=n;j++)
	{
		scanf("%d%d",&a,&b);
		int s=0;
		for(i=a;i<=b;i++)
		{
			if(su[i]==0&&su[f(i)]==0)
			s++;
		}
		printf("Case #%d: %d\n",j,s);
		
	}
	return 0;
}
素数的判定
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
int su[1000000+11]={1,1};
int main()
{
	int a,b,i,j,k;
	for (int i = 2 ; i <= 1000000 ; i++)
	{
		if (su[i] == 1)
			continue;
		for (int j = i * 2 ; j <= 1000000 ; j += i)
			su[j] = 1;
	}
	while(scanf("%d%d",&a,&b)!=EOF&&(a!=0||b!=0))
	{
		
		for(i=a,k=0;i<=b;i++)
		{
			int t=i*i+i+41;
			if(su[t]==1)
			k++;
				
		}
		if(k==0)
		printf("OK\n");
		else
		printf("Sorry\n");
     }
	return 0;
}



/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * <h2><center>© Copyright (c) 2025 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "can.h" #include "dac.h" #include "dma.h" #include "i2c.h" #include "iwdg.h" #include "tim.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ #define ADC_BUFFER_SIZE 32 uint32_t adcBuffer[ADC_BUFFER_SIZE]; uint32_t dac1_value = 2048; uint32_t dac2_value = 1024; uint32_t tim1_pulse = 500; uint32_t tim3_ch1_pulse = 300; uint32_t tim3_ch2_pulse = 700; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_ADC2_Init(); MX_ADC3_Init(); MX_I2C1_Init(); MX_IWDG_Init(); MX_I2C2_Init(); MX_TIM1_Init(); MX_TIM3_Init(); MX_CAN1_Init(); MX_CAN2_Init(); MX_DAC_Init(); MX_TIM2_Init(); MX_TIM6_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start_IT(&htim2); uint32_t adc1_value = 0; uint32_t adc2_value = 0; uint32_t adc3_value = 0; uint32_t new_duty_cycle_1 = 0; HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); HAL_DAC_Start(&hdac,DAC1_CHANNEL_1); HAL_TIM_Base_Start(&htim6); HAL_DAC_Start(&hdac,DAC1_CHANNEL_1); HAL_DAC_Start(&hdac,DAC1_CHANNEL_2); uint32_t adc1_buffer[ADC_BUFFER_SIZE]; uint32_t adc2_buffer[ADC_BUFFER_SIZE]; uint32_t adc3_buffer[ADC_BUFFER_SIZE]; HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc1_buffer, ADC_BUFFER_SIZE); HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc2_buffer, ADC_BUFFER_SIZE); HAL_ADC_Start_DMA(&hadc3, (uint32_t*)adc3_buffer, ADC_BUFFER_SIZE); HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, dac1_value); HAL_DAC_Start(&hdac, DAC_CHANNEL_1); HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, dac2_value); HAL_DAC_Start(&hdac, DAC_CHANNEL_2); HAL_TIM_Base_Start(&htim6); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if(htim->Instance == TIM2) { float feedback = read_adc_value(); float output = pid_calculate(setpoint, feedback); __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, output); } } while (1) { dac2_value = adcBuffer[0] >> 4; HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, dac2_value); HAL_DAC_Start(&hdac, DAC_CHANNEL_2); HAL_Delay(10); } } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * <h2><center>© Copyright (c) 2025 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "can.h" #include "dac.h" #include "dma.h" #include "i2c.h" #include "iwdg.h" #include "tim.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ #define ADC_BUFFER_SIZE 32 uint32_t adcBuffer[ADC_BUFFER_SIZE]; uint32_t dac1_value = 2048; uint32_t dac2_value = 1024; uint32_t tim1_pulse = 500; uint32_t tim3_ch1_pulse = 300; uint32_t tim3_ch2_pulse = 700; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_ADC2_Init(); MX_ADC3_Init(); MX_I2C1_Init(); MX_IWDG_Init(); MX_I2C2_Init(); MX_TIM1_Init(); MX_TIM3_Init(); MX_CAN1_Init(); MX_CAN2_Init(); MX_DAC_Init(); MX_TIM2_Init(); MX_TIM6_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start_IT(&htim2); uint32_t adc1_value = 0; uint32_t adc2_value = 0; uint32_t adc3_value = 0; uint32_t new_duty_cycle_1 = 0; HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); HAL_DAC_Start(&hdac,DAC1_CHANNEL_1); HAL_TIM_Base_Start(&htim6); HAL_DAC_Start(&hdac,DAC1_CHANNEL_1); HAL_DAC_Start(&hdac,DAC1_CHANNEL_2); uint32_t adc1_buffer[ADC_BUFFER_SIZE]; uint32_t adc2_buffer[ADC_BUFFER_SIZE]; uint32_t adc3_buffer[ADC_BUFFER_SIZE]; HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc1_buffer, ADC_BUFFER_SIZE); HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc2_buffer, ADC_BUFFER_SIZE); HAL_ADC_Start_DMA(&hadc3, (uint32_t*)adc3_buffer, ADC_BUFFER_SIZE); HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, dac1_value); HAL_DAC_Start(&hdac, DAC_CHANNEL_1); HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, dac2_value); HAL_DAC_Start(&hdac, DAC_CHANNEL_2); HAL_TIM_Base_Start(&htim6); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if(htim->Instance == TIM2) { float feedback = read_adc_value(); float output = pid_calculate(setpoint, feedback); __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, output); } } while (1) { dac2_value = adcBuffer[0] >> 4; HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, dac2_value); HAL_DAC_Start(&hdac, DAC_CHANNEL_2); HAL_Delay(10); } } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ ../Src/main.c(160): error: #65: expected a ";"
07-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值