Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- typedef long double ld;
- string h;
- int n,R;
- int num[]={6,2,5,5,4,5,6,3,7,6};
- char bb[100009];
- int main()
- {
- for(int p=9;p>=0;p--)
- num[p]-=2;
- int t;
- cin>>t;
- while(t--){
- scanf("%d%s",&n,bb);
- h=bb;
- R=0;
- for(int i=0;i<h.size();i++)R+=num[h[i]-'0'];
- for(int i=0;i<n;i++)
- {
- if(R>4*(n-i)&&R-num[8]>=0)
- {
- h[i]='8';
- R-=num[8];
- continue;
- }
- for(int p=9;p>=0;p--)
- {
- if(R-num[p]>=0)
- {
- if(i==n-1&&R-num[p]!=0)continue;
- h[i]='0'+p;
- R-=num[p];
- break;
- }
- }
- // cout<<R<<' ';
- }
- for(int i=0;i<n;i++)printf("%c",h[i]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement