zoukankan      html  css  js  c++  java
  • 【HDOJ】2526 浪漫手机

    字符串大水题。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cstdlib>
     4 
     5 #define MAXN 105
     6 
     7 typedef struct {
     8     char s[5];
     9     char ch;
    10 } pattern_t;
    11 
    12 char line[2][MAXN];
    13 pattern_t pat[8];
    14 int t, n;
    15 
    16 int comp(const void *a, const void *b) {
    17     pattern_t *p = (pattern_t *)a;
    18     pattern_t *q = (pattern_t *)b;
    19     
    20     return strcmp(p->s, q->s);
    21 }
    22 
    23 int main() {
    24     int m;
    25     int i, j, k;
    26     int v;
    27     
    28 #ifndef ONLINE_JUDGE
    29     freopen("data.in", "r", stdin);
    30     freopen("data.out", "w", stdout);
    31 #endif
    32     
    33     scanf("%d", &t);
    34     while (t--) {
    35         scanf("%d", &m);
    36         for (i=0; i<8; ++i)
    37             scanf("%s %c", pat[i].s, &pat[i].ch);
    38         scanf("%s", line[0]+1);
    39         
    40         qsort(pat, 8, sizeof(pattern_t), comp);
    41         line[0][0] = line[1][0] = '0';
    42         k = 0;
    43         n = strlen(line[0]+1);
    44         while (m--) {
    45             line[k][n+1] = '';
    46             printf("%s
    ", line[k]+1);
    47             line[k][n+1] = '0';
    48             j = !k;
    49             for (i=1; i<=n; ++i) {
    50                 v = ((line[k][i-1]-'0')<<2) + ((line[k][i]-'0')<<1) + (line[k][i+1]-'0');
    51                 line[j][i] = pat[v].ch;
    52             }
    53             k = j;
    54         }
    55     }
    56     
    57     return 0;
    58 }
  • 相关阅读:
    省市级联
    innerText与innerHTML的区别
    使用代码提交表单
    Date的使用
    Array(数组)的使用
    [贪心]Rest Stops
    [数论][Miller_Rabin] Goldbach
    [简单思维题]Hoofball
    [数论][容斥原理]Co-prime
    [图论][二分图最大匹配]Courses
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4181361.html
Copyright © 2011-2022 走看看