zoj 2886 Look and Say
Look and Say
Time Limit: 2 Seconds Memory Limit: 65536 KB
The look and say sequence is defined as follows. Start with any string of digits as the first element in the sequence. Each subsequent element is defined from the previous one by "verbally" describing the previous element. For example, the string 122344111 can be described as "one 1, two 2's, one 3, two 4's, three 1's". Therefore, the element that comes after 122344111 in the sequence is 1122132431. Similarly, the string 101 comes after 1111111111. Notice that it is generally not possible to uniquely identify the previous element of a particular element. For example, a string of 112213243 1's also yields 1122132431 as the next element.
Input
The input consists of a number of cases. The first line gives the number of cases to follow. Each case consists of a line of up to 1000 digits.
Output
For each test case, print the string that follows the given string.
Sample Input
3
122344111
1111111111
12345
Sample Output
1122132431
101
1112131415
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
string s;
cin >> n;
while(n--){
cin >> s;
int len = s.length();
int num = ;
for(int i = ; i < len - ; i++){
if(s[i] == s[i + ]){
num++;
} else {
cout << num << s[i];
num = ;
}
}
cout << num << s[len - ];
cout << endl;
}
//system("pause");
return ;
}
分析:很简单,需要注意的边界问题,当最后两个字符相等的时候,那么就没有输出最后几个相等字符的个数及字符,当最后两个字符不想的时候,则最后一个字符没有输出。
zoj 2886 Look and Say的更多相关文章
- ZOJ 2562 HDU 4228 反素数
反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- Closures闭包
//: Playground - noun: a place where people can play import UIKit /* 闭包 Swift ====> Closures Ruby ...
- redirect与forward的区别
文件名称:forward.jsp <html> <head><title> 跳转 </title> </head> <body> ...
- 在 Windows 7 中禁用IPv6协议/IPv6隧道
How to disable certain Internet Protocol version 6 (IPv6) components in Windows Vista, Windows 7 and ...
- 分层开发之C#分层
假如没有用分层开发,仔细分析三人的开发过程,很容易发现其中的问题: >三人排队式的轮番工作,花费的时间是三人工作时间之和. >后面开发的人基本都是要先花费时间熟悉前面人的代码,否则开发难以 ...
- vue在使用ajax获取数据时,两种方法(jquery和vue_resource)
@{ Layout = null;} <!DOCTYPE html> <html><head> <meta name="viewport ...
- jsonp对付同源策略
当 协议不同或者域名/ip不同或者端口号不同 , 都不算是同源 这时候 源生的ajax 就不能进行数据请求了 JSONP json with padding 在平时的开发中也发现了 ,当我们请求 ...
- 64位系统上32位进程拷贝文件到System32目录时的重定向
64位系统上,32位进程拷贝文件到"System32"目录时,会被文件系统重定向到"SysWOW64"目录 要禁用这种重定向,需要用到下面2个API: Wow6 ...
- 关于maven source1.5报错
是因为maven 默认是1.5编译的 <build>//加上这个配置,把编译给改掉试试 <pluginManagement> <plugins> <plugi ...
- DAX:New and returning customers
The New and Returning Customers pattern dynamically calculates the number of customers with certain ...
- 十分钟搭建App主流框架
搭建主流框架界面 0.达成效果 Snip20150904_5.png 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navi ...