Uploaded by
Acm_ Wang Yarong
The first time I saw 10W I thought it would time out, but it didn't.
is to split the string and then store the segmented string in the struct (a bit embarrassing.) will only use the structure of the string sort, qsort forget ... )
The structure of the string is then sorted, if there are two strings of the same ans++;
Code:
#include <stdio.h> #include <string.h> #include <algorithm>using namespace std; #define NUM 100005char Str[num],temp[11];struct Node {char dir[11];} C[num];bool CMP (node X,node y)//String ordering of structs {if (strcmp (x.dir,y.dir) <0) return True;return false;} int main () {int test,n,i,t,len;scanf ("%d", &test), while (test--) {scanf ("%d%s", &n,str); Len=strlen (str); i=0; while (I+n<=len)//split string and store string {t=0;for (int q=i;q<i+n;q++) temp[t++]=str[q];temp[t]= ' + '; strcpy (c[i].dir,temp ); memset (temp,0,sizeof (temp)); i++;} Sort (c,c+i,cmp), int ans=0;for (int j=1;j<i;j++) if (strcmp (c[j].dir,c[j-1].dir) ==0) ans++;p rintf ("%d\n", ans);} return 0;}