2017年江西理工大学C语言程序设计竞赛(初级组)
问题 A: Petr的盒子(初)
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 using namespace std; 5 int a[100005]; 6 int main(){ 7 int n , x; 8 scanf("%d",&n); 9 for(int i = 0 ; i < n ; i ++){ 10 scanf("%d",&x); 11 a[i] = 1; 12 a[i] *= x; 13 } 14 for(int i = 0 ; i < n ; i ++){ 15 scanf("%d",&x); 16 a[i] *= x; 17 } 18 for(int i = 0 ; i < n ; i ++){ 19 scanf("%d",&x); 20 a[i] *= x; 21 } 22 sort(a , a + n); 23 for(int i = n - 1 ; i >= 0 ; i --){ 24 printf("%d",a[i]); 25 if(i != 0) printf(" "); 26 else printf("\n"); 27 } 28 }
1 #include <stdio.h> 2 3 int main( ) 4 { 5 int i,n,j,t; 6 scanf("%d",&n); 7 int x[10]; 8 int y[10]; 9 int z[10]; 10 int V[10]; 11 12 for(i=0;i<n;i++) 13 {scanf("%d",&x[i]);} 14 for(i=0;i<n;i++) 15 {scanf("%d",&y[i]);} 16 for(i=0;i<n;i++) 17 {scanf("%d",&z[i]);} 18 19 for(i=0;i<n;i++) 20 21 {V[i]=x[i]*y[i]*z[i];} 22 23 for(i=0;i<n-1;i++) 24 25 for(j=i+1;j<n;j++) 26 if(V[i]<V[j]) 27 {t=V[i],V[i]=V[j],V[j]=t;} 28 29 for(i=0;i<n;i++) 30 31 printf("%3d",V[i]); 32 return 0; 33 }
1 #include<stdio.h> 2 3 int main() 4 { 5 int t,n,a[10],i,j,b[10],c[10],d[10]; 6 scanf("%d",&n); 7 for(i=0;i<n;i++) 8 { 9 scanf("%d ",&a[i]); 10 } 11 for(i=0;i<n;i++) 12 { 13 scanf("%d",&b[i]); 14 } 15 for(i=0;i<n;i++) 16 { 17 scanf("%d",&c[i]); 18 } 19 for(i=0;i<n;i++) 20 { 21 d[i]=a[i]*b[i]*c[i]; 22 } 23 for(i=0;i<n-1;i++) 24 for(j=0;j<n-1;j++) 25 { 26 if(d[j]<d[j+1]) 27 { 28 t = d[j]; 29 d[j] = d[j+1]; 30 d[j+1] = t; 31 } 32 } 33 for(i=0;i<n;i++) 34 printf("%d ",d[i]); 35 return 0; 36 }
问题 B: 初级魔法师(初)
1 #include <iostream> 2 using namespace std; 3 int main(){ 4 int n, m, sum = 0; 5 scanf("%d%d", &n, &m); 6 for(int i = 1; i <= m; ++i){ 7 sum += (n%i); 8 } 9 printf("%d\n", sum); 10 return 0; 11 }
1 #include<stdio.h> 2 #define N 1000000000 3 long int main() 4 { 5 long int n,m,i,a=0,s; 6 scanf("%d%d",&n,&m); 7 for(i=1;i<=m;i++) 8 a=a+n%i; 9 s=a%(N+7); 10 printf("%d\n",s); 11 return 0; 12 }
问题 C: Just wanna a bubble of fishes.(初 )
1 #include <iostream> 2 using namespace std; 3 int main(){ 4 double sum = 0, x, num; 5 scanf("%lf", &num); 6 sum = num; 7 for(int i = 1; i < 5; ++i){ 8 scanf("%lf", &x); 9 sum += x; 10 } 11 x = sum / 5.0; 12 printf("%s\n", x < num ? "no" : "yes"); 13 return 0; 14 }
1 #include <stdio.h> 2 int main() 3 { 4 float a[5],ave=0; 5 int i; 6 for(i=0;i<5;i++) 7 { 8 scanf("%f",&a[i]); 9 ave=ave+a[i]; 10 } 11 ave=ave/5; 12 13 if(ave<=a[0]) printf("no"); 14 else printf("yes"); 15 16 return 0; 17 }
问题D: Paginationaried
1 #include <stdio.h> 2 int main(int argc, char *argv[]) 3 { 4 int i,n,m; 5 scanf("%d%d",&n,&m); 6 if(n>5&&m<n-2&&m>2){ 7 printf("%d %d %d(+) %d %d",m-2,m-1,m,m+1,m+2); 8 9 } 10 else if(n>=5&&m>=n-2){ 11 for(i=n-4;i<=n;i++) 12 { 13 if(i==m)printf("%d(+) ",i); 14 if(i!=m)printf("%d ",i); 15 } 16 } 17 else if(n>=5&&m<=2){ 18 for(i=1;i<=5;i++) 19 { 20 if(i==m)printf("%d(+) ",i); 21 if(i!=m)printf("%d ",i); 22 23 } 24 } 25 else if(n<5){ 26 for(i=1;i<=n;i++){ 27 if(i==m)printf("%d(+) ",i); 28 if(i!=m)printf("%d ",i); 29 } 30 } 31 return 0; 32 }
问题 E: 喵喵大战猪猪侠(初)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <algorithm> 4 5 using namespace std; 6 7 int main() 8 { 9 int n; 10 scanf("%d", &n); 11 int* miao = (int*)malloc(sizeof(int) * n); 12 int* zhu = (int*)malloc(sizeof(int) * n); 13 for (int i = 0; i < n; i++) scanf("%d", miao + i); 14 for (int i = 0; i < n; i++) scanf("%d", zhu + i); 15 sort(miao, miao + n); 16 sort(zhu, zhu + n); 17 int left = 0; 18 int right = n - 1; 19 int win_cnt = 0; 20 for (int i = n - 1; i >= 0; i--) 21 { 22 if (miao[right] > zhu[i]) 23 { 24 // printf(" win: %d %d\n", miao[right], zhu[i]); 25 win_cnt++; 26 right--; 27 } 28 else 29 { 30 // printf("lose: %d %d\n", miao[left], zhu[i]); 31 left++; 32 } 33 } 34 printf("%d\n", win_cnt); 35 return 0; 36 }
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 int miao[1000006],zhu[1000006]; 5 int n; 6 int main(){ 7 std::ios::sync_with_stdio(false); 8 cin >> n; 9 for(int i= 0; i < n; i++){ 10 cin >> miao[i]; 11 } 12 for(int i = 0; i < n; i++){ 13 cin >> zhu[i] ; 14 } 15 sort(miao,miao + n); 16 sort(zhu,zhu + n); 17 int ans = 0 ,p = -1; 18 int j = n - 1; 19 for(int i = n - 1; i >= 0; i--){ 20 if (miao[j] > zhu[i] && j != p){ 21 ans ++; 22 j --; 23 }else{ 24 p ++; 25 26 } 27 } 28 cout << ans << endl; 29 return 0; 30 }
问题 F: 美丽的二进制字符串(初)
1 #include <stdio.h> 2 #include <iostream> 3 using namespace std; 4 int main(){ 5 string s; 6 cin >> s; 7 int ans = 0 ; 8 for(int i = 1 ; i < s.size() - 1; i ++){ 9 if(s[i] == '1' && s[i - 1] == '0' && s[i + 1] == '0'){ 10 ans ++; 11 s[i + 1] = '1'; 12 } 13 } 14 printf("%d\n",ans); 15 }
1 import java.io.OutputStream; 2 import java.io.IOException; 3 import java.io.InputStream; 4 import java.io.PrintWriter; 5 import java.util.Scanner; 6 7 /** 8 * Built using CHelper plug-in 9 * Actual solution is at the top 10 * 11 * @author hsy 12 */ 13 public class Main { 14 public static void main(String[] args) { 15 InputStream inputStream = System.in; 16 OutputStream outputStream = System.out; 17 Scanner in = new Scanner(inputStream); 18 PrintWriter out = new PrintWriter(outputStream); 19 Task solver = new Task(); 20 solver.solve(1, in, out); 21 out.close(); 22 } 23 24 static class Task { 25 public void solve(int testNumber, Scanner in, PrintWriter out) { 26 String s = in.next(); 27 char[] str = s.toCharArray(); 28 int h = 0; 29 for (int i = 0; i < s.length() - 2; i++) { 30 if (str[i] == '0' && str[i + 1] == '1' && str[i + 2] == '0') { 31 h++; 32 str[i + 2] = '1'; 33 } 34 } 35 out.println(h); 36 } 37 38 } 39 }
1 print raw_input().count('010')