杭电oj2028、2034、2035、2041、2043-2046

2028  Lowest Common Multiple Plus

 1 #include<stdio.h>
 2 
 3 int gcd(int a,int b){
 4     int temp,temp1;
 5     if(a<b){
 6         temp = a;
 7         a = b;
 8         b = temp;
 9     }
10     while(a%b!=0){
11         temp1 = a%b;
12         a = b;
13         b = temp1;
14     }
15     return b;
16 }
17 
18 int main(){
19     int n,s,i;
20     long long k;
21     while(scanf("%d",&n)!=EOF){
22         k=1;
23         for(i=0;i<n;i++){
24             scanf("%d",&s);
25             k = s*k/gcd(s,k);    
26         }
27         
28         printf("%lld\n",k);
29     }
30 }

 

2034  人见人爱A-B

#include<stdio.h>
#include<string.h>

int main(){
    int n,m,i,j,num,flag,temp,s[101],o[101],p[101];
    while(~scanf("%d %d",&n,&m)){
        if(n==0&&m==0){break;}
        for(i=0;i<n;i++){scanf("%d",&s[i]);}
        for(i=0;i<m;i++){scanf("%d",&o[i]);}
        num = 0;
        for(i=0;i<n;i++){
            flag = 0;
            for(j=0;j<m;j++){
                if(s[i]==o[j]){flag=1;break;}
            }
            if(flag==0){p[num]=s[i];num++;}
        }
        if(num==0){printf("NULL\n");continue;}
        for(i=0;i<num;i++){
            for(j=num-1;j>i;j--){
                if(p[i]>p[j]){
                    temp = p[i];
                    p[i] = p[j];
                    p[j] = temp;
                }
            }
        }
        for(i=0;i<num;i++){
            printf("%d ",p[i]);
        }
        printf("\n");

    }
}

 

2035  人见人爱A^B

 1 #include<stdio.h>
 2 
 3 int main(){
 4     int n,m,i,mul;
 5     while(scanf("%d %d",&n,&m)!=EOF){
 6         if(n==0&&m==0){break;}
 7         mul = 1;
 8         for(i=0;i<m;i++){
 9             mul = mul * n % 1000;
10         }
11         printf("%d\n",mul);
12     }
13 }

 

2041  超级楼梯

 1 #include<stdio.h>
 2 
 3 int main(){
 4     int n,m,i,s[100];
 5     while(~scanf("%d",&n)){
 6         while(n--){
 7             scanf("%d",&m);
 8             s[1]=0;s[2]=1;s[3]=2;
 9             for(i=4;i<=m;i++){
10                 s[i] = s[i-1] + s[i-2];
11             }
12             printf("%d\n",s[m]);
13         }
14     }
15 }

 

2043  密码

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 
 5 int main(){
 6     int n,len,i,j,flag1,flag2,flag3,flag4;
 7     char s[50][50];
 8     while(~scanf("%d",&n)){
 9         getchar();
10         for(i=0;i<n;i++){
11             gets(s[i]);
12             len = strlen(s[i]);
13             flag1=0;flag2=0;
14             flag3=0;flag4=0;
15             if(8>len||len>16){
16                 printf("NO\n");
17                 continue;
18             }
19             else{
20                 for(j=0;s[i][j]!='\0';j++){
21                     if(s[i][j]>='A'&&s[i][j]<='Z'){flag1 = 1;}
22                     else if(s[i][j]>='a' && s[i][j]<='z'){flag2 = 1;}
23                     else if(s[i][j]>='0' && s[i][j]<='9'){flag3 = 1;}
24                     else if(s[i][j]=='~'||s[i][j]=='!'||s[i][j]=='@'||s[i][j]=='#'||s[i][j]=='$'||s[i][j]=='%'||s[i][j]=='^'){flag4 = 1;}
25                 }
26                 if(flag1+flag2+flag3+flag4>2){printf("YES\n");}
27                 else{printf("NO\n");}
28             }
29         }
30     }
31 }

 

2044  一只小蜜蜂...

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 
 5 int main(){
 6     int n,a,b,i;
 7     _int64 s[51];
 8     while(~scanf("%d",&n)){
 9         while(n--){
10             scanf("%d %d",&a,&b);
11             s[1]=0;s[2]=1;s[3]=2;
12             for(i=4;i<=b;i++){
13                 s[i] = s[i-1] + s[i-2];
14             }
15             printf("%I64d\n",s[b-a+1]);
16         }
17         
18     }
19 }

 

2045  不容易系列之(3)—— LELE的RPG难题

 1 #include<stdio.h>
 2 
 3 
 4 int main(){
 5     int n,i;
 6     _int64 s[51];
 7     while(~scanf("%d",&n)){
 8         s[1]=3;s[2]=6;s[3]=6;
 9         for(i=4;i<=n;i++){
10             s[i] = s[i-1] + s[i-2]*2;
11         }
12         printf("%I64d\n",s[n]);
13     }
14         
15     
16 }

 

 

2046  骨牌铺方格

 1 #include<stdio.h>
 2 
 3 
 4 int main(){
 5     int n,i;
 6     _int64 s[51];
 7     while(~scanf("%d",&n)){
 8         s[1]=1;s[2]=2;
 9         for(i=3;i<=n;i++){
10             s[i] = s[i-1] + s[i-2];
11         }
12         printf("%I64d\n",s[n]);
13     }
14         
15     
16 }

 

posted @ 2019-03-08 15:48  Ragd0ll  阅读(344)  评论(0编辑  收藏