zoukankan      html  css  js  c++  java
  • Length of Last Word

    比较简单的问题:

    #include<iostream>
    #include<string>
    using namespace std;
    
    int main()
    {
        int lengthOfLastWord(const char *s);
        char a[20];
        cin.getline(a,20);
        cout << lengthOfLastWord(a) << endl;
    }
    
    int lengthOfLastWord(const char *s) {
            int i=0,new_word=0,last_length=0;
            while(s[i]!=''){
                if(s[i]==' ')
                    new_word=1;
                else if(new_word==1 && s[i]!=' '){
                    last_length=1;
                    new_word=0;
                }
                else{
                    ++last_length;
                }
                ++i;
            }
            return last_length;
        };
  • 相关阅读:
    HDU 5247
    HDU 4965
    CodeForces 445B
    HDU 5835
    CodeForces 731C
    HDU 5783
    CodeForces 660D
    POJ 1631
    HDU 6112
    HDU 5860
  • 原文地址:https://www.cnblogs.com/iois/p/4077196.html
Copyright © 2011-2022 走看看