#include <stdio.h>
#include <stdlib.h>
int inverse(int n);
int main()
{
int n;
scanf("%d",&n);
while( n != inverse(n))
{
printf("%d ",n);
n += inverse(n);
}
printf("%d ",n);//最后一个数字需要补上
return 0;
}
int inverse(int n)
{
int a,b;
a = 0;
b = 0;
while( n != 0)
{
a = n%10;
b = (a+b)*10;
n = n/10;
}
b /= 10;
return b;
}
#include "queue.h"
typedef int datatype;
#define maxnum 20
struct SeqQueue{
datatype f,r;//头跟尾
datatype q[maxnum];//数组长度
};
typedef struct SeqQueue *PSequeue;//重定义结构体
//创建空队列
PSequeue creatEmptyQueue(void){
PSequeue qu=(PSequeue)malloc(sizeof(struct SeqQueue));//顺序队列所指的是对应的元素的位置下标,不是值
if (qu==NULL)
{
printf("out of space");
}
else
{
qu->f=qu->r=0;
return qu;
}
}
//判断队列是否为空
int isEmptySqueue(PSequeue qu){
return qu->f==qu->r;//队尾=队头,则队列为空
}
//在队列中插入某一个元素
void insertQueue(PSequeue qu,datatype x){
//首先判断队列是否已满
if ((qu->r+1)%maxnum==qu->f)
{
printf("full queue");
}
else
{ //尾进头出
qu->q[qu->r]=x;//x插入当前队尾所指的位置
qu->r=(qu->r+1)%maxnum;//循环队列的长度加一
}
}
//返回队列元素的个数
int queuenumber(PSequeue qu){
int count=0;
if (isEmptySqueue(qu))
{
printf("queue is empty");
}
else{
count=qu->r;
}
return count;
}
//删除队列头部元素
void deleteQueue(PSequeue qu){
//首先判断队列是否已空
if (isEmptySqueue(qu))
{
printf("queue is empty");
}
else
{
qu->f=qu->f+1;//使队头的下一个结点成为队头,那么当前的队头就出队了
}
}
//对于非空队列,求队头元素
datatype topQueueElement(PSequeue qu){
return qu->q[qu->f];//返回队头指向的当前元素
}
//判断队列是否已满
int isFullQueue(PSequeue qu){
return (qu->r+1)%maxnum==qu->f;//队尾加一等于队头,则满
}
//主函数
void main(){
PSequeue queue=creatEmptyQueue();
Pointstack newstack=createEmpty_stack();
char letter;
int count=0,i;
printf("input string:\n");
scanf("%c",&letter);
while(letter!='\n'){
insertQueue(queue,letter);//入队
pushElement_stack(newstack,letter);//进栈
scanf("%c",&letter);
count++;
}
for (i=0;i<(count/2);i++)
{
if (ElementStackTop(newstack)==topQueueElement(queue))
{
printf("是回文数\n");
break;
}
else
{
printf("不是回文数\n");
break;
}
}
}
#include<stdio.h>
typedef long DATA_TYPE;
typedef unsigned char boolean;
#define TRUE 1
#define FALSE 0
#define MAXSIZE 100
typedef struct SQ_LIST{
DATA_TYPE data[MAXSIZE];
int count;
}LIST;
void initList(LIST *head);
void appendListElement(LIST *head, DATA_TYPE value);
void showList(LIST list);
DATA_TYPE reverse(DATA_TYPE x);
boolean isPalindrome(DATA_TYPE x);
boolean isPalindrome(DATA_TYPE x){
DATA_TYPE y;
y = reverse(x);
if(y == x){
return TRUE;
}else{
return FALSE;
}
}
DATA_TYPE reverse(DATA_TYPE x){
DATA_TYPE y = 0;
DATA_TYPE tmp = x;
while(tmp){
y = tmp%10 + y*10;
tmp/=10;
}
return y;
}
void showList(LIST list){
int i;
printf("当前顺序表中的元素为:");
for(i = 0; i < list.count; i++){
printf("%d ", list.data[i]);
}
printf("\n");
}
void appendListElement(LIST *head, DATA_TYPE value){
head->data[head->count++] = value;
}
void initList(LIST *head){
head->count = 0;
}
void main(void){
LIST list;
DATA_TYPE x = 55;
DATA_TYPE y;
initList(&list);
printf("请输入一个正整数:");
scanf("%d", &x);
appendListElement(&list, x);
if(isPalindrome(x)){
appendListElement(&list, x);
}else{
y = x + reverse(x);
appendListElement(&list, y);
if(isPalindrome(y))
while(!isPalindrome(y)){
y = y + reverse(y);
appendListElement(&list, y);
}
}
showList(list);
}