Advertisement
Joao_Joao

Beecrowd 3159 - C

May 18th, 2022
766
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4.  
  5. #define f(i, s, t) for (int i = s; i < t; ++i)
  6.  
  7. int main() {
  8.   int ns[125], ns1[125];
  9.   ns['a'] = 2, ns['b'] = 2, ns['c'] = 2;
  10.   ns['d'] = 3, ns['e'] = 3, ns['f'] = 3;
  11.   ns['g'] = 4, ns['h'] = 4, ns['i'] = 4;
  12.   ns['j'] = 5, ns['k'] = 5, ns['l'] = 5;
  13.   ns['m'] = 6, ns['n'] = 6, ns['o'] = 6;
  14.   ns['p'] = 7, ns['q'] = 7, ns['r'] = 7, ns['s'] = 7;
  15.   ns['t'] = 8, ns['u'] = 8, ns['v'] = 8;
  16.   ns['w'] = 9, ns['x'] = 9, ns['y'] = 9, ns['z'] = 9;
  17.   ns[' '] = 0;
  18.  
  19.   ns1['a'] = 1, ns1['b'] = 2, ns1['c'] = 3;
  20.   ns1['d'] = 1, ns1['e'] = 2, ns1['f'] = 3;
  21.   ns1['g'] = 1, ns1['h'] = 2, ns1['i'] = 3;
  22.   ns1['j'] = 1, ns1['k'] = 2, ns1['l'] = 3;
  23.   ns1['m'] = 1, ns1['n'] = 2, ns1['o'] = 3;
  24.   ns1['p'] = 1, ns1['q'] = 2, ns1['r'] = 3, ns1['s'] = 4;
  25.   ns1['t'] = 1, ns1['u'] = 2, ns1['v'] = 3;
  26.   ns1['w'] = 1, ns1['x'] = 2, ns1['y'] = 3, ns1['z'] = 4;
  27.   ns1[' '] = 1;
  28.  
  29.   int n;
  30.   size_t size = 150;
  31.   char * p = (char*) malloc(size * sizeof(char)), ant;
  32.   while(scanf("%d", &n) != EOF) {
  33.     getline(&p, &size, stdin);
  34.     f(i,0,n) {
  35.       getline(&p, &size, stdin);
  36.       ant = '-';
  37.       f(j,0,strlen(p) - (p[strlen(p)-1] == 10)) {
  38.         if(p[j] != 32 && p[j] < 97) printf("#"), p[j] += 32;
  39.         else if(ns[ant] == ns[p[j]]) printf("*");
  40.         f(k,0,ns1[p[j]]) printf("%d", ns[p[j]]);
  41.         ant = p[j];
  42.       }
  43.       printf("\n");
  44.     }
  45.   }
  46. }
Advertisement
RAW Paste Data Copied
Advertisement