lovequeen  

 

 

方法一:

#include<bits/stdc++.h>
using namespace std;
int m,n,lst,ans;
bool pd(int x)
{
lst=0;
while(x)
{

int a=x%10;
x/=10;
if(a==4) return false;
if(lst==3&&a==1) return false;
lst=a;
}
return true;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=n;i<=m;i++)
{
//if(!pd(i))printf("%d\n",i);
if(pd(i)) {ans++;}
}
// printf("%d\n",pd(3131));
printf("%d",ans);
return 0;
}

方法二(这是我第一次的想法,十分暴力,但是简单)

#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
using namespace std;
long int n, m;
long int ans=0;
int ge,shi,bai,qian,wan,shiwan ;
int main()
{
cin>>n>>m;
for(int i=n;i<=m;i++)
{
if(i>99999&&i<1000000)
{
shiwan=i/100000;
wan=(int)(i-shiwan*100000)/10000;
qian=(int)(i-shiwan*100000-wan*10000)/1000;
bai=(int)(i-shiwan*100000-wan*10000-qian*1000)/100;
shi=(int)(i-shiwan*100000-wan*10000-qian*1000-bai*100)/10;
ge=(int)(i-shiwan*100000-wan*10000-qian*1000-bai*100-shi*10);
if(shiwan!=4&&wan!=4&&qian!=4&&bai!=4&&shi!=4&&ge!=4&&shiwan*10+wan!=13&&wan*10+qian!=13&&qian*10+bai!=13&&bai*10+shi!=13&&shi*10+ge!=13) ans++;
}

else if(i>9999&&i<100000)
{
wan=i/10000;
qian=(int)(i-wan*10000)/1000;
bai=(int)(i-wan*10000-qian*1000)/100;
shi=(int)(i-wan*10000-qian*1000-bai*100)/10;
ge=(int)(i-wan*10000-qian*1000-bai*100-shi*10);
if(wan!=4&&qian!=4&&bai!=4&&shi!=4&&ge!=4&&wan*10+qian!=13&&qian*10+bai!=13&&bai*10+shi!=13&&shi*10+ge!=13) ans++;
}
else if(i>999&&i<10000)
{
qian=i/1000;
bai=(int)(i-qian*1000)/100;
shi=(int)(i-qian*1000-bai*100)/10;
ge=(int)(i-qian*1000-bai*100-shi*10);
if(qian!=4&&bai!=4&&shi!=4&&ge!=4&&qian*10+bai!=13&&bai*10+shi!=13&&shi*10+ge!=13) ans++;
}
else if(i>99&&i<1000)
{
bai=i/100;
shi=(int)(i-bai*100)/10;
ge=(int)(i-bai*100-shi*10);
if(bai!=4&&shi!=4&&ge!=4&&bai*10+shi!=13&&shi*10+ge!=13) ans++;
}
else if(i>9&&i<100)
{
shi=i/10;
ge=(int)(i-shi*10);
if(shi!=4&&ge!=4&&shi*10+ge!=13) ans++;
}
else if(i>1&&i<10)
{
ge=i;
if(ge!=4) ans++;
}
}
cout<<ans<<endl;
return 0;
}

posted on 2020-09-27 23:50  lovequeen  阅读(211)  评论(0)    收藏  举报