Advertisement
jeff69

Untitled

Sep 27th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. typedef long double ld;
  5. string h;
  6. int n,R;
  7.  
  8.  int num[]={6,2,5,5,4,5,6,3,7,6};
  9.  
  10. char bb[100009];
  11.   int main()
  12. {
  13.      for(int p=9;p>=0;p--)
  14.                num[p]-=2;
  15.     int t;
  16.     cin>>t;
  17.     while(t--){
  18.             scanf("%d%s",&n,bb);
  19.             h=bb;
  20.             R=0;
  21.             for(int i=0;i<h.size();i++)R+=num[h[i]-'0'];
  22.  
  23.             for(int i=0;i<n;i++)
  24.             {
  25.                 if(R>4*(n-i)&&R-num[8]>=0)
  26.                 {
  27.                     h[i]='8';
  28.                     R-=num[8];
  29.                     continue;
  30.                 }
  31.                 for(int p=9;p>=0;p--)
  32.                 {
  33.                     if(R-num[p]>=0)
  34.                     {
  35.                         if(i==n-1&&R-num[p]!=0)continue;
  36.                         h[i]='0'+p;
  37.                         R-=num[p];
  38.                         break;
  39.                     }
  40.                 }
  41.                // cout<<R<<' ';
  42.             }
  43.              for(int i=0;i<n;i++)printf("%c",h[i]);
  44.             printf("\n");
  45.     }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement