题解 | #小乐乐与字符串#
小乐乐与字符串
http://www.nowcoder.com/practice/e09de1fc11db4a438cf8f0668848660d
#include<stdio.h> #include<string.h> int main() { char a[8000]={0}; int n,countC=0,countH=0,countN=0; long int count=0; scanf("%s",&a); n=strlen(a); for(int i=0;i<n;i++) { if(a[i]=='C') countC++; if(a[i]=='H') { countN=0; for(int y=i;y<n;y++) { if(a[y]=='N') countN++; } count=count+countN*countC; } } printf("%ld\n",count); return 0; }