移动字母(PTA-武理-C实验)

本题要求编写函数,将输入字符串的前3个字符移到最后。
函数接口定义:
void Shift( char s[] );

其中char s[]是用户传入的字符串,题目保证其长度不小于3;函数Shift须将按照要求变换后的字符串仍然存在s[]里。
裁判测试程序样例:
#include <stdio.h>
#include <string.h>

#define MAXS 10

void Shift( char s[] );

void GetString( char s[] ); /* 实现细节在此不表 */

int main()
{
char s[MAXS];

GetString(s);
Shift(s);
printf("%s\n", s);

return 0; 

}

/* 你的代码将被嵌在这里 */

输入样例:
abcdef

输出样例:
defabc

void Shift( char s[] )
{
   
    int i,j;char a[3];
    for(i=0;i<3;i++)
        a[i]=s[i]
  • 3
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集 PTA-数据结构与算法题目集
好的,我理解了你的问题。那么,pta7-5 特殊堆栈的 C 语言实现如下: ```c #include <stdio.h> #include <stdlib.h> #define MAX_SIZE 100 // 定义特殊堆栈结构体 struct SpecialStack { int data[MAX_SIZE]; // 堆栈数据 int min[MAX_SIZE]; // 堆栈中的最小值 int top; // 堆栈顶部指针 }; // 初始化特殊堆栈 void initStack(struct SpecialStack *stack) { stack->top = -1; } // 判断特殊堆栈是否为空 int isEmpty(struct SpecialStack *stack) { return stack->top == -1; } // 判断特殊堆栈是否已满 int isFull(struct SpecialStack *stack) { return stack->top == MAX_SIZE - 1; } // 向特殊堆栈中添加元素 void push(struct SpecialStack *stack, int item) { if (isFull(stack)) { printf("特殊堆栈已满,无法添加元素!\n"); return; } // 添加元素到堆栈中 stack->data[++stack->top] = item; // 更新最小值 if (stack->top == 0) { stack->min[stack->top] = item; } else { int min = stack->min[stack->top - 1]; stack->min[stack->top] = item < min ? item : min; } } // 从特殊堆栈中弹出元素 int pop(struct SpecialStack *stack) { if (isEmpty(stack)) { printf("特殊堆栈为空,无法弹出元素!\n"); return -1; } // 取出堆栈顶部元素 int item = stack->data[stack->top--]; // 更新最小值 stack->min[stack->top + 1] = 0; return item; } // 获取特殊堆栈中的最小值 int getMin(struct SpecialStack *stack) { if (isEmpty(stack)) { printf("特殊堆栈为空,无法获取最小值!\n"); return -1; } return stack->min[stack->top]; } // 测试函数 int main() { // 创建特殊堆栈 struct SpecialStack stack; initStack(&stack); // 向特殊堆栈中添加元素 push(&stack, 3); push(&stack, 5); push(&stack, 2); push(&stack, 1); // 获取特殊堆栈中的最小值 printf("特殊堆栈中的最小值为:%d\n", getMin(&stack)); // 弹出特殊堆栈中的元素 printf("特殊堆栈中的元素依次为:"); while (!isEmpty(&stack)) { printf("%d ", pop(&stack)); } printf("\n"); return 0; } ``` 以上是特殊堆栈的 C 语言实现代码,你可以根据需要进行修改、调试和运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值