L1-041 寻找250 (10分)

L1-041 寻找250 (10分)

题目详情:
L1-041 寻找250 (10分)_第1张图片
方法一:

#include
using namespace std;
int main()
{
    int a,count=0;
    while(1)
    {
        count++;
        cin>>a;
        if(a==250)
            break;
    }
    cout<<count<<endl;
    return 0;
}

方法二:(其中istringstream用法参见C++中的istringstream()函数用法)

#include
#include
using namespace std;
int main()
{
    string str,s;
    int c=0;
    getline(cin,str);
    istringstream stream(str);
    while(stream>>s)
    {
        c++;
        if(s=="250")
            break;
    }
    cout<<c<<endl;
    return 0;
}

永远相信美好的事情即将发生

你可能感兴趣的:(团体程序设计天梯赛-练习集)