Skip to content

Instantly share code, notes, and snippets.

@ankeshanand
Last active December 27, 2015 06:19
Show Gist options
  • Save ankeshanand/7280260 to your computer and use it in GitHub Desktop.
Save ankeshanand/7280260 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<cstdio>
#include<string>
#include<sstream>
#include<cstdlib>
using namespace std;
string str;
int main()
{
int cases;
cin >> cases;
for(int t=0;t<cases;t++)
{
int n,k,result=0;
cin >> n;
cin >> k;
stringstream ss;
ss << k;
string target = ss.str();
for(int i=1;i<=n;i++)
{
char intStr[10];
sprintf(intStr,"%d",i);
str.append(string(intStr));
}
if(target.length()>str.length())
{
result = 0;
}
else{
for(int i=0;i<=str.length()-target.length();i++)
{
string temp = str.substr(i,target.length());
int found = temp.find(target);
if(found!=string::npos)
{
result++;
}
}
}
cout << result << endl;
str.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment