Rhythmli's blog Rhythmli's blog
首页
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Rhythmli

知识就是财富
首页
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 技术文档

  • GitHub技巧

  • Nodejs

  • 博客搭建

  • CSDN迁移

    • Spring IOC
    • Ngnix 阿里云
    • 最长回文子串
    • 面试题xuexixiexue
    • 哈希集合和哈希映射的简单设计
    • leetcode2021.11.03
    • Leetcode2021.11.2
    • JUC学习
    • 869. 重新排序得到 2 的幂
    • Java自动装箱拆箱
    • 55. 跳跃游戏
    • 剑指 Offer II 085. 生成匹配的括号
    • 300. 最长递增子序列
    • Java并发编程之美 01
    • 134. 加油站
    • 139. 单词拆分
    • 岛屿类问题题解
    • 138. 复制带随机指针的链表
    • 347. 前 K 个高频元素
    • 剑指 Offer II 026. 重排链表
    • 剑指 Offer II 025. 链表中的两数相加
    • 剑指 Offer II 014. 字符串中的变位词
    • 剑指 Offer II 010. 和为 k 的子数组
    • 剑指 Offer II 009. 乘积小于 K 的子数组
    • 剑指 Offer II 008. 和大于等于 target 的最短子数组
    • 剑指 Offer II 007. 数组中和为 0 的三个数
    • 剑指 Offer II 006. 排序数组中两个数字之和
    • 剑指 Offer II 002. 二进制加法
    • 129. 求根节点到叶节点数字之和
    • 113.路径总和 II
    • leetcode18. 四数之和
    • 编译OpenCV 以及 openc_contrib 提示缺少boostdesc_bgm.i文件出错的解决
    • fork()浅学习
    • SSM 增删改查
    • springmvc helloworld
    • Spring01 hello实验
    • 树的DFS和BFS
    • leetcode——二分法
    • Halo博客搭建
    • 计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接---转载
    • opencv+python+OpenPose姿态实时识别
    • 03.KNN算法 李航统计学习方法
    • 02.感知机 李航统计学习方法
    • 01.最小二乘法拟合 李航统计学习方法
    • Pycharm atplotlib.pyplot图像不显示解决方法
    • 论文阅读01 SVM+kNN图像分类
    • Java简单实现计算器——用数组实现栈
    • 【剑指Offer3】无重复字符的最长子串
    • 【剑指Offer5】最长回文字符串
    • TF-IDF求取文本相似度
    • JAVA_day02
    • JAVA_day01
    • 递归产生回文数
      • 递归产生回文数
    • 中国象棋QT登录注册以及悔棋功能
    • STM32F4学习笔记(基础介绍篇)
    • leetcode_04 递归,回溯与分治
    • leetcode03_贪心算法
    • leetcode01--链表
    • leetcode_02栈
    • Docker学习入门
    • C/C++编译与链接 程序员的自我修养:链接 装载和库
    • Nginx简单学习
    • JAVA网络编程
    • JVM初步学习
    • Spring简单学习
    • 标准项目格式
    • 设计模式中的几个原则
    • Redis和IDEA简单创建及增删改查
    • Mybatis快速入门01
    • Redis全程学习笔记(附带学习的视频教程)
    • QT入门学习中最基础的那些事儿
    • QT中文输出错误问题:C2001
    • OOP:面向对象编程
    • LINUX常用命令集合(待续)
    • 《C和指针》简单学习笔记
    • 二叉树,栈存储及遍历小程序
    • 数据结构简单学习笔记
    • 扑克牌
    • C++动态内存和智能指针
    • 设计模式之简单工厂模式
    • leetcode_01数组
    • 嵌入式Linux移植应用
    • LINUX 进程与线程 信号量 通信
  • 技术
  • CSDN迁移
梁山话事人
最新推荐文章2026-06-20
目录

递归产生回文数

原文链接:https://blog.csdn.net/qq_39355828/article/details/116008026 (opens new window)

# 递归产生回文数

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kXpJUbME-1619063964580)(C:\Users\123\AppData\Roaming\Typora\typora-user-images\1618797823638.png)]

回文数 包括小写字母的随机产生,大写字母的随机产生,首先显示一个菜单,然后选中需要产生的回文数市数字,小写英文,还是大写英文,进而输入产生的回文数的长度。

// Program RollDice.cpp
// This program demonstrates using random numbers
// to simulate rolling dice.

#include <iostream>
#include <cstdlib>   // rand and srand
#include <ctime>     // For the time function
using namespace std;
void Intfunc(int n);
void showMenu();
void Upperfunc(int n);
void Intfunc1(int n);
void Upperfunc1(int n);
void Lowerfunc1(int n);
void Lowerfunc(int n);
void delay_sec(int sec);
int main()
{  int length,choice;
   int ADULT_CHOICE=1;
   int QUIT_CHOICE=4;
   int m;
   do
   {
      // Display the menu and get the user's choice.
      showMenu();
      cin >> choice;

      // Validate the menu selection.
      while (choice < ADULT_CHOICE || choice > QUIT_CHOICE)
      {  cout<<choice;
         cout << "is not a valid choice!\n";
         cout<<  "Please enter a number from 1 to 4.\n";
         cout<<"Your choice?";
         cin >> choice;
      }

      // If the user does not want to quit, proceed.
      if (choice != QUIT_CHOICE)
      {   cout<<"How long would you like your palindrome to be?";
          cin>>length;
          while (length < 0)
        {

         cout<<  "Please enter a length grater than 0!\n";
         cout<<"Your length?";
         cin >> length;
        }
          cout<<"\nGenerating your palindrome...\n";
          if(choice==1)
          {
          	  if(length%2==1)
               {
                 m=length/2+1;
                 Intfunc1(m);
			   }
               if(length%2==0)
                {
                m=length/2;
                Intfunc(m);
				}
		  }
		   if(choice==2)
          {
          	  if(length%2==1)
               {
                 m=length/2+1;
                 Upperfunc(m);
			   }
               if(length%2==0)
                {
                m=length/2;
                Upperfunc1(m);
				}
		  }
		   if(choice==3)
          {
          	  if(length%2==1)
               {
                 m=length/2+1;
                 Lowerfunc(m);
			   }
               if(length%2==0)
                {
                m=length/2;
                Lowerfunc1(m);
				}
		  }

      }
   } while (choice != QUIT_CHOICE);
   cout<<"Thanks for using my palindrome generator!!"<<endl;
   cout<<"Come back soon!"<<endl;

   return 0;

}
void showMenu()
{  cout<<"\n------------------------------------"<<endl;
   cout << "Welcome to the palindrome generate!\n\n"
        <<"------------------------------------\n"
        <<"Choose the type of palindrome you'd like to generate\n"
        <<"from the menu below,or choose 4 to qiut the program.\n"
        << "1) Digits\n"
        << "2) Uppercase letters\n"
        << "3) Lowercase letters\n"
		<<"4) Quite program\n"
		<<"\n------------------------------------\n"
        << "Your choice?  ";
}
void Intfunc(int n)//even number
{
	unsigned int seed = (unsigned int)(time(0));

   // Seed the random number generator.
   srand(seed);

   // Get some die values.
   int value = rand() % 9 + 1;
   //Sleep(1000);
   delay_sec(5);
   if(n==1)
   {
   	printf("%d",value);
   	printf("%d",value);
   }
   else
   {
   	  printf("%d",value);
   	  Intfunc(n-1);
   	  printf("%d",value);
   }
}
void Intfunc1(int n)//odd number
{
	unsigned int seed = (unsigned int)(time(0));

   // Seed the random number generator.
   srand(seed);

   // Get some die values.
   int value = rand() % 9 + 1;
delay_sec(5);
   if(n==1)

   printf("%d",value);

   else
   {
   	  printf("%d",value);
   	  Intfunc1(n-1);
   	  printf("%d",value);
   }
}
void Upperfunc(int n)//A B C odd number
{
	unsigned int seed = (unsigned int)(time(0));
    int MAX_VALUE=90;
    int MIN_VALUE=65;
   // Seed the random number generator.
   srand(seed);
   int value= (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
   // Get some die values.
   //int value = rand() % 9 + 1;
   delay_sec(5);
   if(n==1)
   printf("%c",value);
   else
   {
   	  printf("%c",value);
   	  Upperfunc(n-1);
   	  printf("%c",value);
   }
}
void Upperfunc1(int n)//A B C even number
{
	unsigned int seed = (unsigned int)(time(0));
    int MAX_VALUE=90;
    int MIN_VALUE=65;
   // Seed the random number generator.
   srand(seed);
   int value= (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
   // Get some die values.
   //int value = rand() % 9 + 1;
   delay_sec(5);
   if(n==1)
   {
   	printf("%c",value);
   	printf("%c",value);
   }
   else
   {
   	  printf("%c",value);
   	  Upperfunc1(n-1);
   	  printf("%c",value);
   }
}
void Lowerfunc(int n)//odd number
{
	unsigned int seed = (unsigned int)(time(0));
    int MAX_VALUE=122;
    int MIN_VALUE=97;
   // Seed the random number generator.
   srand(seed);
   int value= (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
   // Get some die values.
   //int value = rand() % 9 + 1;
   delay_sec(5);
   if(n==1)
   printf("%c",value);
   else
   {
   	  printf("%c",value);
   	  Lowerfunc(n-1);
   	  printf("%c",value);
   }
}
void Lowerfunc1(int n)//even number
{
	unsigned int seed = (unsigned int)(time(0));
    int MAX_VALUE=122;
    int MIN_VALUE=97;
   // Seed the random number generator.
   srand(seed);
   int value= (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
   // Get some die values.
   //int value = rand() % 9 + 1;
   delay_sec(5);
   if(n==1)
   {
   	printf("%c",value);
   	printf("%c",value);
   }
   else
   {
   	  printf("%c",value);
   	  Lowerfunc1(n-1);
   	  printf("%c",value);
   }
}

void delay_msec(int msec)
{
 clock_t now = clock();
 while(clock()-now < msec);
}

void delay_sec(int sec)//
{
 time_t start_time, cur_time;
 time(&start_time);
 do
 {
  time(&cur_time);
 } while((cur_time - start_time) < sec);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

需要注意:随机数的产生和系统的时间有关系,随机数时间如果相邻太短,则相对的时间太少,产生的随机数可能会一致,因此考虑使用延时函数

编辑 (opens new window)
#C++#订阅专栏#查看详情
上次更新: 2026/08/11, 13:36:18
JAVA_day01
中国象棋QT登录注册以及悔棋功能

← JAVA_day01 中国象棋QT登录注册以及悔棋功能→

最近更新
01
Spring IOC
03-31
02
Git修改分支名
08-11
03
CSS给table的tbody添加滚动条
06-29
更多文章>
Theme by Vdoing | Copyright © 2019-2026 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式