pascal改为C++程序

来源:百度知道 编辑:UC知道 时间:2024/05/17 09:14:00
把下面的pascal程序改为C++~~我急用~好的有加分~~越快分越多
var
b:array[0..100] of boolean;
a:array[0..100] of integer;
n,m,i,j,s,x,k:integer;
begin
assign(input,'print.in');
reset(input);
assign(output,'print.out');
rewrite(output);
readln(n,m);
for i:=0 to n-1 do b[i]:=false;
for i:=0 to n-1 do read(a[i]);
s:=0;
j:=0;
for i:=9 downto a[m] do
begin
x:=j;
k:=0;
repeat
if x=n then begin x:=0; k:=1;end;
if (b[x]=false) and (a[x]=i) then begin
s:=s+1;
if x=m then begin
writeln(s);
close(input);
close(output);
exit;
end;
b[x]:=true;
j:=x;
end;
x:=x+1;
until (k=1) and (j=x);
end;
writeln(s);
close(input);
close(output);
end.

for i:=0 to n-1 do b[i]:=false;

//两个程序肯定是等价的,不过是在不知道这个是干什么用的。能告诉我吗?
#include<fstream>
using namespace std;

int main(int argc,char* argv[])
{
bool b[101];
int a[101];
int n,m,i,j,s,x,k;
ifstream input("print.in");
ofstream output("print.out");
input>>n>>m;
for(i=0;i<=n-1;i++) b[i]=false;
for(i=0;i<=n-1;i++) input>>a[i];
s=0;
j=0;
for(i=9;i>=a[m];i--)
{
x=j;
k=0;
do
{
if( x==n )
{
x=0;k=1;
}
if( b[x]==false && a[x]==i )
{
s=s+1;
if( x==m )
{
output<<s<<endl;
input.close();
output.close();
return 0;
}
b[x]=true;
j=x;
}
x=x+1;
}while( !((k==1) && (j==x)) );
}
output<<s<<endl;
input.close();
o