杭电oj2031、2033、2070、2071、2075、2089、2090、2092、2096-2099

2031  进制转换

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 int main(){
 5     int n,i,r,x,j,flag;
 6     int s[1000];
 7     while(scanf("%d %d",&n,&r)!=EOF){
 8         flag = 0;
 9         if(n<0){flag=-1;n=-n;}
10         i = 0;
11         while(n>0){
12             x = n%r;
13             s[i] = x;
14             i++;
15             n = n/r;
16         }
17         if(flag==-1){
18             printf("-");
19         }
20         for(j=i-1;j>=0;j--){
21             if(s[j]==10){printf("A");}
22             else if(s[j]==11){printf("B");}
23             else if(s[j]==12){printf("C");}
24             else if(s[j]==13){printf("D");}
25             else if(s[j]==14){printf("E");}
26             else if(s[j]==15){printf("F");}
27             else{printf("%d",s[j]);}
28         }
29         printf("\n");
30     }
31 }

 

2033  人见人爱A+B

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 int main(){
 5     int n,AH,AM,AS,BH,BM,BS,SUMH,SUMM,SUMS;
 6     while(scanf("%d",&n)!=EOF){
 7         while(n--){
 8             scanf("%d %d %d %d %d %d",&AH,&AM,&AS,&BH,&BM,&BS);
 9             SUMS = AS + BS;
10             SUMM = AM + BM;
11             SUMH = AH + BH;
12             if(SUMS>=60){SUMM++;SUMS -= 60;}
13             if(SUMM>=60){SUMH++;SUMM -= 60;}
14             printf("%d %d %d\n",SUMH,SUMM,SUMS);
15         }
16     }
17 
18 }

 

2070  Fibbonacci Number

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

 

2071  Max Num

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 int main(){
 5     int n,m,i;
 6     double h[110];
 7     while(scanf("%d",&n)!=EOF){
 8         while(n--){
 9             scanf("%d",&m);
10             for(i=1;i<=m;i++){
11                 scanf("%lf",&h[i]);
12             }
13             h[0] = 0;
14             for(i=1;i<=m;i++){
15                 if(h[0]<h[i]){
16                     h[0]=h[i];
17                 }
18             }
19             printf("%.2lf\n",h[0]);
20             
21         }
22     }
23 }

 

2075  A|B?

 1 #include<stdio.h>
 2 
 3 int main(){
 4     _int64 a,b;
 5     int n;
 6     while(scanf("%d",&n)!=EOF){
 7         while(n--){
 8             scanf("%I64d %I64d",&a,&b);
 9             if(a%b==0){printf("YES\n");}
10             else{printf("NO\n");}
11         }
12     }
13 }

 

2089  不要62

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 
 5 int s[1000000];
 6 int main(){
 7     int n,m,i,count;
 8     char stri[10];
 9     for(i=0;i<=1000000;i++){
10             itoa(i,stri,10);
11             if(strstr(stri,"4")==NULL && strstr(stri,"62")==NULL){s[i]=1;}
12             else{s[i]=0;}
13         }
14     while(scanf("%d %d",&n,&m)!=EOF){
15         if(n==0&&m==0){break;}
16         count = 0;
17         
18         for(i=n;i<=m;i++){count += s[i];}
19         printf("%d\n",count);
20     }
21     
22 }

这里有点坑,首先先要生成100000个数据的数组,提前判断是否是不吉利数,再输入后就直接查询,不然就会Time Limit Exceeded。

 

2090  算菜价

 1 #include<stdio.h>
 2 
 3 
 4 int main(){
 5     double n,p,sum=0;
 6     char s[1000];
 7     while(scanf("%s %lf %lf",&s,&n,&p)!=EOF){
 8 
 9         sum += n*p;
10     }
11     printf("%.1lf\n",sum);
12 }

 

2092  整数解

 1 #include<stdio.h>
 2 
 3 
 4 int main(){
 5     int n,m,a,k,flag;
 6     while(scanf("%d %d",&n,&m)!=EOF){
 7         flag=0;
 8         if(n==0&&m==0){break;}
 9         if(m==0){printf("Yes\n");}
10         if(m<0){k=-m;}else{k=m;}
11         for(a=1;a<=k/2;a++){
12             if(m%a==0 && (a+m/a==n || (-a)+m/(-a)==n)){printf("Yes\n");flag=1;break;}
13         }
14         if(flag==0){printf("No\n");}
15     }
16 }

 

2096  小明A+B

 1 #include<stdio.h>
 2 
 3 int main(){
 4     int n,a,b,sum;
 5     while(scanf("%d",&n)!=EOF){
 6         while(n--){
 7             scanf("%d %d",&a,&b);
 8             sum = a%100+b%100;
 9             if(sum>99){sum %= 100;}
10             printf("%d\n",sum);
11         }
12     }
13 }

 

2097  Sky数

 1 #include<stdio.h>
 2 
 3 int hex(int n){
 4     int sum=0;
 5     while(n>15){
 6         sum = sum + n%16;
 7         n /= 16;
 8     }
 9     sum = sum + n;
10     return sum;
11 }
12 
13 int dms(int n){
14     int sum=0;
15     while(n>11){
16         sum = sum + n%12;
17         n /= 12;
18     }
19     sum = sum + n;
20     return sum;
21 }
22 
23 int main(){
24     int n,a,b,c,d,sum,sum1,sum2;
25     while(~scanf("%d",&n)){
26         if(n==0){break;}
27         a = n%10;
28         b = n/10%10;
29         c = n/100%10;
30         d = n/1000;
31         sum = a+b+c+d;
32         sum1 = hex(n);
33         sum2 = dms(n);
34         if(sum==sum1 && sum==sum2){printf("%d is a Sky Number.\n",n);}
35         else{printf("%d is not a Sky Number.\n",n);}
36     }
37 }

 

2098  分拆素数和

 1 #include<stdio.h>
 2 #include<math.h>
 3 
 4 int ispn(int n){
 5     int i,flag=0;
 6     for(i=2;i<=n/2;i++){
 7         if(n%i==0){flag=1;break;}
 8     }
 9     return flag;
10 }
11 
12 int main(){
13     int n,i,count;
14     while(~scanf("%d",&n)){
15         if(n==0){break;}
16         count = 0;
17         for(i=2;i<n/2;i++){
18             if(ispn(i)==0 && ispn(n-i)==0){count++;}
19         }
20         printf("%d\n",count);
21     }
22 }

 

2099  整除的尾数

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 
 5 
 6 int main(){
 7     int a,b,i,j,len,k;
 8     char s[100][10],str[10];
 9     while(~scanf("%d %d",&a,&b)){
10         if(a==0&&b==0){break;}
11         j=0;
12         for(i=a*100;i<=a*100+99;i++){
13             if(i%b==0){
14                 itoa(i,str,10);
15                 strcpy(s[j],str);
16                 j++;
17             }
18         }
19         for(i=0;i<j;i++){
20             k = atoi(s[i]);
21             if(i==j-1){
22                 if(k%100<10){printf("0%d\n",k%100);}
23                 else{printf("%d\n",k%100);}
24             }else{
25                 if(k%100<10){printf("0%d ",k%100);}
26                 else{printf("%d ",k%100);}
27             }
28         }
29     }
30 }

 

posted @ 2019-03-02 23:55  Ragd0ll  阅读(359)  评论(0编辑  收藏