一天一天。。。又结束了。。。。蒟蒻之路还很漫长。。。。
讲谈一下:(玩一下
cin>>10
cout<<
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111
解法:
cin>>n;
k=1;
for(i=1;i<=n;i++)
{
for(j=1;j<=k;j++)
{
cout<<1;
}
cout<<endl;
k++;
}
2.
cin>>10;
cout<<
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10
解法:
cin>>n;
k=1;
for(i=1;i<=n;i+)
{
for(j=1;j<=k;j++)
cout<<k<<' ';
cout<<endl;
k++;
}
3.
cin>>3;
cout<<
1
12
123
解法:
cin>>n;
k=1;
for(i=1;i<=n;i++)
{
for(j=1;j<=k;j++)
cout<<j;
cout<<endl;
k++;
}
扩展3:
cin>>5 10;
cout<<20
var
i,j,x,z,b,k:longint;
sb,si,sx,sz:string;
begin
assign(input,'3n.in');
assign(output,'3n.out');
reset(input);
rewrite(output);
read(k,j);
b:=0;
for i:=k to j do
begin
x:=i;
z:=1;
while x<>1 do
begin
if odd(x) then
begin
x:=x*3+1;
z:=z+1;
end
else
begin
x:=x div 2;
z:=z+1;
end;
end;
if z>b then b:=z;
str(i,si);str(b,sb);str(z,sz);str(x,sx);
end;
write(b);
close(input);
close(output);
end.
4.
cin>>3;
cout<<
1
1 2
1 2 4
cin>>5;
cout<<
1
1 2
1 2 4
1 2 4 8
1 2 4 8 16
解法
:
cin>>n;
k=1;x=1;
for(i=1;i<=n;i++)
{
for(j=1;j<=k;j++)
{
cout<<x;
x*=2;
}
x=1;k++;cout<<endl;
}
5:
cin>>5;
cout<<
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
解法:
var
a:array[1..10,1..10] of longint;
i,j,k,z,x,n:longint;
begin
assign(input,'5.in');
assign(output,'5.out');
reset(input);
rewrite(output);
readln(n);
for i:= 1 to n do
for j:=1 to n do
a[i,j]:=0;
for i:=1 to n do
begin
a[i,1]:=1;
end;
for i:=2 to n do
for j:=2 to i do
begin
a[i,j]:=a[i-1,j]+a[i-1,j-1];
end;
for i:=1 to n do
begin
for j:=1 to i do
write(a[i,j]:4);
writeln;
end;
close(input);
close(output);
end.
6:
cin>>5;
cout<<
1
1 1 1
1 2 3 2 1
1 3 6 7 6 3 1
1 4 10 16 19 16 10 4 1
解法:
var
i,j,n,z,k:longint;
a:array[1..10,-1..100] of longint;
begin
assign(input,'6.in');
assign(output,'6.out');
reset(input);
rewrite(output);
readln(n);
fillchar(a,sizeof(a),0);
a[1,1]:=1;
for i:=2 to n do
begin
for j:=1 to i*2 do
a[i,j]:=a[i-1,j]+a[i-1,j-1]+a[i-1,j-2];
end;
for i:=1 to n do
begin
for j:=1 to i*2-1 do
write(a[i,j]:5);
writeln;
end;
close(input);
close(output);
end.
7:
cin>>30 15
cout<<1/2326762800
cin>>1 1;
cout<<1/1;
解法
var
i,j,n,z,k,m:longint;
a:array[1..30,1..30] of int64;
begin
assign(input,'7.in');
assign(output,'7.out');
reset(input);
rewrite(output);
read(n,m);
fillchar(a,sizeof(a),0);
for i:=1 to n do
a[i,1]:=i;
k:=1;
for i:=2 to n do
begin
for j:=2 to i do
a[i,j]:=a[i-1,j-1]div(j-1)*i;
end;
write('1/',a[n,m]);
close(input);
close(output);
end.
8:
cin>>10 10
cout<<115975
cin>>1 1
cout<<1;
解法:
var
i,j,n,z,k,m:longint;
a:array[1..100,1..100] of qword;
begin
assign(input,'8.in');
assign(output,'8.out');
reset(input);
rewrite(output);
readln(n,m);
fillchar(a,sizeof(a),0);
a[1,1]:=1;
a[2,1]:=1;
a[2,2]:=2;
for i:=3 to n do
begin
for j:=1 to i do
begin
if j<>1 then a[i,j]:=a[i,j-1]+a[i-1,j-1]
else a[i,j]:=a[i-1,i-1]
end;
end;
write(a[n,m]);
close(input);
close(output);
end.
9:
cin>>7;
cout<<1/4;
cin>>10;
cout<<4/1;
解法
var
i,j,n,z,k,m:longint;
a:array[1..100,1..100] of longint;
begin
assign(input,'9.in');
assign(output,'9.out');
reset(input);
rewrite(output);
readln(n);
fillchar(a,sizeof(a),0);
k:=1;
repeat
n:=n-k;
k:=k+1;
until n<=k;
if n=0 then begin
n:=n+1;
k:=k-1;
end;
write(n,'/',k+1-n);
close(input);
close(output);
end.
10题关于一些数字游戏。。。。c++是伪代码。。。Pascal是真代码