关于stringstream的用法杭电2072

#include <sstream>
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
int main()
{
    string s,t;
    set<string> bag;
    while(getline(cin,s))
    {
        if(s=="#")
            break;
        bag.clear();//清楚缓冲区的状态
        stringstream ss;
        //cout<<ss.str()<<endl;//输出流中的东西
        ss<<s;
        //cout<<ss.str().length()<<endl;
        while(ss>>t)
        {

           // cout<<ss.str()<<endl;
            bag.insert(t);
        }
        cout<<bag.size()<<endl;
    }
}

关于总结来自
clear()的用法
https://www.cnblogs.com/qingsiburan/p/3858680.html
stringstream的用法
http://www.cnblogs.com/propheteia/archive/2012/07/12/2588225.html
string s;
stringstream ss(s);和ss>>s;是一样的
cout<<s和cout<<ss.str()一样,都是输出流中的东西
http://www.dotcpp.com/oj/problem1116.html
将字符转换成数字
#include
#include
#include
using namespace std;
bool judge(string str)
{
int i=0;
string str1;
while(i<str.length())
{
while(str[i]!=’.’&&i<str.length())
{
if(str[i]<=‘9’&&str[i]>=‘0’)
{
str1=str1+str[i];
}else
{
return false;
}
i++;
}
i++;
int num;
stringstream ss;
ss<<str1;
ss>>num;
if(num<0||num>255)
{
return false;
}
str1="";
}
return true;
}
int main()
{
string str;
while(cin>>str)
{
if(judge(str))
cout<<“Y”<<endl;
else
cout<<“N”<<endl;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值