We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
// this solution without any type of container#include<iostream>typedefintusg_t;intmain(){charx,y,z;usg_tdup{0},dupc{0},tria{0},dis{0};// dup count for X...XX // tria count for XOX // dis count for XO .x=getchar();y=getchar();z=getchar();if((x<'a'||x>'z')||(y<'a'||y>'z'))std::cout<<0,exit(0);elseif(z<'a'||z>'z')std::cout<<1,exit(0);if(x==y){if(x==z)dis++,dup++,++dupc;elsedup++,dis+=2;}else{if(x==z)dis+=3,tria++;elseif(y==z)dis+=2,dup++,dupc++;elsedis+=3;}while(true){x=y,y=z;z=getchar();if(z<'a'||z>'z')break;if(x==y){if(x!=z)++dis;}else{if(x!=z){if(y==z)++dup;else++dis;}elsedis++,tria++;}}std::cout<<((dis*(dis-1)/2)+dup-tria)<<std::endl;system("pause");}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Strings
You are viewing a single comment's thread. Return to all comments →