[Group] title NOIP2018 popularity statistics

Method a : Read-fitting gets, because gets any character can be read and including spaces , until '\ n- ' newline stopped. Note: it is determined by the space '' ,

code:

#include<bits/stdc++.h>
using namespace std;
int p,len=0,i,ans;
char a[1212];
int main()
{
gets(a);
len=strlen(a);
for(int i=0;i<len;i++)
if(a[i]==' ')
ans++;
//cout<<ans<<endl;
cout<<len-ans<<endl;
}

Method two: with getchar reads, G etchar may be read and any character, including spaces , remaining as above , but the character getchar most efficient, the gets easily cause a stack overflow, when read getchar manually added to the end

 Space '\ 0 ', and the rest were read into the law comes.

code:

#include <bits / STDC ++ H.>
the using namespace STD;
int P, len = 0, I;
char A [1212];
int main ()
{
I = 0;
the while ((A [I] = getchar ())! = '\ n-')
{
I ++;
}
A [I] = '\ 0';
I = 0;
! the while (A [I] = '\ 0')
{
// the putchar (A [I]);

I ++;
if (a [i] == '')
len ++;
}
IF (a [0] == '')  must be a space Laid first sentence, because I while in the i ++ if (a [i] == '') in front
len ++;
// the putchar ( '\ n-');
COUT << endl << I-len;
// len COUT << << endl;
}

Guess you like

Origin www.cnblogs.com/nlyzl/p/11264623.html