3160. 统计字符及行数

Andrew-Malcom

include

include

using namespace std;
int main()
{
char c=’\0’;
int i=0,j=0,sum=0,max=0;
while((c=getchar())!=EOF)
{
if(c!=’\n’){
sum++;}
else if(c==’\n’)
{
i++;
if(sum>max) {max=sum;}
j+=sum;
sum=0;
}
}
cout<<j<<’,’<<i<<’,’<<max<<endl;
}

IWani-Z

include

using namespace std;

int main() {
int len, k = 0, max = 0, res = 0;
string str;
while(getline(cin, str)) {
k++;
len = str.length();
res += len;
if(len > max)
max = len;
}
cout << res << “,” << k << “,” << max << endl;
return 0;
}

Deuchie
#include <cctype>
#include <iostream>
#include <string>

int main() {
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string a;
    int max_size = 0, lines = 0, characters = 0;
    while (getline(cin, a)) {
        ++lines;
        if (max_size < a.size())
            max_size = a.size();
        characters += a.size();
    }
    cout << characters << ',' << lines << ',' << max_size << '\n';
}
你当前正在回复 博客/题目
存在问题!