1140 Look-and-say Sequence(20 分)
Look-and-say sequence is a sequence of integers as the following:

D, D1, D111, D113, D11231, D112213111, ...

where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd number means that there is one D in the 1st number, and hence it is D1; the 2nd number consists of one D (corresponding to D1) and one 1 (corresponding to 11), therefore the 3rd number is D111; or since the 4th number is D113, it consists of one D, two 1's, and one 3, so the next number must be D11231. This definition works for D = 1 as well. Now you are supposed to calculate the Nth number in a look-and-say sequence of a given digit D.

Input Specification:
Each input file contains one test case, which gives D (in [0, 9]) and a positive integer N (≤ 40), separated by a space.

Output Specification:
Print in a line the Nth number in a look-and-say sequence of D.

Sample Input:

1 8

Sample Output:

1123123111

题意:
D是0到9中除1以外的数字。第n+1个数字是第n个数字的一种描述。举个例子,第二个数表示第一个数中只有一个D,因此为D1;第二个数由一个D(D1)和一个1(11)组成,因此第三个数是D111;第四个数是D113,它由一个D(D1),三个1(13)组成;下一个是D11231。
你被要求计算第n个数对于给定的D。

思路:
用一个vector接收。每一次从头开始遍历。
注意一下vector数组结尾时的数据也要进行保存。

题解:

 #include<cstdlib>
 #include<cstdio>
 #include<vector>
 using namespace std;
 int main() {
     int d, n;
     scanf("%d %d", &d, &n);
     vector<int> num;
     num.push_back(d);
     ; i < n; i++) {
         vector<int> temp;
         ];
         ;
         ; j < num.size(); j++) {
             if (num[j] == v) cnt++;
             else{
                 temp.push_back(v);
                 temp.push_back(cnt);
                 cnt = ;
                 v = num[j];
             }
             //如果到达结尾时,要最后一组数据进行push
             ) {
                 temp.push_back(v);
                 temp.push_back(cnt);
             }
         }
         num = temp;
     }
     ; i < num.size(); i++) {
         printf("%d", num[i]);
     }
     ;
 }

[PAT] 1140 Look-and-say Sequence(20 分)的更多相关文章

  1. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  2. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  3. PAT甲级:1152 Google Recruitment (20分)

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  4. PAT乙级:1072开学寄语(20分)

    PAT乙级:1072开学寄语(20分) 题干 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面 ...

  5. PAT乙级:1057 数零壹 (20分)

    PAT乙级:1057 数零壹 (20分) 题干 给定一串长度不超过 105 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一 ...

  6. PAT乙级:1082 射击比赛 (20分)

    PAT乙级:1082 射击比赛 (20分) 题干 本题目给出的射击比赛的规则非常简单,谁打的弹洞距离靶心最近,谁就是冠军:谁差得最远,谁就是菜鸟.本题给出一系列弹洞的平面坐标(x,y),请你编写程序找 ...

  7. PAT乙级:1084 外观数列 (20分)

    PAT乙级:1084 外观数列 (20分) 题干 外观数列是指具有以下特点的整数序列: d, d1, d111, d113, d11231, d112213111, ... 它从不等于 1 的数字 d ...

  8. PAT乙级:1063 计算谱半径 (20分)

    PAT乙级:1063 计算谱半径 (20分) 题干 在数学中,矩阵的"谱半径"是指其特征值的模集合的上确界.换言之,对于给定的 n 个复数空间的特征值 { a1+b1i,⋯,a** ...

  9. PAT 乙级 1044 火星数字 (20 分)

    1044 火星数字 (20 分) 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, j ...

  10. PAT 甲级 1041 Be Unique (20 分)

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

随机推荐

  1. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

  2. PHP检测json格式数据

    首先要记住json_encode返回的是字符串, 而json_decode返回的是对象 判断数据不是JSON格式: 复制代码代码如下: function is_not_json($str){      ...

  3. finetune on caffe

    官方例程:http://caffe.berkeleyvision.org/gathered/examples/finetune_flickr_style.html 相应的中文说明:http://blo ...

  4. 《python核心编程》读书笔记--第18章 多线程编程

    18.1引言 在多线程(multithreaded,MT)出现之前,电脑程序的运行由一个执行序列组成.多线程对某些任务来说是最理想的.这些任务有以下特点:它们本质上就是异步的,需要多个并发事务,各个事 ...

  5. Educational Codeforces Round 6 B

    B. Grandfather Dovlet’s calculator time limit per test 1 second memory limit per test 256 megabytes ...

  6. 树莓派搭建LAMP,然后更改根目录

    参考网页: http://shumeipai.nxez.com/2013/10/13/install-and-config-lamp.html http://blog.csdn.net/zzuzadz ...

  7. [iptables]iptables日志记录

    Mar :: kernel: [:] IN=eth1 OUT= MAC=f0:1f:af:da:6f:1e::fb::ae:fa::: SRC= TOS= ID= DF PROTO=TCP SPT= ...

  8. ACM2066

    题目原址:http://acm.hdu.edu.cn/showproblem.php?pid=2066 大神必须飘过,我在这个题目里面学到了太多太多了.我提交了十六次,错了十二次,反复了这么久才解决内 ...

  9. getQueryString----获取url中得参数

    /** * 获取url中得参数 * @param name * @returns {null} */ window.getQueryString = function (name) { var reg ...

  10. [LeetCode] 数组的最长连续数, O(n)解法

    Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...