69,336
社区成员
发帖
与我相关
我的任务
分享
//把数字1到n连接起来就构成了第n个Smarandache consecutive number。Smarandache的前17个数如下:
//1
//12
//123
//1234
//12345
//123456
//1234567
//12345678
//123456789
//12345678910
//1234567891011
//123456789101112
//12345678910111213
//1234567891011121314
//123456789101112131415
//12345678910111213141516
//1234567891011121314151617
//给定一个正整数n,问[1,n]之间含有多少个Smarandache consecutive number?
//输入
//多行数据组成。
//每行一个整数n,n大于1并且小于第1000个Smarandache consecutive number。
//输出
//对于每一行的数据n,输出一行,即[1,n]之间Smarandache consecutive number的个数。
//
//样例输入
//1
//13
//1233
//样例输出
//1
//2
//3
#include <stdio.h>
#include <string.h>
char S[1000][4000];
int i,j,L,n;
char ln[4000];
int main() {
for (i=0;i<1000;i++) {
L=0;
for (j=1;j<=i+1;j++) {
L+=sprintf(S[i]+L,"%d",j);
}
// printf("%4d %s\n",i+1,S[i]);
}
while (1) {
if (NULL==fgets(ln,4000,stdin)) break;
if ('\n'==ln[0]) break;
if ('\n'==ln[strlen(ln)-1]) ln[strlen(ln)-1]=0;
n=0;
for (i=999;i>=0;i--) {
if (strlen(ln)>=strlen(S[i])) {
if (strcmp(ln,S[i])>=0) n++;
n+=i;
break;
}
}
printf("%d\n",n);
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n = 1;
string str;
string input;
cin>>input;
while( 1 )
{
char c[1024];
sprintf( c, "%d", n );
str += c;
if( str.size() >= input.size() ) break;
n++;
}
if( str.size() > input.size() || (str.size() == input.size() && str > input ) ) n--;
cout<<str.size()<<endl;
cout<<str<<endl;
cout<<"Total number is:"<<n<<endl;
getchar();
getchar();
return 0;
}