# Blue Bridge Cup exercise

## Blue Bridge Cup exercise

1. Problem description
Judge whether the given three digit number is the number of daffodils. The so-called narcissus number refers to the number whose value is equal to the sum of each number cube of itself. Example 153 is a daffodil number. 153=13+53+33

```#include<stdio.h>
int main () {
int a,b,c,d;
scanf("%d",&a);
b=a/100;
c=a/10%10;
d=a%10;
if((b*b*b+c*c*c+d*d*d)==a){
printf("YES");
}
else{
printf("NO");
}
return 0;
}

```

2. Problem description
Find the prime factor decomposition of all integers in the interval [a,b]‘
Output:
3=3
4=22
5=5
6=23
7=7
8=222
9=33
10=25

```#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b,n,i,j;
scanf("%d %d",&a,&b);

for(a;a<=b;a++)
{
printf("%d=",a);
n=a;
j=2;
while(n!=j)
{
for(j=2;j<n;j++)
{
if(n%j==0 && n!=j)
{
printf("%d*",j);
n/=j;
break;
}
}
}
printf("%d\n",n);
}
return 0;
}

```

3. Problem description
Given a time t in seconds, it is required to represent the time in the format of '". < represents the time, < > represents the minute, and represents the second. They are all integers and have no leading" O ". For example, if t=0, it should output" 0:0:0 "; if t=3661, it should output" 1:1:1 ".

```#include<stdio.h>
int main () {
int t,H,M,S;
scanf("%d",&t);
H=t/3600;
M=t%3600/60;
S=t%3600%60;
printf("%d",H);
printf(":");
printf("%d",M);
printf(":");
printf("%d",S);
return 0;
}
```

4. Problem description
Given a year, judge whether it is a leap year.
This year is a leap year when one of the following conditions is met:
1. The year is a multiple of 4 rather than a multiple of 100;
2. The year is a multiple of 400.
Other years are not leap years.

```#include <stdio.h>
int main()
{
int year;
scanf("%d",&year);
if (year%400 == 0 || year%4 == 0 && year%100 != 0){
printf("yes");
}
else{
printf("no");
}
return 0;
}
```

5. Problem description
An array of integers and an integer b are given. It is required to delete all elements in the array that can be divided by b, and sort the elements of the array from small to large. If the array element value is between ASCII A and Z, replace it with the corresponding letter. The number of elements does not exceed 100, and b is between 1 and 100.
Input format
The first line is the number of array elements and the integer b
The second line is each element of the array
Output format
Output as required
sample input
7 2
77 11 66 22 44 33 55

sample output

11 33 55 M

```#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,b,i,k;
int num[101];
char ch;
cin>>n>>b;
for(i=0;i<n;i++)
{
cin>>num[i];
}
sort(num,num+n);
for(i=0;i<n;i++)
{
if(num[i]%b==0)
{
for(k=i;k<n-1;k++)
{
num[k]=num[k+1];
}
n--;
i--;
}
}
for(i=0;i<n;i++)
{
if(num[i]>='A'&&num[i]<='Z')
{
ch=num[i]-65+'A';
cout<<ch<<" ";
}
else
cout<<num[i]<<" ";
}
cout<<endl;
return 0;
}

```

6. Problem description
Given two strings consisting only of uppercase or lowercase letters (length between 1 and 10), the relationship between them is one of the following 4 cases:
1: the two strings are not equal in length. For example, Beijing and Hebei
2: the two strings are not only equal in length, but also the characters at the corresponding positions are exactly the same (case sensitive), such as Beijing and Beijing
3: the two strings are equal in length, and the characters at the corresponding positions can be completely consistent only on the premise of not case sensitive (that is, it does not meet case 2). For example, BEIjing and BEIjing
4: the two strings are equal in length, but even if they are not case sensitive, they cannot be consistent. For example, Beijing and Nanjing
Program to judge which of the four categories the relationship between the two input strings belongs to, and give the number of the class to which it belongs.

Input format
Includes two lines, each of which is a string

Output format
There is only one number indicating the relationship number of the two strings

sample input
BEIjing
beijing
sample output
3

```#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
char s1[20],s2[20];
int main()
{
while(~scanf("%s %s",s1,s2))
{
int flag=0;
int l1=strlen(s1);
int l2=strlen(s2);
if(l1!=l2)
printf("1\n");
else//strupr changes lowercase to uppercase strlwr changes uppercase to lowercase
{
if(strcmp(s1,s2)==0)
printf("2\n");
else
{
//printf("%s %s>>>>\n",strupr(s1),strupr(s2));
if(strcmp(strupr(s1),strupr(s2))==0)
printf("3\n");
else
printf("4\n");
}
}
}
return 0;
}
```

OK, that's all for today's sharing. Give me a praise

Posted on Sat, 27 Nov 2021 23:20:25 -0500 by phpnewb999