1 条题解

  • 0
    @ 2025-9-10 9:15:11

    C :

    #include <stdio.h>
    #include <malloc.h>
    int main()
    { int N;
    	while(scanf("%d",&N)!=EOF)
    	{int x,count1=0,count2=0,t,i,m,*p;
         while(N--)
    	 {
    		 scanf("%d",&x);
    		 if(!x) count1++;
    		 else count2++;
    	 }
          t=(count2/9)*9+count1;
    	  m=t-count1;
    	  p=(int *)malloc(t*sizeof(int));
    	  i=t;
    	  if(!m&&count1)       printf("0");
    	  else if(!count1) printf("-1");
    	  else
    	  {
    	  while(m--)
    	  p[--i]=5;	  
    	  while(count1--)
          p[--i]=0;
    	  for(;t>0;t--)
    	  printf("%d",p[t-1]);
    	  }
    	  printf("\n");
    	}
    return 0;
    }
    

    C++ :

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
        int n;
        while(cin>>n)
        {
            int i,temp,count5=0,count0=0;
            while(n--)
            {
                cin>>temp;
                temp?count5++:count0++;
            }
            if(count5<9)
            {
                if(count0>0)
                {
                    cout<<"0"<<endl;
                    continue;
                }
                cout<<"-1"<<endl;
                continue;
            }
            if(count0==0)
            {
                cout<<"-1"<<endl;
                continue;
            }
            for(i=1;i<=count5/9;i++)
                cout<<"555555555";
            for(i=1;i<=count0;i++)
                cout<<"0";
            cout<<endl;
        }
        return 0;
    }
    
    
    • 1

    信息

    ID
    4454
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者