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[] = {
 6     , , , , , , , ,
 7     , , , , , , , ,
 8     , , , , , , , ,
 9     , , , , , , , 
 };
 
 int op[] = {
     , , , , , , 
 };
 
 char op2[][] = {
     "", "ADD", "SUB", "DIV", "MUL", "MOVE", "SET"
 };
 
 
 
 
 int main(){
     int type, a, b, i, j, c;
     char str[];
     while(scanf("%d", &type) != EOF){
         if(type == ){
             scanf("%s ", str);
              if(strcmp(str, "ADD") == ){
                 scanf("%*c%d,%*c%d", &a, &b);
                 printf("%06d%05d%05d\n", op[], num[a], num[b]);
             }
             else if(strcmp(str, "SUB") == ){
                 scanf("%*c%d,%*c%d", &a, &b);
                 printf("%06d%05d%05d\n", op[], num[a], num[b]);
             }
             else if(strcmp(str, "DIV") == ){
                 scanf("%*c%d,%*c%d", &a, &b);
                 printf("%06d%05d%05d\n", op[], num[a], num[b]);
             }
             else if(strcmp(str, "MUL") == ){
                 scanf("%*c%d,%*c%d", &a, &b);
                 printf("%06d%05d%05d\n", op[], num[a], num[b]);
             }
             else if(strcmp(str, "MOVE") == ){
                 scanf("%*c%d,%*c%d", &a, &b);
                 printf("%06d%05d%05d\n", op[], num[a], num[b]);
             }
             else if(strcmp(str, "SET") == ){
                 scanf("%*c%d", &a);
                 printf("%06d%05d%05d\n", op[], num[a], num[]);
             }
         }
         else{
             scanf("%s", str);
             for(c = i = ; i < ; i++){
                 if(str[i] == ''){
                     c += (int)pow(,  - i);
                 }
             }
             if(c >  || c == ){
                 printf("Error!\n");
                 continue;
             }
             for(a = , i = ; i < ; i++){
                 if(str[i] == ''){
                     a += (int)pow(,  - i);
                 }
             }
             if(a >  || a == ){
                 printf("Error!\n");
                 continue;
             }
             for(b = , i = ; i < ; i++){
                 if(str[i] == ''){
                     b += (int)pow(,  - i);
                 }
             }
             if(b > ){
                 printf("Error!\n");
                 continue;
             }
             if(c ==  && b != ){
                 printf("Error!\n");
                 continue;
             }
             if(c ==  && a !=  && b == ){
                 printf("%s R%d\n", op2[c], a);
                 continue;
             }
             if(c >  && c <  && a !=  && b != ){
                 printf("%s R%d,R%d\n", op2[c], a, b);
                 continue;
             }
             printf("Error!\n");
         }
     }
     return ;
 }

BestCoder Round#15 1002-Instruction的更多相关文章

  1. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  2. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [f(n ...

  3. BestCoder Round#15 1001-Love

    http://acm.hdu.edu.cn/showproblem.php?pid=5082 Love Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  5. Manacher BestCoder Round #49 ($) 1002 Three Palindromes

    题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...

  6. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

  7. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  8. BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)

    今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...

  9. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

随机推荐

  1. js 点击往div里添加图片(实例)

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  2. UGUI(四)事件系统的封装

    UGUI的事件系统默认使用时,是需要当前的类继承事件接口,就可以在该类中加入它的事件方法,但是在多人开发时这种方式没什么好处. 用过NGUI的或许都知道UIEventListener这个类,因为使用超 ...

  3. Cocoapods在OS X Yosemite上报错的解决方法

    今天升级了Mac OS X 10.10-Yosemite以后运行pod install遇到下面的错误: /System/Library/Frameworks/Ruby.framework/Versio ...

  4. bzoj2502清理雪道

    传送门 好题啊,由于每个点既可以进,也可以出,就可以新建一个源点和汇点,对于每个点都连边,然后就是最小流板子了. 代码: #include<cstdio> #include<iost ...

  5. JavaScript 原生提供两个 Base64 相关的方法

    JavaScript 原生提供两个 Base64 相关的方法. btoa():任意值转为 Base64 编码 atob():Base64 编码转为原来的值 var string = 'Hello Wo ...

  6. Map集合的四种常用遍历方式整理

    1.Map集合简介:map集合是一个key—value型的数据结构,存储的数据具有查询速度快速的特点,但由于是无序的,所以没有顺序可言.在遍历时没有办法像简单的list或数组一样. 2.代码: pac ...

  7. FMDB存储模型对象(以二进制存储)用NSKeyedArchiver archivedDataWithRootObject序列号,NSKeyedUnarchiver unarchiveObjectWithData反序列化(重点坑是sql语句@"insert into t_newsWithChannel (nwesName,newsType) values (?,?)")一定要用占位符

    交友:微信号 dwjluck2013 一.封装FMDB单例 (1)JLFMDBHelp.h文件 #import <Foundation/Foundation.h> #import < ...

  8. [題解](貪心/堆)luogu_P2107小Z的AK計劃

    清明講過一道類似的,難度略大的:P3545 [POI2012]HUR-Warehouse Store 兩道題類似,都是暫時先把前面的加進候選集合里,如果超出限制的話就拿現在這個和前面的交換, 相當於不 ...

  9. Flask (七) 部署

    阿里云部署Flask项目   部署Flask项目和部署Django项目基本一致,我们也使用uwsgi+nginx   我们在部署Django项目基础上部署Flask项目   1, 将uwsgi.ini ...

  10. 剑指offer部分编程题

    一 斐波那契数列 题目描述: 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项. n<=39 问题分析: 可以肯定的是这一题通过递归的方式是肯定能做出来,但是这样会有 ...