标签:algorithm
2 1 6
9 258
//0ms #include <cstdio> #include <cstring> #include <iostream> int a[7]={1,9,18,54,90,174,258}; int main() { int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n",a[n]); } }
//46ms #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[10]; bool judge(int x) { int n=0; while(x>0) { a[++n]=x%10; x=x/10; } //printf("%d\n",n); if(a[1]!=a[n]) return false; for(int j=2,k=n-1;j<=k;j++,k--) { if(a[j]>a[j-1]&&a[j]==a[k]) ; else return false; } return true; } int main() { int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); int temp=1; int ans=0; for(int i=1;i<=n;i++) { temp*=10; } //printf("%d",temp); for(int i=1;i<=temp;i++) { if(judge(i)) { ans++; } } printf("%d\n",ans); } return 0; }
hdu 5062 Beautiful Palindrome Number(Bestcodeer Round #13)
标签:algorithm
原文地址:http://blog.csdn.net/caduca/article/details/40014941