POJ 1302 Blue Gene, Jr.(递归实现)

2023-11-04

Inspired by IBM’s Blue Gene project, the CEO of Universal Biological Machinery (UBM), has called on you, UBM’s top software engineer, to develop a program that will calculate the mutation of the Areopagus-virus, a virus discovered on Mars by your company’s privately-subsidized (top-secret) space program.
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
A single data set has 3 components:

Start line - A single line, “START N”, where 1 <= N <= 20.
Viral code - A sequence of N alphanumeric characters. Alphanumeric characters will consist of an uppercase letter (A-Z) or a digit (0-9).
End line - A single line, “END”

Following the final data set will be a single line, “ENDOFINPUT”.
Output
For each data set, there will be exactly one output set, and there will be no blank lines separating output sets.

A single output set consists of a single line of the viral code after it has stabilized (through mutating).

The viral code will mutate according to the following rules:

Initially the first viral segment to mutate begins with the first alphanumeric character of the viral code and ends with the rightmost alphanumeric character of the code.
If the first alphanumeric character of a viral segment is a letter (A-Z), that alphanumeric character is considered “unstable”, and will mutate into n, where n is the number of mutations that occur to the viral segment immediately to the unstable alphanumeric character’s right (see #5), unless n is greater than 9, in which case the unstable alphanumeric character will mutate into n % 10. Also, if there is no viral segment immediately to the right of the unstable alphanumeric character, the unstable alphanumeric character will mutate into 0.
If the first alphanumeric character of a viral segment, n, is a positive number (1-9), that alphanumeric character is also considered “unstable”, and will mutate into n-1. It also causes the viral segment beginning with the alphanumeric character n alphanumeric characters to its right and ending with the rightmost alphanumeric character of the viral code to mutate. If there is no alphanumeric character n alphanumeric characters to its right, then the viral segment immediately to its right (see #5), if one exists, will mutate.
If the first alphanumeric character of a viral segment is 0, that alphanumeric character is considered “stable”, and will not mutate (the alphanumeric character will remain a 0 and a mutation will not be considered to have occurred).
A viral segment immediately to the right of an alphanumeric character begins with the alphanumeric character one position to its right and ending with the rightmost alphanumeric character of the viral code.

Sample Input
START 1
A
END
START 4
A1B2
END
START 15
A3B2CCC4AD1232R
END
START 15
0ABCDEFGHIJKLMN
END
START 11
ABCDEFGHIJK
END
START 10
9AAAAAAAAA
END
ENDOFINPUT

Sample Output
0
3011
82B26543AD11310
0ABCDEFGHIJKLMN
09876543210
8AAAAAAAA0
题意分析:
就是给你一串字符串,如果字符串是字母开头的,此字母就变成后面变异数的总和。
如果字符串的开头是数字n,此数字变成n-1,然后从后面第n个开始变异。
如果字符串以0开头,就不发生变异,直接输出。
解题思路:
就是一个递归的过程
1.字符串是字母开头时,直接向后移一位,进行递归。
2.开头是数字n时,就变成n-1,如果后面还有n位,就移到n位再继续转变,否则右移一位开始转变,进行递归。
3.当开头为0时,直接结束递归。

#include <stdio.h>
#include <string.h>
s
int digui(int t); 
int n,t=0;
char a[25];
char str[25];
int main()
{
    
    while (scanf("%s",str)) 
	{
        if (strcmp(str,"ENDOFINPUT")==0)
        {
        	break;
		}
        scanf("%d%s%s",&n,a,str);
        digui(0);
        printf("%s\n",a);
    }
    return 0;
}
int digui(int t)
{
	int  m; 
    if (a[t]=='0'||t == n) //递归出口 
	{
        return 0;
    }
    if (a[t]>='A'&&a[t]<='Z') //字母处理 
	{
        m=digui(t+1);
    	a[t]=(m%10)+'0';
        return  m+1;
    }
    if (a[t]>='1'&&a[t]<='9') //数字处理 
	{
		a[t]--;
        if (t+a[t]-'0'+1<n) 
		{
            m=digui(t+a[t]-'0'+1);
            return m+1;
        }
        else 
		{
            m=digui(t+1);
            return m+1;
        }
    }
}



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

POJ 1302 Blue Gene, Jr.(递归实现) 的相关文章

  • 新手学编程必会的100个代码

    前言 我记得刚开始接触编程的时候 觉得太难了 也很好奇 写代码的那些人也太厉害了吧 全是英文的 他们的英文水平一定很好吧 他们是怎么记住这么多代码格式的 而且错了一个标点符号 整个程序都会有影响 一个程序几千行 错一个标点符号都不行这也太难
  • python 代码 给点云增加随机噪音同时保留原有点云

    微信 394467238 有的时候我们需要把原有的点云数据扩充一下 让它的鲁棒性更强 思路很简单 就是先生成一个随机的正态分布的噪音 然后加到点云原有的XYZ数据上面 直接放代码 代码已经运行过了 没有问题 代码中的 std 就是正态分布的
  • 记录一下mac mini 2018 的折腾过程

    更新 昨天手贱在外置雷电SSD中安装了苹果内置SSD的驱动 随即就造成了外置显卡的挂载不上 又折腾了大概三个小时 随后想到了应该是操作系统内部资源竞争 造成不挂载外置显卡 随后删除了内置SSD的驱动 然后才挂载外置显卡成功 还有一点就是 外

随机推荐

  • SendMessage()窗体之间发消息

    SendMessage调用一个窗口的窗口函数 将一条消息发给那个窗口 一 父窗口向子窗口发消息 1 接收方 1 1头文件里面声明消息 define MSG UPDATE LEFT CHILD WM USER 600 1 2消息映射 在头文件
  • halcon基本图像操作

    halcon基本图像操作 阈值分割 取某一个阈值下的某一个区域 获取中心点位置 形态学 膨胀 腐蚀 开运算 闭运算 综合使用 开运算和检测轮廓 字符识别 资源路径 F halcon halconStudy 阈值分割 灰度值 读取图像 转灰度
  • 在线接口测试工具(神器)

    前方高能 请注意 想必大家都用过POSTMAN 进行接口的测试吧 那么接下来我告诉你 你用了这个工具以后 你就不会再想去用POSTMAN了 话不多说了 直接上代码吧 还是那句话 我会尽可能详细的去演示操作过程 避免大家走弯路 123456
  • MySQL阅读网上MySQL文章有感的杂记

    前言 本篇文章将会记录各大MySQL文章的一些有意思的内容摘取 以及一些问题的提问 并且持续更新 并且MySQL专栏将会记录MySQL常考的场景题等实战 问题归类 1 MySQL从加锁范围上分为哪三类 2 全局锁加锁方法的执行命令是什么 主
  • Openwrt的uci接口

    UCI是Unified Configuration Interface的缩写 翻译成中文就是统一配置接口 用途就是为OpenWrt提供一个集中控制的接口 OpenWrt实现的这个工具 能够让你的不管是Lua还是PHP程序 或者SHELL程序
  • 无网络环境,如何部署Docker镜像

    一 简介 无网络环境 部署 Docker 镜像 这通常适用于一些部署环境是脱离网络的公司 或者公司内部有着严格的网络安全要求 且还是 Docker 部署的程序 这个时候怎么办 别急今天就来讲讲 无网络环境 如何部署 Docker 镜像 二
  • awk命令的使用

    1 获取根分区剩余大小 先用df h命令查看磁盘 确定我们需要获取字段的位置 再使用awk命令获取此字段 df h df h awk NR 6 print 4 2 获取当前机器ip地址 ifconfig awk NR 2 print 2 3
  • 终止for循环的方式

    continue break return 1 continue 当程序运行到 continue 语句时 会终止当前的这一次循环 进入下一次的循环中 它 适用于所有的循环结构 for int i 0 i lt 10 i 执行内容 conti
  • stm32F103C8T6 keil5编译完成使用XCOM进行串口打印时乱码

    一 检查波特率 串口调试工具和main c的串口初始化一定要相同 二 检查编码格式 第一步 点击keil5的小扳手图标 修改为Chinese GB2312 Simplified 这样一来 代码的中文就可以显示出来啦 第二步 XCOM这款串口
  • 安装Visio 2013与原本的office冲突的最终解决方案

    一 下载office visio 2013 二 开始安装 但是提示卸载原本的office 三 网上找寻答案 于是按照这篇文章https jingyan baidu com article 19192ad8c1d6dae53e570735 h
  • HashMap常用API及注意事项

    map clear map size map isEmpty map containsKey 判断 map containsValue map get key map put key value map putAll otherMap ma
  • ubuntu18.04安装cmake3.18.0

    ubuntu18 04安装cmake3 18 0 1 本方法可适用安装任何版本的cmake 可以在官网中找到需要的版本 本文以3 18 0为例 https cmake org files 2 wget https cmake org fil
  • Javaweb和微信小程序项目部署阿里云服务器总结(上)

    谈到微信小程序的java后台怎么部署在阿里云服务器上的问题 弯弯绕绕 好多坑 网上的博客资料也特别乱 博主也是在没有任何经验和指导下花了几天的工夫才完成的 这里为了方便大家不踩坑 总结了下整个流程和注意事项 由于篇幅原因 只讲重点的地方 所
  • 软件测试(3)——白盒测试

    文章目录 白盒测试 白盒测试方法 静态测试 人工代码检查 软件度量 其它方法 动态测试 覆盖测试分析 运行时错误检测 覆盖测试 逻辑覆盖方法 路径测试 数据流测试 白盒测试 白盒测试也称结构性测试 逻辑驱动测试 基于程序的测试 特点 将程序
  • Android App开机自启动

    最近项目中 有用到开机自启动的功能 这里做一下总结 供大家学习探讨 Android 开机启动延迟问题 Android 开机自启动被拦截问题 实战演练 测试手机 红米手机 Redmi 6A 安卓version 9 华为手机 DUA AL00
  • vs2010 vs2013等vs中如何统计整个项目的代码行数

    vs2010 vs2013等vs中如何统计整个项目的代码行数 在一个大工程中有很多的源文件和头文件 我如何快速统计总行数 解决方案 b b b b ctrl shift F 查找选项选 正则表达式 具体步骤 1 鼠标停靠在你的项目解决方案附
  • ERRORS: auth.User.groups: (fields.E304) Reverse accessor for ‘User.groups‘ clashes with reverse acce

    写博客网站后台 设计数据库结构时 博客 Article 表中定义了一个作者外键 author models ForeignKey settings AUTH USER MODEL verbose name 作者 这个外键是网站注册用户 这样
  • Oracle数据库获取uuid函数

    Oracle新建系统表时 要求主键为32位uuid 猜测Oracle肯定会提供相关的函数 翻阅相关文档 果然发现Oracle提供的函数 sys guid 用于获取32位uuid 简单使用为 select sys guid from dual
  • 【Linux内核中的并发控制】- 自旋锁

    在内核中会经常看到spin lock 自旋锁 它到底是个神马东西 在驱动相关的书籍和论坛中查阅了不少资料 看的也是云里雾里 现在将知识罗列总结一下 便于日后回顾 1 自旋锁定义 在Linux内核并发控制中最常见的锁就是自旋锁 自旋锁最多只能
  • POJ 1302 Blue Gene, Jr.(递归实现)

    Inspired by IBM s Blue Gene project the CEO of Universal Biological Machinery UBM has called on you UBM s top software e