POJ 3438:Look and Say
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 9196 | Accepted: 5566 |
Description
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
Output
Sample Input
3
122344111
1111111111
12345
Sample Output
1122132431
101
1112131415
洪水题,看着读这个数,再输出。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; string s; void solve()
{
int i,j;
int len=s.length(); for(i=0;i<len;i++)
{
int result=1;
for(j=i+1;j<len;j++)
{
if(s[j]==s[i])
{
result++;
}
else
{
break;
}
}
cout<<result<<s[i];
i=i+result-1;
}
cout<<endl;
} int main()
{
int Test;
cin>>Test; while(Test--)
{
cin>>s;
solve();
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3438:Look and Say的更多相关文章
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- POJ 3436:ACM Computer Factory(最大流记录路径)
http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...
- POJ 2195:Going Home(最小费用最大流)
http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...
- POJ 3281:Dining(最大流)
http://poj.org/problem?id=3281 题意:有n头牛,f种食物,d种饮料,每头牛有fnum种喜欢的食物,dnum种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种 ...
- POJ 3580:SuperMemo(Splay)
http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...
- POJ 3237:Tree(树链剖分)
http://poj.org/problem?id=3237 题意:树链剖分.操作有三种:改变一条边的边权,将 a 到 b 的每条边的边权都翻转(即 w[i] = -w[i]),询问 a 到 b 的最 ...
- POJ 2763:Housewife Wind(树链剖分)
http://poj.org/problem?id=2763 题意:给出 n 个点, n-1 条带权边, 询问是询问 s 到 v 的权值, 修改是修改存储时候的第 i 条边的权值. 思路:树链剖分之修 ...
随机推荐
- MQ的调用
mq调用(相关dll) using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Collecti ...
- c# GlobalAddAtom GlobalDeleteAtom
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- centos7安装google-chrome和chromedriver
1.root用户下进入到etc/yum.repos.d目录下 [root@f7d6b9f2-1291-4d2f-8805-aef94deac9f7 yum.repos.d]# pwd /etc/y ...
- Window Server 2019 配置篇(3)- 建立hyper-v集群并在其上运行win10 pro虚拟机
上次讲到我们的域里有了网关跟DHCP,这次我们要在域中建立hyper-v集群并在其上运行win10 pro虚拟机 那么什么是hyper-v集群呢? 就是两个及两个以上的运行hyper-v服务的服务器建 ...
- springBoot (适合ssm)
很多小白在学ssm的时候,选用idea,网上应该有很多教程,创建maven项目,创建spring项目的都有,五花八门. 最近接触了springBoot,这个项目类型适用于ssm,还不用去创建很多文件夹 ...
- arduino 通过串口接收string,int类型数据
串口接收string类型数据源码如下 String comdata = ""; void setup() { Serial.begin(9600); } void lo ...
- MongoDB 副本集搭建
搭建mongodb副本集 [root@ mongodb]# cd /u02 [root@ u02]# mkdir -p mongodb/data_2777 [root@ u02]# mkdir -p ...
- tomcat以服务形式开机启动
第一步 将tomcat配置为服务模式 cp $TOMCAT_HOME/bin/catalina.sh /etc/init.d/tomcat #将tocmt启动文件复制到/etc/init.d下 vim ...
- 九十二、SAP中ALV事件之六,复制一个标准工具栏到自己的程序
一.我们来到SE41,点击复制状态按钮 二.点击复制状态后,弹出一个框框,上面是模板内容,下面是我们自己的程序 三.我们根据上一篇的标准模板内容,填好相应的模板和我们的程序的内容 三.点击复制按钮 五 ...
- 029-PHP取随机数
<?php //打印从1到100中间的10个随机的数 ; $index < ; $index++) { print(rand(,) . "<BR>\n"); ...