1、键盘输入一个字符串,编写代码获取字符串的长度并输出,要求使用字符指针实现。
#include <iostream>
using namespace std;
int main() {
char str[100]={
0};
cin.getline(str,sizeof(str));
int len=0;
char *p =str;
while (*p!='\0')
{
len ++;
p++;
}
cout<<len<<endl;
return 0;
}
2、 判断链表中是否有环
#include <stdbool.h>
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
*
* @param head ListNode类
* @return bool布尔型
*/
bool hasCycle(struct ListNode* head ) {
// write code here
if(head==NULL||head->next==NULL)
{
return NULL;
}
struct ListNode*slow=head->next,*fast=head->next->next;
while(fast!=NULL&&fast->next!=NULL)
{
if(fast&#