沐里纷纷


私信TA

用户名:Epoch

访问量:62719

签 名:

我不会算法

等  级
排  名 37
经  验 12805
参赛次数 1
文章发表 172
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

不会算法

解题思路:

注意事项:

参考代码:

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

char A[27] = {'\0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

int main()
{
    int n = 0;
    cin >> n;
    if(n == 1)
        cout << 'A' << endl;
    else
    {
        int i = 2;
        string str = "A";
        while (i <= n) {
            str = str + A[i] + str;
            i++;
        }
        cout << str << endl;
    }
    return 0;
}

【思路二】
#include <iostream>
#include <string>
using namespace std;

string Fun(int n)
{
	string N;
	N = 'A' + n - 1;
	string ans;
	if(n == 1) 
		return N;
	else
	{
		ans = Fun(n - 1);
		return ans + N + ans;
	}
}

int main(void)
{
	int n;
	cin >> n;
	cout << Fun(n) << endl;
	return 0;
	
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区