C三道题
来源:互联网 发布:la域名在哪注册 编辑:程序博客网 时间:2024/06/05 00:34
1、写一函数int fun(char *p)判断一字符串是否为回文,是返回1,不是返回0,出错返回-1.(例如:字符串”123454321”就是回文字符串)
# include <stdio.h># include <string.h>int fun(char *p) { int len = strlen(p) - 1; //查看字符串长度 char *q = p+len; //定义指针q指向字符串的结尾 while(p<q) { if ((*p++) != (*q--)) //将字符串数值逐一比较 return 0; } if (*p == *q) return 1; else return -1; } int main(void) { char a[] = "12321"; printf("%d\n", fun(a)); return 0; }
2、假设现有一个单向的链表,但是只知道只有一个指向该节点的指针p,并且假设这个节点不是尾节点,试编程实现删除此节点。
节点结构:struct node
{
int data;
struct node *p_next;
};
3、Write a function string reverse string word By word(string input) that reverse a string word by word.
For instance:
“The house is blue” –> “blue is house The”
“Zed is dead” –>”dead is Zed”
“All-in-one” –> “one-in-All”
在不增加任何辅助数组空间的情况下,完成function
字符串中每个单词(子串)的逆序
#include <stdio.h>void fun(char *str){ char *head = str; //记录头指针 while (*str++ != 0); //指向\0后一个位置 str -= 2; //指向最后一个有效字符 while (1) { //向前指向第一个间隔符号 while (*str >= 'A'&&*str <= 'Z' || *str >= 'a'&&*str <= 'z') str--; printf("%s",++str); //打印字符串,不包括间隔符号 if (str == head) //如果到头指针就退出 return ; printf("%c", *(--str));//打印间隔符号 *(str) = 0; //设置间隔符号为结束符 str--; }}int main(void){ char s[] = "da ma ha yu zhan shi"; fun(s); return 0;}
阅读全文
0 0
- C三道题
- C三道题(2)
- C三道题(3)
- C三道题(四)
- C三道题(五)
- C三道题(六)
- c语言三道题12.23
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- 关于数据处理使用python时出现的各种编码问题的解决方案
- 树莓派-wiringPi-编译&头文件&lib
- 第二类斯特林数的推导
- MergeTwoSortedList
- ASCII、Unicode、UTF-8编码
- C三道题
- Activity四种启动模式
- shell的变量功能(一)
- VC++实现视频聊天:VFW视频采集+FFmpeg编码
- 源码怎么找之rest_framework的用户认证
- JavaScript标准对象(笔记)
- maya(学习笔记)之Arnold渲染器
- 最近了解的对python字典的用法(有字典的排序)
- 下拉列表 级联菜单操作(js代码的级联操作)