来源:点击打开链接

看上去很简单的一道题,可是错的次数却不少。

题目要求是将一串字母转化成网址——形如格式http(ftp)://xxx.ru/xxxx的样子,看上去很简单,可是还是很容易出错。

刚开始找的时候是按照寻找第一组http/ftp,然后寻找第一个ru,构成网址,但是报错了,反例如下:httpruc

所以不能寻找第一个网址,也就是说尽量避免.ru之前没有东西,这样是不合法 的。然后注意http是四个字符,ftp只有三个字符,所以不能固定。。

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string tar,res;
  8. string tarstack;
  9. int propos=0,ctpos=0;
  10. cin>>tar;
  11. if(tar[0]=='h')
  12. {
  13. tarstack="http";
  14. }
  15. if(tar[0]=='f')
  16. {
  17. tarstack="ftp";
  18. }
  19. ctpos=tar.find("ru",tarstack.length()+1); //5是不行的,惯性思维不可
  20. if(tar[0]=='h')
  21. {
  22. cout<<tarstack<<"://";
  23. for(int i=4;i<ctpos;i++)
  24. {
  25. cout<<tar[i];
  26. }
  27. cout<<".ru";
  28. if(ctpos+2==tar.length())
  29. cout<<endl;
  30. else
  31. {
  32. cout<<"/";
  33. for(int i=ctpos+2;i<tar.length();i++)
  34. {
  35. cout<<tar[i];
  36. }
  37. cout<<endl;
  38. }
  39.  
  40. }
  41. else if(tar[0]=='f')
  42. {
  43. cout<<tarstack<<"://";
  44. for(int i=3;i<ctpos;i++)
  45. {
  46. cout<<tar[i];
  47. }
  48. cout<<".ru";
  49. if(ctpos+2==tar.length())
  50. cout<<endl;
  51. else
  52. {
  53. cout<<"/";
  54. for(int i=ctpos+2;i<tar.length();i++)
  55. {
  56. cout<<tar[i];
  57. }
  58. cout<<endl;
  59. }
  60. }
  61. return 0;
  62.  
  63. }
  64. //范例:httpruhhphhhpuhruruhhpruhhphruhhru

【周全考虑】CodeForces 245B——Internet Address的更多相关文章

  1. FileZilla上傳報錯:421 There are too many connections from your internet address

    起因:2019年01月27日晚九點左右,想要將一個50MB+的文件夾上傳到阿里雲的虛擬主機上,使用FTP 工具FileZilla,出現了上傳一段時間後提示421 There are too many ...

  2. How do I use a host name to look up an IP address?

    The InetAddress class can be used to perform Domain Name Server (DNS) lookups. For example, you can ...

  3. [转]Peer-to-Peer Communication Across Network Address Translators

    Peer-to-Peer Communication Across Network Address Translators Bryan Ford Massachusetts Institute of ...

  4. lwip IP address handling 关于 IP 地址的 操作 API接口

    lwip 2.0.3  IP address handling /** * @file * IP address API (common IPv4 and IPv6) */ 1.u32_t ipadd ...

  5. 网络编程-Java中的Internet查询

    前提 在深入理解URL.URI等概念,或者学些Socket相关的知识之,有必要系统理解一下Internet相关的一些基础知识. Internet地址 连接到Internet(因特网)的设备称为节点(n ...

  6. Converts Internet addresses to Internet numbers. ip2long long2ip

    http://php.net/manual/en/function.long2ip.phpPHP: ip2long - Manual http://php.net/manual/en/function ...

  7. TNS-12541: TNS:no listener , TNS-12542: TNS:address already in use

    查看数据库监听状态不对$ lsnrctl status LSNRCTL for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - Production on ...

  8. Linux Socket 网络编程

    Linux下的网络编程指的是socket套接字编程,入门比较简单.在学校里学过一些皮毛,平时就是自学玩,没有见识过真正的socket编程大程序,比较遗憾.总感觉每次看的时候都有收获,但是每次看完了之后 ...

  9. [协议]ICMP协议剖析

    1.ICMP简介 ICMP全名为(INTERNET CONTROL MESSAGE PROTOCOL)网络控制消息协议. ICMP的协议号为1. ICMP报文就像是IP报文的小弟,总顶着IP报文的名头 ...

随机推荐

  1. yii的常用配置文件

    <?php return array( 'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..', //当前应用根目录路径 'nam ...

  2. 腾讯qq的发展史

    腾讯qq的发展史 即时通信软件的历史并不久远,但是它一诞生,就立即受到网民的喜爱,并风靡全球.    在其发展史上,以色列人功不可没.正是四位以色列籍的年轻人,在1996年7月成立的Mirabilis ...

  3. JRebel: ERROR Could not define reloadable class 'com.sun.proxy.$Proxy118': java.lang.OutOfMemoryError: PermGen space

    MyEclipse由于配置了JRebel,所以是它报错,不过根本问题还是:java.lang.OutOfMemoryError: PermGen space 现在按照经验调整内存大小. 在MyEcli ...

  4. 转 Eclipse下svn的创建分支/合并/切换使用

    最近接项目要求,要在svn主干上创建分支,用分支来进行程序的bug修改,而主干上进行新功能的开发.分支上的bug修改完,发布后,可以合并到主干上.项目程序可以在主干和分支之间进行切换,来实现主干和分支 ...

  5. nginx+php+flight 构建RESTFul API

    配置: Nginx: conf目录下nginx.conf配置文件. 第44行改为:root   D:/wwwroot/www; 第45行改为:index  index.html index.htm i ...

  6. Redis Master/Slave 实践

    本次我们将模拟 Master(1) + Slave(4) 的场景,并通过ASP.NET WEB API进行数据的提交及查询,监控 Redis Master/Slave 数据分发情况,只大致概述,不会按 ...

  7. Drawing with GoogLeNet

    Drawing with GoogLeNet In my previous post, I showed how you can use deep neural networks to generat ...

  8. 发布windows phone应用经历实谈

    经过这一次艰辛的发布应用的过程,看来果然这不是个简单的过程,不过经历过了一次之后感觉其实也没这么难,下面我将介绍我通过学生账号发布windows phone 8的应用到商店的全过程,其实整个过程最为困 ...

  9. JS通过ajax动态读取xml文件内容

    http://www.sharejs.com/codes/javascript/8178 HTML文件代码如下 <!DOCTYPE html> <html> <head& ...

  10. POJ 3185

    The Water Bowls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4088   Accepted: 1609 D ...