题解 | 字符串最后一个单词的长度

字符串最后一个单词的长度

https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>//队列
#include <stack> //栈
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
#define pii pair<int, int>
//queue<int> que;
//set<int> s;
//stack<int> st;



void solve() {
    //scanf("%d", &);
    //printf("\n", );

    /*
    cout << "手慢无" << endl;
    cout << "骗你的,手快也无" << endl;
    cout << "haha ^_^" << endl;
    */

    //vector<int>a(n);
    //sort(a.begin(), a.end());
    //map<int, int>mp;

    int len=0;
    string s;
    while(cin>>s)
    {
        len=s.size();
    }
    cout<<len;

}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << endl;
    }
    return 0;
}

#牛客春招刷题训练营#
全部评论
题解:用 while(cin) 不断读入以空格隔开的字符串,然后用一个len变量记录字符串的长度
点赞 回复 分享
发布于 03-16 21:30 河南

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务