解题思路:

A1  =  “A” 

A2  =  “ABA” 

A3  =  “ABACABA” 

A4  =  “ABACABADABACABA

根据规律,得到

      A2=A1+"B"+A1

     A3=A2 +"C"+A2

     A4=A3 +"D"+A3

    

注意事项:

参考代码:

#include <iostream>             

#include <string>             


using namespace std;

  //对应数字转对应字母---------------------------------------------------------------------------------------       

string conversion(int n) {

string str;

switch (n)

{

case 1: str = "A"; break;case 2: str = "B"; break;case 3: str = "C"; break;case 4: str = "D"; break;case 5: str = "E"; break;

case 6: str = "F"; break;case 7: str = "G"; break;case 8: str = "H"; break;case 9: str = "I"; break;case 10: str = "J"; break;

case 11: str = "K"; break;case 12: str = "L"; break;case 13: str = "M"; break;case 14: str = "N"; break;case 15: str = "O"; break;

case 16: str = "P"; break;case 17: str = "Q"; break;case 18: str = "R"; break;case 19: str = "S"; break;case 20: str = "T"; break;

case 21: str = "U"; break;case 22: str = "V"; break;case 23: str = "W"; break;case 24: str = "X"; break;case 25: str = "Y"; break;

case 26: str = "Z"; break;

}

return str;

}

//-----------------------------------------------------------------------------------------------------------

int main()                             

{


int n;//项数

cin >> n;

string *str = new string[n];

str[0] = "A";

int d=2;

for (int i = 1; i < n; i++) {

str[i] = str[i - 1] + conversion(d) + str[i - 1];

d++;

}

cout << str[n-1] << endl;//输出第n项字符串

delete[]str;//释放



return 0;

}       


点赞(0)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论