A1140 Look-and-say Sequence
用string操作很方便,沒什麼坑點,看懂題意就行了。主要就是統計連續的一片區域有幾個連續的數字。
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
string now,next;
int n;
cin>>now>>n;
while(--n){
//cout<<now<<endl;
next = "";
for(int i=0;i<now.length();){
char temp = now[i];
int cnt = 0;
while(now[i]==temp&&i<now.length()){
cnt++;
i++;
}
char num = '0'+cnt;
next += temp;//這兩個+要分開寫因為temp+num會程式設計另外一個char字元
next += num;
}
now = next;
}
cout<<now;
return 0;
}
相關推薦
A1140 Look-and-say Sequence
用string操作很方便,沒什麼坑點,看懂題意就行了。主要就是統計連續的一片區域有幾個連續的數字。 #include <stdio.h> #include <string> #include <iostream> using namespace std
1140 Look-and-say Sequence (20)
-s gin win div CI clu TP include pan Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D1122
1140 Look-and-say Sequence(20)
//將每個不同的字元存入,初始字元後面的個數為1, //之後下一個時判斷是否去前一個字元相同,相同則個數++; //不同的將新字元存入,並且個數初始為1。 #include <cstdio> #include <cstring> int main() { char s
PAT 1140 Look-and-say Sequence [比較]
1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D
pta 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. T
1140 Look-and-say Sequence (20 分)(cj)
1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D11221311
【笨方法學PAT】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,
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] excep
Look And Say 序列 php
Look and say 序列,因為每個元素通過檢視前一個元素並說出其中是什麼得來的。例如:檢視第一個元素 1 ,你會說 “一個 1”,所以第二個元素就是 “11”。這就是兩個 1 ,所以第三個元素是 “21”。類似的,這裡有一個 2 和一個 1 ,所以第四個元素是 “1211”,以此類
38. Count and Say
integer ive output while each int result first seq The count-and-say sequence is the sequence of integers with the first five terms as f
[Leetcode] count and say 計數和說
str 一個 實現 當前 ger repr begin lee http The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221,
leetcode-38 Count And Say
pop -m seq rac note 不變 article ger else 問題描寫敘述: The count-and-say sequence is the sequence of integersbeginning as follows: 1, 11,
LeetCode 38: Count and Say
log mat rate and style valueof dsa blog res class Solution { public String countAndSay(int n) { if (n == 0) { re
codeforces 894C - Marco and GCD Sequence - [有關gcd數學題]
mes when section got 操作 positive ive cin style 題目鏈接:https://cn.vjudge.net/problem/CodeForces-894C In a dream Marco met an elderly man wit
LeeCode from 0 ——38. Count and Say
urn ++ temp ont RM fir IT The family 38. Count and Say The count-and-say sequence is the sequence of integers with the first five terms a
Jamie and Binary Sequence (changed after round) - CodeForces 916B
con tdi chang ren second ack pan else tar http://codeforces.com/problemset/problem/916/B 好尬啊。。。 1 #include<cstdio> 2 #includ
38. Count and Say 題目解釋
註意 ron 輸出 n-1 tail .net -a 字符 描述 初看題目很迷,Google看了各大神的解釋,才明白 原題連接:https://leetcode.com/problems/count-and-say/description/ 題目解釋:原題的意思就是用一個
[LeetCode] 38. Count and Say 計數和讀法
相同 output for ews represent class urn present count The count-and-say sequence is the sequence of integers with the first five terms as f
【算法】LeetCode算法題-Count And Say
對象 nds iou 得到 eas for 結果 支持 amp 這是悅樂書的第153次更新,第155篇原創 01 看題和準備 今天介紹的是LeetCode算法題中Easy級別的第12題(順位題號是38)。count-and-say序列是整數序列,前五個術語如下: 1 11
LeetCode-38. Count and Say
0.原題 The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5.