• BestCoder Round#15 1002-Instruction


    http://acm.hdu.edu.cn/showproblem.php?pid=5083

    官方题解——》

    1002 Instruction 先考虑编码,首先找到operation对应的编码,如果是SET就找后面的一个R后面跟着的数字a,令b=0,否则找后面第一个R后面的数字当作a,第二个R后面的数字当作b,最后依次输出operation二进制编码,a, b的二进制编码。 再说解码,先将前6位,中间5位和后面5位转化成十进制记为oid, a, b。如果oid<1||oid>6就是Error!,如果oid<6那么a,b都不能为0,如果oid==6那么a!=0&&b==0。其它情况都是Error!,最后按照oid,a,b输出指令即可。

     下面来代码。。水平有限,比较丑,勿怪-_-|||

      1 #include <stdio.h>

     2 #include <string.h>
     3 #include <math.h>
     4 
     5 int num[33] = {
     6     011011100101110111,
     7     10001001101010111100110111101111,
     8     1000010001100101001110100101011011010111,
     9     1100011001110101101111100111011111011111
    10 };
    11 
    12 int op[10] = {
    13     011011100101110
    14 };
    15 
    16 char op2[7][6] = {
    17     """ADD""SUB""DIV""MUL""MOVE""SET"
    18 };
    19 
    20 
    21 
    22 
    23 int main(){
    24     int type, a, b, i, j, c;
    25     char str[20];
    26     while(scanf("%d", &type) != EOF){
    27         if(type == 1){
    28             scanf("%s ", str);
    29              if(strcmp(str, "ADD") == 0){
    30                 scanf("%*c%d,%*c%d", &a, &b);
    31                 printf("%06d%05d%05d ", op[1], num[a], num[b]);
    32             }
    33             else if(strcmp(str, "SUB") == 0){
    34                 scanf("%*c%d,%*c%d", &a, &b);
    35                 printf("%06d%05d%05d ", op[2], num[a], num[b]);
    36             }
    37             else if(strcmp(str, "DIV") == 0){
    38                 scanf("%*c%d,%*c%d", &a, &b);
    39                 printf("%06d%05d%05d ", op[3], num[a], num[b]);
    40             }
    41             else if(strcmp(str, "MUL") == 0){
    42                 scanf("%*c%d,%*c%d", &a, &b);
    43                 printf("%06d%05d%05d ", op[4], num[a], num[b]);
    44             }
    45             else if(strcmp(str, "MOVE") == 0){
    46                 scanf("%*c%d,%*c%d", &a, &b);
    47                 printf("%06d%05d%05d ", op[5], num[a], num[b]);
    48             }
    49             else if(strcmp(str, "SET") == 0){
    50                 scanf("%*c%d", &a);
    51                 printf("%06d%05d%05d ", op[6], num[a], num[0]);
    52             }
    53         }
    54         else{
    55             scanf("%s", str);
    56             for(c = i = 0; i < 6; i++){
    57                 if(str[i] == '1'){
    58                     c += (int)pow(25 - i);
    59                 }
    60             }
    61             if(c > 6 || c == 0){
    62                 printf("Error! ");
    63                 continue;
    64             }
    65             for(a = 0, i = 6; i < 11; i++){
    66                 if(str[i] == '1'){
    67                     a += (int)pow(210 - i);
    68                 }
    69             }
    70             if(a > 32 || a == 0){
    71                 printf("Error! ");
    72                 continue;
    73             }
    74             for(b = 0, i = 11; i < 16; i++){
    75                 if(str[i] == '1'){
    76                     b += (int)pow(215 - i);
    77                 }
    78             }
    79             if(b > 32){
    80                 printf("Error! ");
    81                 continue;
    82             }
    83             if(c == 6 && b != 0){
    84                 printf("Error! ");
    85                 continue;
    86             }
    87             if(c == 6 && a != 0 && b == 0){
    88                 printf("%s R%d ", op2[c], a);
    89                 continue;
    90             }
    91             if(c > 0 && c < 6 && a != 0 && b != 0){
    92                 printf("%s R%d,R%d ", op2[c], a, b);
    93                 continue;
    94             }
    95             printf("Error! ");
    96         }
    97     }
    98     return 0;
    99 }
  • 相关阅读:
    腾讯视频插入网页的代码;
    FW: 软件持续交付的诉求;
    TOGAF
    Windows WSL2 htop打开黑屏的问题解决
    requests.exceptions.ConnectionError: HTTPSConnectionPool(host='appts.xxx.com%20', port=443):
    sqlalchemy实现模糊查询
    jenkins过滤版本,可选择版本
    QML 布局之一:锚布局详解(各种例子)
    Qt Quick 常用控件:Button(按钮)用法及自定义
    The Common Order Operations of Dis Operation System (DOSS)
  • 原文地址:https://www.cnblogs.com/angle-qqs/p/4051151.html
Copyright © 2020-2023  润新知