POJ2105 IP Address
来源:互联网 发布:海德堡工程师软件过期 编辑:程序博客网 时间:2024/05/16 18:35
学了一下insert();囧。。
AC program:#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<iomanip>#include<queue>#include<map>using namespace std;void fn(int p , string aa){ int len=aa.length(); int sum=0,base=1; for(int i=len-1;i>=0;i--) { int tt=aa[i]-'0'; sum=sum+tt*base; base*=2; } if(p==1) cout<<sum; else cout<<'.'<<sum;}int main(){int n;cin>>n;string cc;while(n--){ cin>>cc; string u,v,w,l; u.insert(0,cc,0,8); fn(1,u); v.insert(0,cc,8,8); fn(2,v); w.insert(0,cc,16,8); fn(3,w); l.insert(0,cc,24,8); fn(4,l); cout<<endl; }system("pause"); return 0;}
小结:
(1)、
//insert() 插入字符.其实,insert运用好,与其他的插入操作是一样的.
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s = "hehe";
s.insert(0,"头部"); //在头部插入
s.insert(s.size(),"尾部"); //在尾部插入
s.insert(s.size()/2,"中间"); //在中间插入
cout<<s<<endl;
cin.get();
return 0;
}
(2)、
iterator insert( iterator i, const char &ch );
basic_string &insert( size_type index, const basic_string &str );
basic_string &insert( size_type index, const char *str );
basic_string &insert( size_type index1, const basic_string &str, size_type index2, size_type num );
basic_string &insert( size_type index, const char *str, size_type num );
basic_string &insert( size_type index, size_type num, char ch );
void insert( iterator i, size_type num, const char &ch );
void insert( iterator i, iterator start, iterator end );
insert()函数的功能非常多:
- 在迭代器i表示的位置前面插入一个字符ch,
- 在字符串的位置index插入字符串str,
- 在字符串的位置index插入字符串str的子串(从index2开始,长num个字符),
- 在字符串的位置index插入字符串str的num个字符,
- 在字符串的位置index插入num个字符ch的拷贝,
- 在迭代器i表示的位置前面插入num个字符ch的拷贝,
- 在迭代器i表示的位置前面插入一段字符,从start开始,以end结束.
相关主题:
replace()
- ZOJ2482 POJ2105 IP Address
- POJ2105 IP Address
- POJ2105:IP Address
- poj2105--IP Address
- POJ2105 IP Address
- POJ2105 IP Address
- ZOJ2482&&POJ2105-IP Address
- UVALive3093 POJ2105 ZOJ2482 IP Address
- POJ2105 IP Address 八进制转十进制
- poj2105 IP Address(简单题)
- 北大暑假训练计划—POJ2105 IP Address(C语言)
- Poj2105
- poj2105
- poj2105
- IP address
- ip address
- IP Address
- IP Address
- static与普通的区别--东软笔试题
- 七夕夜、离别,涵情经河岸
- android ListView+自定义标题栏
- struts2 与 spring集成原因 详解
- Android应用程序消息处理机制(Looper、Handler)分析
- POJ2105 IP Address
- 测试中常遇到的问题
- shell 间接变量引用的问题
- java:IO流学习小结
- poj 1679 The Unique MST (次小生成树)
- 水晶头
- 爱情如江南的青花瓷
- ArcGIS for iOS 开发系列(4) – 基础篇-地图组件
- STL之迭代器事例二