• hdu 2707


    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2707

    题意:在一篇文章中,每一段连续的空格代表一个0或一个1。偶数个代表1,奇数个则为0。把所有空格连起来得到一串0-1组成的二进制,再进行解密。每5个0-1二进制字符对应1个字母,末尾不足5个补零。二进制对应的十进制中,0代表空格,1代表A,2代表B……26代表Z,之后27到31分别代表',-.?。按要求解密文章。

    mark:暴力搞就好,题目说保证空格不出现在每行的行头和行尾,就简单多了。装逼没有好下场,1wa就wa在不想用memset,结果i+j>=cnt写成了i+j>cnt。。。

    代码:

     1 # include <stdio.h>
     2 # include <string.h>
     3 
     4 
     5 char str[110] ;
     6 char tab[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ',-.?" ;
     7 int cnt, label[1100] ;
     8 
     9 
    10 void gao()
    11 {
    12     int i, sp = 0 ;
    13     for (i = 0 ; str[i] ; i++)
    14     {
    15         if (str[i] != ' ' && sp != 0)
    16             label[cnt++] = ((sp&1)?0:1), 
    17             sp = 0 ;
    18         else if (str[i] == ' ') sp++ ;
    19     }
    20 }
    21 
    22 
    23 void Print()
    24 {
    25     int i, j, buff ;
    26     for (i = 0 ; i < cnt ; i+= 5)
    27     {
    28         buff = 0 ;
    29         for (j = 0 ;j < 5 ; j++)
    30         {
    31             if (i+j>=cnt) label[i+j] = 0 ;
    32             buff = buff * 2 + label[i+j] ;
    33         }
    34         putchar (tab[buff]) ;
    35     }
    36     printf("\n") ;
    37 }
    38 
    39 
    40 int main ()
    41 {
    42     gets (str) ;
    43     while (1)
    44     {
    45         cnt = 0 ;
    46         if (strcmp(str, "#") == 0) break ;
    47         while (1)
    48         {
    49             if (strcmp(str, "*") == 0) break ;
    50             gao() ;
    51             gets (str) ;
    52         }
    53         Print() ;
    54         gets (str) ;
    55     }
    56     return 0 ;
    57 }
  • 相关阅读:
    Discuz!NT 系统架构分析
    jquery pager
    Nhibernate分页方法
    Discuz nt模板机制
    WTclient创建OPC client方法
    OPC
    Regular Expressions in Java
    How to use VS to manipulate Access
    OPC客户端设计
    How to use VS to manipulate Excel使用MFC读写Excel
  • 原文地址:https://www.cnblogs.com/lzsz1212/p/2511885.html
Copyright © 2020-2023  润新知