![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
TASK: ariprog
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <iostream>
#include <fstream>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
const int N = 300000;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
bool flag[N];
bool none_find =true;
int array[N];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
int i,j,num,n,m, def;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
ifstream in("ariprog.in");
ofstream out("ariprog.out");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
in>>n>>m;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
num=0;
for(i=0;i<=m;++i)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(j=0;j<=m;++j)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(!flag[i*i+j*j])
{
array[num++] = i*i+j*j;
}
flag[i*i+j*j] = true;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
sort(array, array+num);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
//a+(n-1)*b <= m*m+m*m
bool is;
int p,c;
int max = 2*m*m;
int def_max = max/(n-1);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(def=1; def<=def_max; def++)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(p=0; array[p]<=(max-((n-1)*def)); p++)
{
is = true;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(c=(n-1); c>=0; c--)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(!flag[array[p]+c*def])
{
is =false;
break;
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(is)
{
none_find = false;
out<<array[p]<<" "<<def<<endl;
}
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(none_find)
out<<"NONE"<<endl;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
posted @
2010-11-09 12:54 小阮 阅读(123) |
评论 (0) |
编辑 收藏
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
TASK: clocks
LANG: C++
*/
#include <iostream>
#include <fstream>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
char *movestr[] =
{"abde","abc","bcef","adg","bdefh","cfi","degh","ghi","efhi"};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int movedist[9][9];
int clocks[9];
int move[9];
int bestmove[9];
int nbestmove;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
void mkmove()
{
int i;
char *p;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0; i<9; ++i)
for(p=movestr[i]; *p; p++)
movedist[i][*p-'a']=3;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
void solve(int k)
{
int i,j,n,rep;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(k==9)
{
for(j=0; j<9; ++j)
if(clocks[j]%12!=0)
return;
n=0;
for(j=0; j<9; ++j)
n+=move[j];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(nbestmove==0 || n<nbestmove)
{
nbestmove = n;
for(j=0; j<9; ++j)
bestmove[j] = move[j];
}
return;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(rep=3; rep>=0; --rep)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0; i<rep; ++i)
for(j=0; j<9; ++j)
clocks[j] += movedist[k][j];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
move[k]=rep;
solve(k+1);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0; i<rep; ++i)
for(j=0; j<9; ++j)
clocks[j] -= movedist[k][j];
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
char *ch="";
int i,j;
ifstream in("clocks.in");
ofstream out("clocks.out");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0;i<9;i++)
in>>clocks[i];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
mkmove();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
solve(0);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0; i<9; ++i)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(j=0; j<bestmove[i]; ++j)
{
out<<ch<<i+1;
ch=" ";
}
out<<endl;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
posted @
2010-11-09 12:53 小阮 阅读(196) |
评论 (0) |
编辑 收藏
摘要: 这题看了答案..
/**//*ID: lorelei3TASK: packrecLANG: C++*/#include <fstream>#include <algorithm>#include <iostream>using namespace std;const in...
阅读全文
posted @
2010-11-09 12:52 小阮 阅读(595) |
评论 (0) |
编辑 收藏
这个代码好烂。。
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
TASK: crypt1
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
const int N = 10;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int s[N];
bool f[N];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
int a,b,c,d,e,i,n,ans=0;
int ai[3], bi[3], res[4];
ifstream in("crypt1.in");
ofstream out("crypt1.out");
memset(f, false, sizeof(f));
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
in>>n;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(i=0; i<n; ++i)
{
in>>s[i];
f[s[i]] = true;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(a=0; a<n; ++a)
for(b=0; b<n; ++b)
for(c=0; c<n; ++c)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(d=0; d<n; ++d)
{
if(s[a]*s[d]>10)
continue;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(e=0; e<n; ++e)
{
memset(ai, 0, sizeof(a));
memset(bi, 0, sizeof(b));
memset(res, 0, sizeof(res));
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int cc =0, bb=0;
bb = (s[c]*s[e])%10;
cc = (s[c]*s[e])/10;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
ai[0] = bb;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
bb = (s[b]*s[e]+cc)%10;
cc = (s[b]*s[e]+cc)/10;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
ai[1] = bb;
ai[2] = (s[a]*s[e]+cc);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(!(f[ai[0]] && f[ai[1]] && f[ai[2]]))
continue;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(ai[2]>10)
continue;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
bb = (s[c]*s[d])%10;
cc = (s[c]*s[d])/10;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
bi[0] = bb;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
bb = (s[b]*s[d]+cc)%10;
cc = (s[b]*s[d]+cc)/10;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
bi[1] = bb;
bi[2] = (s[a]*s[d]+cc);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(!(f[bi[0]] && f[bi[1]] && f[bi[2]]))
continue;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(bi[2]>10)
continue;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
res[0]=ai[0];
cc=0;
bb=(ai[1]+bi[0]+cc)%10;
cc=(ai[1]+bi[0]+cc)/10;
res[1]=bb;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
bb=(ai[2]+bi[1]+cc)%10;
cc=(ai[2]+bi[1]+cc)/10;
res[2]=bb;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
res[3]=bi[2]+cc;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(res[3]>10)
continue;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
else
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(f[res[0]]&&f[res[1]]&&f[res[2]]&&f[res[3]])
{
ans++;
}
}
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
out<<ans<<endl;
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
posted @
2010-11-09 01:02 小阮 阅读(144) |
评论 (0) |
编辑 收藏
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
TASK: calfflac
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
const int N = 21000;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
char fulltext[N];
char text[N];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int pallen,b;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int findpal()
{
char *p, *fwd, *bkwd, *etext = text+strlen(text);
int tmp;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(p=text; *p; ++p)
{
for(fwd=p,bkwd=p; fwd<etext && bkwd>=text && *fwd==*bkwd; fwd++, bkwd--);
bkwd++;
tmp=fwd-bkwd;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(tmp>pallen)
{
pallen=tmp;
b=bkwd-text;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(fwd=p,bkwd=p+1; fwd<etext && bkwd>=text && *fwd==*bkwd; fwd++, bkwd--);
bkwd++;
tmp=fwd-bkwd;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(tmp>pallen)
{
pallen=tmp;
b=bkwd-text;
}
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
int i;
char *p, *q, ch;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
FILE *fin, *fout;
fin = fopen("calfflac.in", "r");
fout = fopen("calfflac.out", "w");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
p=fulltext;
q=text;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while((ch = getc(fin)) != EOF)
{
if(isalpha(ch))
*q++ = tolower(ch);
*p++ = ch;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
*p = '\0';
*q = '\0';
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
findpal();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
fprintf(fout, "%d\n", pallen);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0, p=fulltext; *p; ++p)
if(isalpha(*p))
if(i++==b)
break;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(i=0; i<pallen && *p; ++p)
{
fputc(*p, fout);
if(isalpha(*p))
i++;
}
fprintf(fout, "\n");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
posted @
2010-11-09 01:01 小阮 阅读(163) |
评论 (0) |
编辑 收藏
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
TASK: barn1
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <fstream>
#include <algorithm>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
const int MAX = 200;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int a[MAX], b[MAX];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
int i, j, m, s, c, t;
ifstream in("barn1.in");
ofstream out("barn1.out");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
in>>m>>s>>c;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0; i<c; ++i)
in>>a[i];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
sort(a, a+c);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
t=a[c-1]-a[0]+1;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0; i<c-1;++i)
b[i]=a[i+1]-a[i]-1;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
sort(b, b+c-1);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=c-2, j=1; i>=0&&j<m; i--,j++)
t-=b[i];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
out<<t<<endl;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
posted @
2010-11-09 01:00 小阮 阅读(148) |
评论 (0) |
编辑 收藏
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
PROG: milk
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <fstream>
#include <algorithm>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
const int MAX = 5005;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
typedef struct Cow
{
int price;
int amount;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
bool operator< (const Cow& c) const
{
return price < c.price;
}
}Cow, *pCow;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
Cow cows[MAX];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int total,n;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
int i, cost=0;
ifstream in("milk.in");
ofstream out("milk.out");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
in>>total>>n;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(i=0; i<n; ++i)
{
in>>cows[i].price>>cows[i].amount;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
sort(cows, cows+n);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
i=0;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(total-cows[i].amount>0)
{
total -= cows[i].amount;
cost += cows[i].amount * cows[i].price;
i++;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
cost += cows[i].price*total;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
out<<cost<<endl;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
posted @
2010-11-09 00:59 小阮 阅读(120) |
评论 (0) |
编辑 收藏
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
PROG: dualpal
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <fstream>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int IsDual(int num, int base)
{
int s[100];
int i,j = 0;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(num!=0)
{
s[j] = num%base;
num /= base;
j++;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=0,j--; i<j; ++i,--j)
if(s[i]!=s[j])
return 0;
return 1;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int IsDoubleDual(int S)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(int i=2, j=0; i<=10; ++i)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(IsDual(S, i))
{
j++;
if(j==2)
return 1;
}
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
int n,N,S;
ifstream in("dualpal.in");
ofstream out("dualpal.out");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
in>>N>>S;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
n=0;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(n<N)
{
S++;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(IsDoubleDual(S))
{
n++;
out<<S<<endl;
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
posted @
2010-11-09 00:56 小阮 阅读(119) |
评论 (0) |
编辑 收藏
先进制转换,再判断是不是回文。
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
PROG: palsquare
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <fstream>
#include <iostream>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
void transform(int s, int b, char* k)
{
int j=0;
char t[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(s!=0)
{
k[j] = t[s%b];
s = s/b;
++j;
}
k[j]='\0';
char* a;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(a=k+j-1; k<a; a--,k++)
{
char ch = *a;
*a = *k;
*k = ch;
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int isPal(char* s)
{
int len = 0;
char* r = s;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(*r!='\0')
{
len++;
r++;
}
char* t;
for(t=s+len-1; s<t; s++,t--)
if(*s!=*t)
return 0;
return 1;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
int b;
char k[100];
char a[100];
ifstream in("palsquare.in");
ofstream out("palsquare.out");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
in>>b;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(int i=1; i<=300; i++)
{
transform(i*i, b, k);
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(isPal(k))
{
transform(i,b,a);
out<<a<<" "<<k<<endl;
}
}
return 0;
}
posted @
2010-11-09 00:54 小阮 阅读(144) |
评论 (0) |
编辑 收藏
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*
ID: lorelei3
PROG: namenum
LANG: C++
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <fstream>
#include <string>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
const char code[26] =
{'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','0','7','7','8','8','8','9','9','9','0'};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
int main()
{
bool flag = false;
string digits, b, s;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
ifstream in1("namenum.in");
ifstream in2("dict.txt");
ofstream out("namenum.out");
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
in1>>digits;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while(in2>>s)
{
if(code[s[0]-'A'] != digits[0])
continue;
int len = s.length();
b = s;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(int i=0; i<len; ++i)
{
b[i] = code[s[i]-'A'];
}
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(b == digits)
{
flag = true;
out<<s<<endl;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
if(!flag)
out<<"NONE"<<endl;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
posted @
2010-11-09 00:46 小阮 阅读(147) |
评论 (0) |
编辑 收藏