2580129
Solution:
1#include <iostream>2#include <vector>3 using namespacestd;4 5 intm[Ten][Ten] = {{1,0,0,0,0,0,0,0,0,0},6{1,1,1,1,1,1,1,1,1,1},7{1,0,1,1,0,1,1,0,1,1},8{0,0,0,1,0,0,1,0,0,1},9{1,0,0,0,1,1,1,1,1,1},Ten{1,0,0,0,0,1,1,0,1,1}, One{0,0,0,0,0,0,1,0,0,1}, A{1,0,0,0,0,0,0,1,1,1}, -{1,0,0,0,0,0,0,0,1,1}, -{0,0,0,0,0,0,0,0,0,1}}; the - - intMain () { -Ios_base::sync_with_stdio (false); + intT; -CIN >>T; + while(t--) { Avector<Char>_s; at stringstr; -CIN >>str; - CharCH = str[0]; - _s.push_back (CH); - inti; - BOOLF =true; in for(i =1; F && i < str.length (); ++i) { - if(m[ch-'0'][str[i]-'0']) { toCH =Str[i]; + _s.push_back (CH); - } the Else { * CharCC =Str[i]; $ while(1) {Panax Notoginseng Charc =_s.back (); - intK = CC-'0'-1; the for(; k >=0; --k) { + if(m[c-'0'][K]) Break; A } the + if(k >=0) { - for(intj =0; J < I; ++j) { $cout <<_s[j]; $ } -cout <<K; -CC ='0'+K; the for(intj = i +1; J < Str.length (); ++j) { - ints =9;Wuyi for(; s >=0; --s) { the if(m[cc-'0'][s]) Break; - } WuCC ='0'+s; -cout <<cc; About } $F =false; - Break; - } - Else { ACC =C; + _s.pop_back (); thei--; - if(_s.empty ()) { $cc--; the if(CC = ='0') { the for(intj =1; J < Str.length (); ++j) { thecout <<'9'; the } - } in Else { thecout <<cc; the About for(intj =1; J < Str.length (); ++j) { the ints =9; the for(; s >=0; --s) { the if(m[cc-'0'][s]) Break; + } -CC ='0'+s; thecout <<cc;Bayi } the } theF =false; - Break; - } the } the } the } the } - if(F) { the for(inti =0; I < _s.size (); ++i) cout <<_s[i]; the } thecout <<Endl;94 } the}