?? 10-4(5,6).cpp
字號:
#include<iostream>
#include<vector>
#include<string>
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::cin;
using std::getline;
struct record_info
{
string s;
struct record_info *next,*front;
};
class String_list
{
public:
typedef struct record_info* ptr;
String_list();
string name(ptr record) const
{
return record->s;
}
ptr begin() const
{
return first;
}
ptr end() const
{
return last->next;
}
ptr rbegin() const
{
return last;
}
void push_back(ptr);
void push_front(ptr);
private:
ptr first,last;
};
void String_list::push_back(ptr x)
{
x->front=x->next=NULL;
if(last==NULL)
first=last=x;
else
{
x->front=last;
last->next=x;
last=x;
}
}
void String_list::push_front(ptr x)
{
x->front=NULL;
x->next=first;
if(first==NULL)
last=first=x;
else
{
first->front=x;
first=x;
}
}
String_list::String_list():first(NULL),last(NULL)
{
}
String_list split(const string& s)
{
String_list ret;
typedef string::size_type string_size;
string_size i=0;
//ivarinant: we have processed characters [original value of i, i)
while(i!=s.size())
{
//ignore leading blanks
//invariant: characters in range [original i, current i) are all spaces
while(i!=s.size()&&isspace(s[i]))
++i;
//find end of next word
string_size j=i;
//invariant: none of the characters in range [original j,current j)is a space
while(j!=s.size()&&!isspace(s[j]))
j++;
//if we found some nonwhitespace characters
if(i!=j)
{
//copy from s starting at i and taking j-i chars
String_list::ptr p=new struct record_info;
p->s=s.substr(i,j-i);
ret.push_back(p);
i=j;
}
}
return ret;
}
int main()
{
String_list L;
string s;
getline(cin,s);
L=split(s);
for(String_list::ptr i=L.begin();i!=L.end();i=i->next)
cout<<L.name(i)<<endl;
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -