This konjac nothing better to brush water problem
Saying the problem and see downstairs bigwigs basically with the character (char) to do, then let me introduce the advantages of C ++:
string !
String , is the type of string C language is not very convenient to use
Let me introduce string of usage:
1. Definitions
string 字符串名;
2. Enter
It has two kinds of input methods:
① getline \ Color Black {} \ {text} getline getline: Usage:
getline(cin,字符串名);
② CIN \ Color Black {} \ {text} CIN CIN: Usage:
cin>>字符串名;
Simple, right?
3. The test string length
①
串长=字符串名.size();
②
串长=字符串名.length();
Remember that the first string is 0!
4. member function
Here I do not speak first, if interested can go to my blog browser (I still have not written)
Moreover, where n ≤ 100000, so I took out my trick
Fast reading!
Do believe that this question must know bigwigs read it fast!
Fast read, understood literally is ____ .
Answer: Quick read
We all know that reading a character than read an integer much faster.
Then this easy to handle! We also know that every character has its own ASCII code, then we are not as long as the character input minus the ASCII characters 0 48 can it?
Of course.
The following release quick read codes, notes, do not understand can ask the teacher and classmates.
int Read () { // Fast Read, Read int R & lt = 0 , f = . 1 ; // R & lt counter is, f is the flag to see negative integer or char C = getchar (); // read C the while (( C < ' 0 ' || C> ' . 9 ' !) && C = ' - ' ) // read non-numeric, character minus C = getchar (); IF (C == ' - ' ) // Laid determination c, if c is negative then f -1 is set, that is negative f = - . 1 , c = getchar (); the while (c <= '. 9 ' && C> = ' 0 ' ) // official read digital R & lt = R & lt * 10 + the C- ' 0 ' , C = getchar (); // R & lt ASCII code c-0 by the composition of return R & lt F *; / / If f is negative compared to 1, f is compared to a negative -1 }
Pretty simple, right?
That is the whole point of this knowledge, and hope we have a good reading comprehension
I released the following code:
#include <the iostream> the using namespace STD; // present konjac likes to write this String S; // string int n-, Anton, danik, len, I; // Anton Anton wins a field rate, danik empathy int Read () { // quick to read hot int R & lt = 0 , F = . 1 ; char C = getchar (); the while ((C < ' 0 ' || C> ' . 9 ' !) && C = ' - ' ) c=getchar(); if(c=='-') f=-1,c=getchar(); while(c<='9'&&c>='0') r=r*10+c-'0',c=getchar(); return r*f; } int main () { n- = Read (); // fast read into the read mode, get at CIN >> S; // CIN I use, getline may len = s.size (); // test string length spicy! for (I = 0 ; I <len; I ++) { // the first character string is 0 IF (S [I] == ' A ' ) // Anton wins if Anton ++ ; the else // anyway is not A, D ( here is Danik win situation) Danik ++ ; } IF (Anton == Danik) // This section is intended purely on written questions, bigwigs all know it printf ( " Friendship " ); IF (Anton < Danik) printf("Danik"); if(anton>danik) printf("Anton"); return 0; }