杭电oj2012-2021

2012  素数判定

 1 #include <stdio.h>
 2 #include <math.h>
 3
 4 int main()
 5 {
 6     int x,y,i,j,a,flag;
 7     while(scanf("%d %d",&x,&y)!=EOF){
 8         flag = 0;
 9         if(x==0&&y==0){break;}
10         for(i=x;i<=y;i++){
11             a = i*i+i+41;
12             for(j=2;j<a/2;j++){
13                 if(a%j==0){flag++;break;}
14             }
15             if(flag!=0){break;}
16         }
17         if(flag==0){printf("OK\n");}
18         else{printf("Sorry\n");}
19     }
20 }

2013  蟠桃记

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

2014  青年歌手大奖赛_评委会打分

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

2015  偶数求和

 1 #include <stdio.h>
 2
 3 int main(){
 4     int n,m,i,j,a,count,sum;
 5     int s[101],c[101];
 6     while(scanf("%d %d",&n,&m)!=EOF){
 7         a = 0;
 8         count = 0;
 9         for(i=1;i<=n;i++){a += 2;s[i] = a;}
10         for(i=1;i<=n;i++){
11             if(i%m==0){
12                 sum = 0;
13                 for(j=i-m+1;j<=i;j++){sum += s[j];}
14                 c[count] = sum/m;
15                 count++;
16             }
17             if(i==n&&i%m!=0){
18                 sum = 0;
19                 for(j=i-(n%m)+1;j<=i;j++){sum += s[j];}
20                 c[count] = sum/(n%m);
21                 count++;
22             }
23         }
24         for(i=0;i<count;i++){
25             if(i==count-1){printf("%d\n",c[i]);}
26             else{printf("%d ",c[i]);}
27         }
28     }
29 }

2016  数据的交换输出

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

2017  字符串统计

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

2018  母牛的故事

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

2019  数列有序!

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

2020  绝对值排序

 1 #include <stdio.h>
 2 int ab(int a){
 3     if(a<0){a=-a;}
 4     return a;
 5 }
 6
 7 int main(){
 8     int n,i,j,temp;
 9     int s[101];
10     while(scanf("%d",&n)!=EOF){
11         if(n==0){break;}
12         for(i=0;i<n;i++){scanf("%d", &s[i]);}
13         for(i=0;i<n-1;i++){
14             for(j=0;j<n-1-i;j++){
15                 if(ab(s[j]) < ab(s[j+1])){
16                     temp = s[j];
17                     s[j] = s[j+1];
18                     s[j+1] = temp;
19                 }
20             }
21         }
22         for(i=0;i<n;i++){
23             if(i==n-1){printf("%d\n",s[i]);}
24             else{printf("%d ",s[i]);}
25         }
26     }
27 }

2021  发工资咯:)

 1 #include <stdio.h>
 2
 3 int main(){
 4     int s[101];
 5     int n,i,sum,temp,count;
 6     while(scanf("%d",&n)!=EOF){
 7         if(n==0){break;}
 8         count = 0;
 9         for(i=0;i<n;i++){scanf("%d",&s[i]);}
10         for(i=0;i<n;i++){
11             sum = 0;
12             if(s[i]/100!=0){sum += s[i]/100;}
13             if((s[i]%100)/50!=0){sum += (s[i]%100)/50;}
14             if(s[i]%100%50/10!=0){sum += s[i]%100%50/10;}
15             if(s[i]%100%50%10/5!=0){sum += s[i]%100%50%10/5;}
16             if(s[i]%100%50%10%5/2!=0){sum += s[i]%100%50%10%5/2;}
17             sum += s[i]%100%50%10%5%2;
18             count += sum;
19         }
20         printf("%d\n",count);
21     }
22 }

原文地址:https://www.cnblogs.com/Ragd0ll/p/10419583.html

时间: 2024-11-17 21:26:26

杭电oj2012-2021的相关文章

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b

杭电1276--士兵队列训练问题

士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4605    Accepted Submission(s): 2148 Problem Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行

杭电1272 并查集找环+判断连通

杭电1272 并查集找环+判断连通 E - E Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1272 Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B

杭电ACM Java实现样例

若使用Java求解杭电ACM,答案提交必须注意两点: 1.类名一定得是Main,否则服务器无法编译: 2.必须用while进行输入判断. 以1000题测试题为例,代码如下: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); while(scan.hasNextInt()) { int a=scan.n

杭电 HDU 1038 Biker&#39;s Trip Odometer

Biker's Trip Odometer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4745    Accepted Submission(s): 3144 Problem Description Most bicycle speedometers work by using a Hall Effect sensor faste