两道P语言编程题

来源:百度知道 编辑:UC知道 时间:2024/07/08 00:29:41
1、N进制乘法口诀表(table.pas,table.in,table.out,时限1秒)
从table.in中读入一个自然数N(2≤N≤16),打印出N进制乘法口诀表,输出到table.out中。
请注意格式(大写字母、右对齐,除了最左列外,每个数据项占4列),以下是N=16时的结果:
* 0 1 2 3 4 5 6 7 8 9 A B C D E F
0 0
1 0 1
2 0 2 4
3 0 3 6 9
4 0 4 8 C 10
5 0 5 A F 14 19
6 0 6 C 12 18 1E 24
7 0 7 E 15 1C 23 2A 31
8 0 8 10 18 20 28 30 38 40
9 0 9 12 1B 24 2D 36 3F 48 51
A 0 A 14 1E 28 32 3C 46 50 5A 64
B 0 B 16 21 2C 37 42 4D 58 63 6E 79
C 0 C 18 24 30 3C 48 54 60 6C 78 84 90
D 0 D 1A 27 34 41 4E 5B 68 75 82 8F 9C A9
E 0 E 1C 2A 38 46 54 62 70 7E 8C 9A A8 B6 C4
F 0 F 1E 2D 3C 4B 5A 69 78 87 96 A5 B4 C3 D2 E1

2、波浪数(num.pas,num.in,num.out,时限3秒)
波浪数是在一对数字之间交替转换的数,如1212121,双重波浪数则是指在两种进制下都是波浪数的数,如十进制数191919是一个十进制

#include<iostream> #include<cstdio> #include<vector>#include<algorithm>using namespace std; vector<int> g;const int maxn=10000005;int p1,p2,low,high,tar;void make(int jz){ int i,j,n,a[40]={0},tmp,x,y; tmp=low;j=1; while(tmp) { a[j++]=tmp%jz; tmp=tmp/jz; } n=j-1; if(n>1) { i=a[n-1]; j=a[n]; } else { i=0; j=a[n]; } for(x=n;;) { if(i==j) { i++; if(i==jz) { j++; i=0; } if(j==jz) { j=1; x++; } continue; } if(x%2) { for(y=x;y>=3;y-=2){a[y]=j;a[y-1]=i;} a[1]=j; } else { for(y=x;y>=2;y-=2){a[y]=j;a[y-1]=i;} } tmp=0; for(y=x;y>=1;y--)tmp=tmp*jz+a[y]; if(x==1)j++; else i++; if(i==jz) { j++; i=0; } if(j==jz) { j=1; x++; } if(tmp<low)continue; else if(tmp>high)break; else g.push_back(tmp); }}int test,c;int main(){ //freopen("r.txt","r",stdin); //freopen("w.txt","w",stdout); while(scanf("%d",&p1)==1) { g.clear(); scanf("%d%d%d%d",&p2,&low,&high,&tar); for(test=p1;test<=p2;test++)make(