변경이력

돌아가기
2 16개 문자 추가

2016/10/18 07:50

길가의풀

```{.cpp} #include <cstdlib> #include <iostream> using namespace std; int count_zero(int *a,int m){ int i; for(i=0;i<m;i++){ if(a[i]!=0)return 1; } return 0; } int count_sum(int *b,int m){ int i; int sum=0; for(i=0;i<m;i++){ sum=sum+b[i]; } return sum; } int clean1(int *a,int m,int n){ int i; for(i=0;i<m;i++){ if(a[i]==n){ a[i]=0; return 0; } } return 1; } int main(int argc, char *argv[]) { FILE* stream1; int m,w,n;//m 차량수 ,w 다리길이, n 하중한계 int i,j; //int a[100]={0,}; int *a; int *b; int z=0; //int b[100]={0,}; int sum=0; stream1=fopen("1.txt","r"); fscanf(stream1,"%d %d %d",&m,&w,&n); a=new int[m]; b=new int[w]; memset(a, 0, m * sizeof(int)); memset(b, 0, w * sizeof(int)); for(i=0;i<m;i++){ fscanf(stream1,"%d",&a[i]); } //memset(a, 0, m * sizeof(int)); //memset(b, 0, w * sizeof(int)); while(count_zero(a,m)){ for(i=w-1;i>=0;i--){ if(b[i]!=0&&i==w-1){ // b[i+1]=b[i]; clean1(a,m,b[i]); b[i]=0; } if(b[i]==0&&i!=0){ b[i]=b[i-1]; b[i-1]=0; } /* if(b[i]!=0&&i!=w-1){ //clean1(a,m,b[i]); b[i+1]=b[i]; b[i]=0; i--; } */ } if(b[0]==0&&count_sum(b,w)+a[z]<=n){ b[0]=a[z]; //printf("%d\n",b[0]); z++; } /* for(i=0;i<w;i++){ printf("%d ",b[i]); } printf("\n"); /* for(i=0;i<m;i++){ printf("%d ",a[i]); } printf("\n"); */ sum++; } delete []a; delete []b; printf("%d\n",sum); system("PAUSE"); return EXIT_SUCCESS; } ```
```{.cpp} #include <cstdlib> #include <iostream> using namespace std; int count_zero(int *a,int m){ int i; for(i=0;i<m;i++){ if(a[i]!=0)return 1; } return 0; } int count_sum(int *b,int m){ int i; int sum=0; for(i=0;i<m;i++){ sum=sum+b[i]; } return sum; } int clean1(int *a,int m,int n){ int i; for(i=0;i<m;i++){ if(a[i]==n){ a[i]=0; return 0; } } return 1; } int main(int argc, char *argv[]) { FILE* stream1; int m,w,n;//m 차량수 ,w 다리길이, n 하중한계 int i,j; //int a[100]={0,}; int *a; int *b; int z=0; //int b[100]={0,}; int sum=0; stream1=fopen("1.txt","r"); fscanf(stream1,"%d %d %d",&m,&w,&n); a=new int[m]; b=new int[w]; memset(a, 0, m * sizeof(int)); memset(b, 0, w * sizeof(int)); for(i=0;i<m;i++){ fscanf(stream1,"%d",&a[i]); } //memset(a, 0, m * sizeof(int)); //memset(b, 0, w * sizeof(int)); while(count_zero(a,m)){ for(i=w-1;i>=0;i--){ if(b[i]!=0&&i==w-1){ // b[i+1]=b[i]; clean1(a,m,b[i]); b[i]=0; } if(b[i]==0&&i!=0){ b[i]=b[i-1]; b[i-1]=0; } /* if(b[i]!=0&&i!=w-1){ //clean1(a,m,b[i]); b[i+1]=b[i]; b[i]=0; i--; } */ } if(b[0]==0&&count_sum(b,w)+a[z]<=n){ b[0]=a[z]; //printf("%d\n",b[0]); z++; } /* for(i=0;i<w;i++){ printf("%d ",b[i]); } printf("\n"); /* for(i=0;i<m;i++){ printf("%d ",a[i]); } printf("\n"); */ sum++; } delete []a; delete []b; printf("%d\n",sum); system("PAUSE"); return EXIT_SUCCESS; } ```
1 Original

2016/10/13 06:37

Lee Gorden

코딩도장

코딩도장은 프로그래밍 문제풀이를 통해서 코딩 실력을 수련(Practice)하는 곳입니다.