您的位置:首页 > 其它

leetcode Count and Say

2015-05-13 15:30 225 查看
代码:

#include<iostream>
#include<string>
#include<vector>

using namespace std;

string countAndSay(int n)
{
string s = "1";
int i = 0;
while (--n > 0)
{
char c = s[0];
string b = "";
i = 0;
while (i < s.length())
{
i++;
int count = 1;
while (i<s.length()&&s[i] == c)
{
count++;
i++;
}
b = b + (char)(count + '0');
b = b + c;
if (i == s.length())
{
break;
}
c = s[i];
}
s = b;
}
return s;
}

int main()
{
cout << countAndSay(2) << endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: