Sunday, June 19, 2016

TLAC Kattis T9Spelling

Having a bad day , struggling with even simplest problems.

If can't think of anything smarter , code the dumb one if IT WORKS.


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/****************************************

@_@
Cat Got Bored *_*
#_#
*****************************************/

#include <bits/stdc++.h>


#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)


#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);


#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define fs first

#define sc second

#define CASE(t) printf("Case #%d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

using namespace std;
//Remove this before submission

const int parser[] = {0,2,22,222,3,33,333,4,44,444,5,55
                      ,555,6,66,666,7,77
                      ,777,7777,8,88,888,9,99,999,9999
                     };

int prse(char c)
{
    if(c==' ')
        return 0;
    int cnv = c - 'a' +1;
    return parser[cnv];
}
bool sme_btn(char ch1,char ch2)
{
    //cout<<c1<<"  "<<c2<<endl;
    if(ch1==ch2)
        return true;
    int c1 = ch1 - 'a' +1;
    int c2 = ch2 - 'a' +1;

    //cout<<cn1<<" "<<cn2<<endl;
    if(c1==1 || c1==2 ||c1==3)
        if(c2==1 || c2==2 ||c2==3)
            return true;
    if(c1==4 || c1==5 ||c1==6)
        if(c2==4 || c2==5 ||c2==6)
            return true;

    if(c1==7 || c1==8 ||c1==9){
        if(c2==7 || c2==8 ||c2==9)
            return true;

    }

    if(c1==10 || c1==11 ||c1==12)
        if(c2==10 || c2==11 ||c2==12)
            return true;

    if(c1==13 || c1==14 ||c1==15)
        if(c2==13 || c2==14 ||c2==15)
            return true;

    if(c1==16 || c1==17 ||c1==18 ||c1==19)
        if(c2==16 || c2==17 ||c2==18 ||c2==19)
            return true;

    if(c1==22 || c1==20 ||c1==21)
        if(c2==22 || c2==20 ||c2==21)
            return true;
    if(c1==25 || c1==23 ||c1==24 ||c1==26)
        if(c2==25 || c2==23 ||c2==24 ||c2==26)
            return true;

    return false;


}
char ss[10000];
int main()
{
    int N;
    int cas = 0;
    sfi(N);
    gets(ss);
    while(N--)
    {

        gets(ss);
        int len = strlen(ss);

        CASE(cas);
        loop(i,0,len-1)
        {
            if(i!=0 && sme_btn(ss[i-1],ss[i]))
                cout<<" "<<prse(ss[i]);
            else
                cout<<prse(ss[i]);
        }
        cout<<endl;
    }

    return 0;
}

No comments:

Post a Comment