Cattle-off practice match 51 A abc https://ac.nowcoder.com/acm/contest/1083/A

Meaning of the questions:
Given a string s, you need to do is count the number of neutrons s string "abc" is. Substring is defined in the presence of an arbitrary scale a <b <c, then the "s [a] s [b] s [c]" s constitute a sub-string. The "abc" substring has "a", "b", "c", "ab", "ac", "bc", "abc".
Enter a description:
A string s. Ensure input contains only lowercase Latin characters.
1<=|s|<=1e5
Output Description:
S represents an integer number of neutrons string "abc" of.
Example 1
Entry
abcabc
Export
4
 
ac Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll a=0,ab=0,abc=0;
int main(){
 cin>>s;
 for(int i=0;s[i]!='\0';i++){
    if(s[i]=='a')
       a++;
    else if(s[i]=='b')
       ab+=a;
    else if(s[i]=='c')
       abc+=ab;
 }
   cout<<abc<<endl;
  return 0;
}
 
Ideas:
1. The need to count is the number of abc, the string length 1e5, violence times out, it can only sweep again.
2. Then we can think of is to order a re-abc b Finally c, we may first think of sub-problems ab,
As long as you have a plus-one, a record number of c1 occurs when b appears there will be a c1 ab, then look abc, ab as a whole, the number of recorded AB ab arise, when there is there is c a abc AB .
3. When a is traversed appears on a record ++, when there is a traversing a B ab, when traversed C, there abc ab a, the final output value of abc.
 
note:
a, ab, abc type of data to be provided to a long long, int type if provided, will wa !!!
 
 

Guess you like

Origin www.cnblogs.com/lusiqi/p/11478950.html