当前位置: 首页 > news >正文

个人学习编程(3-10) 刷题

逆序字符串

如果是对于输入的字符串

char s[100]; // 用来存储用户输入的字符串

printf("请输入一个字符串: ");

scanf("%s", s); // 获取用户输入的字符串

#include <stdio.h>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
int main() {char s[] = "i like laoda";int len = 0;len = strlen(s);int i;char temp;for (int i = 0; i < len/2; i++){temp = s[i];s[i] = s[len-i-1];s[len-i-1] = temp;}printf("%s",s);return 0;    
}

 指针解法:

#include <stdio.h>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
int main() {char s[] = "i like laoda";int len = 0;char *p = s;while (*p != '\0'){len++;p++;}//printf("len=%d\n",len);int i;char temp;for (i = 0; i < len/2; i++){temp = *(s+i);*(s+i) = *(s+len-i-1);*(s+len-i-1) = temp;}printf("%s\n",s);return 0;    
}

递归算年龄

第五个人说比第四个人大两岁

第四个人说比第三个人大两岁

第三个人说比第二个人大两岁

第二个人说比第一个人大两岁

第一个说他十岁,问第五个人多大?

#include <stdio.h>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;int age(int n){int c = 0;if (n == 1){c = 10;}else{c = age(n-1) + 2;printf("c = %d\n", c);}return c;}
int main() {int age(int n);printf("age(5)=%d\n",age(5));return 0;    
}


http://www.mrgr.cn/news/93929.html

相关文章:

  • Jetson Orin 安装 onnxruntime
  • LSTM方法实践——基于LSTM的汽车销量时序建模与预测分析
  • 基金股票期权期货投资方式对比
  • 软考 数据通信基础——信道
  • 【SoC基础】第2节:CPU简介
  • DeepSeek本地化部署与跨域访问架构构建
  • ngx_regex_create_conf
  • 多视图几何--相机标定--从0-1理解张正友标定法
  • 【Go每日一练】统计字符出现的次数
  • Nuxt.js 全栈开发指南:构建现代 Web 应用的终极解决方案
  • 【09】单片机编程核心技巧:变量赋值,从定义到存储的底层逻辑
  • 最大括号深度
  • 一二三应用开发平台——能力扩展:多数据源支持
  • 「string」笔记
  • 优选算法系列(1. 双指针_上)
  • Trae IDE:解锁 AI 驱动的高效编程体验
  • [Java]使用java进行JDBC编程
  • 【追根溯源】在数电中脉冲波形的产生和整形电路
  • 数学之快速幂-数的幂次
  • el-pagination的使用说明