发布时间:2025-12-10 19:25:15 浏览次数:8
检测url失败是什么意思_腾讯url检测题目:编写一个C语言函数,要求输入一个url,输出该url是首页、目录页或者其他url如下形式叫做首页:militia.info/www.apcnc.com.cn/http://www.cyjzs.comwww.greena888.com/www.800cool.net/http://hgh-product…
题目: 编写一个C语言函数,要求输入一个url,输出该url是首页、目录页或者其他url
如下形式叫做首页:
militia.info/
www.apcnc.com.cn/
http://www.cyjzs.comwww.greena888.com/
www.800cool.net/
http://hgh-products.my-age.net/
如下形式叫做目录页:
thursdaythree.net/greenhouses–gas-global-green-house-warming/
http://www.mw.net.tw/user/tgk5ar1r/profile/
http://www.szeasy.com/food/yszt/chunjie/
www.fuckingjapanese.com/Reality/
请注意:
a) url有可能带http头也有可能不带
b)动态url(即含有”?”的url)的一律不算目录页,如:
www.buddhismcity.net/utility/mailit.php?l=/activity/details/3135/
www.buddhismcity.net/utility/mailit.php?l=/activity/details/2449/
解题思路:
1.先将有http://的字符串滤掉,判断剩下的字符串
2.扫描剩下的字符串,记录‘/’的数目,若有‘?’出现,则直接返回结果:其他
3.有一个‘/’的即为域名(其实域名也可不加/,只不过这里是题目的要求),如果数目多于一个,则是一个网站目录
//程序
#include <stdio.h>#include <string.h>int CheckUrl(const char * url){ char temp[100]; char strHead[8]; memmove(strHead,url,7); strHead[7] = '#include <stdio.h>#include <string.h>int CheckUrl(const char * url){char temp[100];char strHead[8];memmove(strHead,url,7);strHead[7] = '\0';strcpy(temp,url);char * s = temp;if (strcmp("http://",strHead)==0){s = temp+7;}int segCount = 0;for (;s<temp+strlen(temp);){if (*s == '?'){return 3;//其他}if (*s == '/'){segCount++;}s++;}if (segCount>1){return 2;//目录}return 1;//域名}int main(){char str[100];while(scanf("%s",str)){printf("%s:%d\n",str,CheckUrl(str));}}
'; strcpy(temp,url); char * s = temp; if (strcmp("http://",strHead)==0) { s = temp+7; } int segCount = 0; for (;s<temp+strlen(temp);) { if (*s == '?') { return 3;//其他 } if (*s == '/') { segCount++; } s++; } if (segCount>1) { return 2;//目录 } return 1;//域名}int main(){ char str[100]; while(scanf("%s",str)) { printf("%s:%d\n",str,CheckUrl(str)); }} 是否还在为Ide开发工具频繁失效而烦恼,来吧关注以下公众号获取最新激活方式。亲测可用!
【正版授权,激活自己账号】:Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】:官方授权 正版激活 自己使用,支持Jetbrains家族下所有IDE…
转载于:https://www.cnblogs.com/hxf829/archive/2009/10/12/1659752.html