当前位置:网站首页>2021-02-01

2021-02-01

2021-02-03 09:23:15 osc_ zken4nb1

The first week of algorithm training
Just write it out 14 Problem , There is a thinking problem that is wrong after thinking about it. Ha ha ha
A. Check the score
Topic link :https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-131
According to the reading find,insert,end To determine what needs to be done
Code :




#include<stdio.h>
#include<string.h>
struct student
{
   
   
	char name[20];
	int score;
};
int main()
{
   
   
	struct student stu[200];
	char str[10];
	char name0[20];
	int i=0;
	int j;
	int a[200];
	int k=0;
	int q;
	for(q=0;q<1000000;q++)		
	{
   
   
		scanf("%s",str);
		if(str[0]=='e')
		break;
		else if(str[0]=='i') 
		{
   
   
			scanf("%s %d",stu[i].name,&stu[i].score);
			i++;
			
		}
		else if(str[0]=='f')
		{
   
   
			int F=0;
			scanf("%s",name0);
			for(j=0;j<i;j++)
			{
   
   
				if(strcmp(name0,stu[j].name)==0)
				{
   
   
					a[k]=stu[j].score;
					F=1;
					break;
				}
				if(F==0) a[k]=-1;
				
			}
			k++;
		}
	
	}
	
	for(i=0;i<k;i++)
	{
   
   
		printf("%d\n",a[i]);
		
	}
	
	return 0;
 } 

D. Palindrome number conjecture
Topic link :
https://vjudge.net/problem/HDU-1282
Write a function to reverse the number , Very convenient , The title is not difficult. , Pay attention to the output format , Use a two-dimensional array to store the numerical process of transformation .
Code :



#include<stdio.h>
#include<math.h>
int reverse(int x)// Reverse the number  
{
   
   
	int a[100];
	int i=0;
	int j,y=0;
	while(x)
	{
   
   
		a[i]=x%10;
		x/=10;
		i++;
	}
	for(j=0;j<i;j++)
	{
   
   
		y+=a[j]*pow(10,i-j-1);
	}
	return y;
	
}
int main()
{
   
   
	int a,b;
	
	int times[10000]={
   
   0};// The record changed a few times  
	int count=0;// It's used to record a few numbers  
    int group[100][1000];
	int i,j;
	
	while(scanf("%d",&group[count][times[count]])!=EOF)
	{
   
   
		a=group[count][times[count]]; 
		while(a!=reverse(a))
		{
   
   
			times[count]++;// Change it once 
			group[count][times[count]]=a=a+reverse(a); 
			
		}
		
	
		
		count++;
	}
	//printf("count=%d\n",count);
	for(i=0;i<count;i++)
	{
   
   
		printf("%d\n",times[i]);
		for(j=0;j<=times[i];j++)
		{
   
   
			printf("%d",group[i][j]);
			if(j<times[i])
			printf("--->");
			else
			printf("\n");
		}
	}
	
	return 0;
}

F. The problem of buying chicken
Topic link :
https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-T1372
Just set up a baby , Notice also that no answer


#include<stdio.h>
int main()
{
   
   
	int a,b,c;// The number of cocks, hens and chicks 
	int i,j,k;// Loop variable 
	int n;
	int count=0;
	scanf("%d",&n);
	for(i=0;i<=n/5;i++)
	{
   
   
		for(j=0;j<=n/2;j++)
		{
   
   
			for(k=0;k<=3*n;k+=3)
			{
   
   
				if((5*i+3*j+k/3==n)&&(i+j+k==n))
				{
   
   
			
				printf("%d %d %d\n",i,j,k);
			    count=1;
				}
			}
		}
	 } 
	 if(count==0)
	 printf("No Answer.");
	 return 0;
}

H. The smallest new integer
Topic link :
https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-T1258
To delete larger numbers from the front , Try to increase the number as much as possible , This new integer will be the smallest .
Code :



#include<stdio.h>
#include<string.h>
int main()
{
   
   
	int n;//n Group data 
	char s[20];// To store a string of numbers  
	int  k;// The number of digits deleted  
	int len ,i,j;
	scanf("%d\n",&n);
	int p=0;
	char result[100][20];
	int l[100];
	int q=n;
	while(n--)
	{
   
   
		scanf("%s %d",s,&k);
		len=strlen(s);
		int b;
		b=len;
		int a;
		//, Start with the big ones , If the front one is bigger than the back one , Just delete it  , In total, delete k position , That is to say k operations  
		for(i=0;i<k;i++)
		
		{
   
    
		    for(j=0;j<len-1;j++)
		    {
   
   
		    	if(s[j]>s[j+1])
		    	{
   
   
		    		for(a=j;a<len-1;a++)
		    		{
   
    
		    	    	s[a]=s[a+1];
		    		} 
		    		len--;// Delete once ,s One less  
					break;// Cover forward , Make the next deletion  
					
				}
			}
		} 
		l[p]=b-k;
		/*printf("l[%d]=%d\n",p,l[p]);
		for(i=0;i<l[p];i++)
		{
			printf("s[%d]=%c\n",i,s[i]);
		}*/
		for(i=0;i<l[p];i++)
		{
   
   
			result[p][i]=s[i];
		//	printf("result[%d][%d]=%c\n",p,i,result[p][i]);
		}
		p++;
	}
	for(i=0;i<q;i++)
	
	{
   
   
		for(j=0;j<l[i];j++)
		{
   
   
			printf("%c",result[i][j]);
		}
		printf("\n");
	}
	return 0;
 } 

I In a hurry
Topic link :
https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-T1321
It's OK to calculate time in seconds


#include<stdio.h>
int main()
{
   
   
	char s1[20],s2[20];
	int a1,a2;
	scanf("%s %s",s1,s2);
	a1=((s1[0]-'0')*10+(s1[1]-'0'))*3600+((s1[3]-'0')*10+(s1[4]-'0'))*60+(s1[6]-'0')*10+(s1[7]-'0');
	a2=((s2[0]-'0')*10+(s2[1]-'0'))*3600+((s2[3]-'0')*10+(s2[4]-'0'))*60+(s2[6]-'0')*10+(s2[7]-'0');
	printf("%d",a1-a2);
	return 0;
}

J The heating doesn't work
Topic link :
https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-T1703#include<stdio.h>

Each time you just need to judge the part that is repeated before and after , Subtract the repetition and then sum

int main()
{
   
   
	char s1[20],s2[20];
	int a1,a2;
	scanf("%s %s",s1,s2);
	a1=((s1[0]-'0')*10+(s1[1]-'0'))*3600+((s1[3]-'0')*10+(s1[4]-'0'))*60+(s1[6]-'0')*10+(s1[7]-'0');
	a2=((s2[0]-'0')*10+(s2[1]-'0'))*3600+((s2[3]-'0')*10+(s2[4]-'0'))*60+(s2[6]-'0')*10+(s2[7]-'0');
	printf("%d",a1-a2);
	return 0;
}

L.n The arrangement of logarithms
Topic link :
https://vjudge.net/problem/HDU-2554
Looking for a regular , When n yes 4 Multiple of or 3*n-1 yes 4 Multiple of .
The process of finding regularity :



Code :

#include<stdio.h> 
int main()
{
   
   
	
	int n;
	int i=0;
	int l;
	char s[1000000];
	for(l=0;l<1000000;l++)
	{
   
   
	    scanf("%d",&n);
	    if(n==0) break;
		if((n%4==0)||((n*3-1)%4==0))
		s[i]='Y';
		else s[i]='N';
		i++;
	
	}

	int j;
	for(j=0;j<i;j++)
	{
   
   

		printf("%c\n",s[j]);
	
	
    }
	
	return 0;
}

M. The story of the cow
Topic link :
https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-T1904
It's actually the Fibonacci problem , The number of cattle in this year is equal to the number of cattle born in the previous year plus , And three years ago and before the cattle grow to this year just can have a calf , namely
F(n)=F(n-1)+F(n-3)
Code :




#include<stdio.h>
int main()
{
   
   
	int i;
	int n;
	scanf("%d",&n);
	int a[60]={
   
   0};
	a[1]=1;
	a[2]=2;
	a[3]=3;
	for(i=4;i<=n;i++)
	{
   
   
		a[i]=a[i-1]+a[i-3];
	}
	printf("%d",a[n]);
	return 0;
}

N. Infinite Road
Topic link :
https://vjudge.net/problem/HDU-2073
Calculate the distance between the coordinates and the origin , Then take the absolute value of the difference
Code :



#include<stdio.h>
#include<math.h>
double sum(int x,int y)
{
   
   
	int i;
	int s;
    double a[200];
    double f=0,l=0;
    s=x+y;
    for(i=1;i<=s;i++)
    {
   
   
    	a[i]=sqrt((i-1)*(i-1)+i*i);
    	f+=a[i];
	}
	for(i=1;i<s;i++)
	{
   
   
		l+=i;
	}
	f=f+sqrt(2)*(l+x);
	return f;
}
int main()
{
   
   
	int n;//n Group data 
	int x1,x2,y1,y2;// coordinate 
	int i,j; 
	double result[100];
	double sum1,sum2;
	scanf("%d\n",&n);
	for(i=0;i<n;i++)
	{
   
   
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		sum1=sum(x1,y1);
		sum2=sum(x2,y2);
		result[i]=fabs(sum1-sum2);
		//printf("sum1=%f sum2=%f\n",sum1,sum2);
	 } 
	 for(i=0;i<n;i++)
	 {
   
   
	 	printf("%.3f\n",result[i]);
	 }
	 
	 return 0;
}

O. Statistical vowels
Topic link :
https://vjudge.net/problem/HDU-2027
Note the output format !!!
Code :



#include<stdio.h>
#include<string.h>
struct each
{
   
   
	int num[5];
	char s[200];
};
int main()
{
   
   
	int n,i,j,len;
	
	scanf("%d\n",&n);
	struct each a[200];
	int k=n;
	for(i=0;i<n;i++) 
	{
   
   
		gets(a[i].s);
		len=strlen(a[i].s);
		
		a[i].num[0]=0;
		a[i].num[1]=0;
		a[i].num[2]=0;
		a[i].num[3]=0;
		a[i].num[4]=0;
	
		for(j=0;j<len;j++)
		{
   
   
			if(a[i].s[j]=='a')
			a[i].num[0]++;
			else if(a[i].s[j]=='e')
			a[i].num[1]++;
			else if(a[i].s[j]=='i')
			a[i].num[2]++;
			else if(a[i].s[j]=='o')
			a[i].num[3]++;
			else if(a[i].s[j]=='u')
			a[i].num[4]++;
				
		}
	
	}
	    if(k>0)
    {
   
    
		for(i=0;i<k;i++)
		{
   
   
			printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d",a[i].num[0],a[i].num[1],a[i].num[2],a[i].num[3],a[i].num[4]);
			if(i<k-1)
			printf("\n\n");
			else printf("\n");
		}

	} 
	return 0;
}

P Find the sum of sequence
Topic link :
https://vjudge.net/problem/HDU-2009
Code :


#include<stdio.h>
#include<math.h>
int main()
{
   
   
	double a[1000];
	int b;
	int i;
	double sum[10000];
	int k=0;
	
	while((scanf("%lf %d",&a[0],&b))!=EOF)
	{
   
   
		sum[k]=a[0];
		for(i=1;i<b;i++)
		{
   
   
			a[i]=sqrt(a[i-1]);
			sum[k]+=a[i];
		}
		k++;
	}
	for(i=0;i<k;i++)
	{
   
   
		printf("%.2f\n",sum[i]);
	}
	return 0;
 } 

Q Digital games
subject :https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-T3227
Code :

#include<stdio.h>
int main()
{
   
   
	char s[10];
	gets(s);
	int i;
	int count=0;
	for(i=0;i<8;i++)
	{
   
   
		if(s[i]=='1')
		count ++;
	}
	printf("%d\n",count);
	return 0;
 } 

Q Light and heavy
Topic link :https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-A2240
Code :

#include<stdio.h>
int a[500010];
int n;
// Quick line up  
void qsort(int left,int right)
{
   
   
	int i,j,t,temp;
	if(left>right)
	return;
	 temp=a[left];
	 i=left;
	 j=right;
	 while(i!=j)
	 {
   
   
	 	while(a[j]>=temp&&i<j)
	 	j--;
	 	while(a[i]<=temp&&i<j)
	 	i++;
	 	if(i<j)
	 	{
   
   
	 		t=a[i];
	 		a[i]=a[j];
	 		a[j]=t;
		 }
	 }
	 a[left]=a[i];
	 a[i]=temp;
	 qsort(left,i-1);
	 qsort(i+1,right);
	 return;
 } 
int main()
{
   
   
	int i;
	scanf("%d",&n);
	int count=n;
	for(i=0;i<n;i++)
	{
   
   
		scanf("%d",&a[i]);
	}
	// Make a sequence 
	 qsort(0,n-1);
	 int m;
	 m=n/2;
	 for(i=0;i<n/2;i++)
	 {
   
   
	 	while(a[i]*2>a[m]&&m<n)
	 	m++;
	 	if(m>=n)
	 	break;
	 	// If you find it 
		 m++;// Move backward 
		  count--;// One less ticket ; 
	 }
	 printf("%d",count);
	return 0;
}

版权声明
本文为[osc_ zken4nb1]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/02/20210203091718377a.html