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. 一步步完成“迷你版” 的ASP.NET Core框架

    一 前言 Artech 分享了 200行代码,7个对象--让你了解ASP.NET Core框架的本质 . 用一个极简的模拟框架阐述了ASP.NET Core框架最为核心的部分. 这里一步步来完成这个迷 ...

  2. 利用YYLabel 进行图文混排+高度计算

    利用YYLabel 进行图文混排+高度计算 1.项目需求: 用一个控件显示图片和文字,并且依据图片和文字动态计算控件的高度. 2.方案: 利用YYLabel控件和属性字符串处理. 注:(在使用YYLa ...

  3. Android开发实践:掌握Camera的预览方向和拍照方向

    http://ticktick.blog.51cto.com/823160/1592267?utm_source=tuicool&utm_medium=referral Android的Cam ...

  4. unity关于StartCoroutine的简单线程使用

    StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,但是在unity中有些元素是不能操作的.这个时候可以使用协程来完成. 使 ...

  5. NDAP 日志

    2014.04.29 1.理论债券价格CalculateExpetedBondPrice计算有误差 CalculateLibrary中的计算理论债券价格(计算理论期货价格的反函数)和正确结果有误差(可 ...

  6. perl C/C++ 扩展(五)

    perl 的C++扩展,返回值为自定义类型. 在 perl C/C++扩展(三) 中,我已经介绍了,如何让perl 认识 c++的类,但是前面的介绍中,包括我参考的博客http://chunyemen ...

  7. sed 匹配\n换行符

    假设 str="a,b,c,d" echo ${str} | sed "s/,/\n/g" 输出: a b c d echo ${str} | sed &quo ...

  8. xml和TreeView

    1.TreeView代码代码: private void Form1_Load(object sender, EventArgs e) {<br> //代码为TreeView添加子项 tr ...

  9. 第十二章 设计用户界面 之 设计自适应的UI布局

    1. 概述 随着手机和平板设备的日益普及,使得开发者不得不考虑MVC网站在移动设备上的展示. 本章内容包括:运行在多种设备上的程序(屏幕分辨率,CSS,HTML).设计手机端Web程序. 2. 主要内 ...

  10. go实现生产者消费者

    package main import ( "fmt" "math/rand" ) func main() { ch := make(chan int) don ...