由于增加了换行符,所以只需要在读入字符串后删去最后一个字符即可。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("log.in","r",stdin);
    freopen("log.out","w",stdout);
    string s;
    cin>>s;
    s.erase(s.end());
    cout<<s.size();
}

是运行时间最多的……