FJ的字符串 【字符串模拟】

FJ的字符串

Description

FJ在沙盘上写了这样一些字符串:  A1 = “A”  A2 = “ABA”  A3 = “ABACABA”  A4 = “ABACABADABACABA”  … …  你能找出其中的规律并写所有的数列AN吗?

Input

仅有一个数:N ≤ 26。

Output

请输出相应的字符串AN,以一个换行符结束。输出中不得含有多余的空格或换行、回车符。

Sample Input 1 

3

Sample Output 1

ABACABA

 解析:get新技能,将 char 转换成 string。


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    string st = "";
    for(int i = 1; i <= n; i ++)
    {
        string tp = st;
        char  xx = (char)((int)'A' + i - 1);
        string str;
        stringstream stream;
        stream << xx;
        str = stream.str();
        st += str;
        st += tp;
    }
    cout << st << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Mercury_Lc/article/details/107144722
今日推荐