单项选择
问题求解
阅读程序
#include<iostream>
using namespace std;
int rSum(int j)
{
int sum=0;
while(j!=0)
{
sum=sum*10+(j%10);
j=j/10;
}
return sum;
}
int main()
{
int n,m,i;
cin>>n>>m;
for(i=n;i<m;i++)
if(i==rSum(i))
cout<<i<<' ';
return 0;
}
输入:90 120
输出:______
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
char m1,m2;
int i;
getline(cin,s);
m1=' ';
m2=' ';
for(i=0;i<s.length();i++)
if(s[i]>m1)
{
m2=m1;
m1=s[i];
}
else if(s[i]>m2)
m2=s[i];
cout<<int(m1)<<' '<<int(m2)<<endl;
return 0;
}
输入:Expo 2010 Shanghai China
输出:______________________
完善程序
#include<iostream>
using namespace std;
int main()
{
const int SIZE=1000;
int n,r,p[SIZE],i,j,k,ans;
bool tmp;
cin>>n;
r=1;
p[1]=2;
for(i=3;i<=n;i++)
{
①;
for(j=1;j<=r;j++)
if(i%②==0)
{
tmp=false;
break;
}
if(tmp)
{
r++;
③;
}
}
ans=0;
for(i=2;i<=n/2;i++)
{
tmp=false;
for(j=1;j<=r;j++)
for(k=j;k<=r;k++)
if(i+i==④)
{
tmp=true;
break;
}
if(tmp)
ans++;
}
cout<<ans<<endl;
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
const int SIZE=100;
const int INFINITY = 10000;
const bool LEFT=true;
const bool RIGHT =false;
const bool LEFT_TO_RIGHT=true;
const bool RIGHT_TO_LEFT=false;
int n,hour[SIZE];
bool pos[SIZE];
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int go(bool stage)
{
int i,j,num,tmp,ans;
if(stage==RIGHT_TO_LEFT)
{
num=0;
ans=0;
for(i=1;i<=n;i++)
if(pos[i]==RIGHT)
{
num++;
if( hour[i]>ans)
ans=hour[i];
}
if( ① )
return ans;
ans=INFINITY;
for(i=1;i<=n-1;i++)
if(pos[i]==RIGHT)
for(j=i+1;j<=n;j++)
if(pos[j]==RIGHT)
{
pos[i]=LEFT;
pos[j]=LEFT;
tmp=max(hour[i],hour[j])+ ②;
if(tmp<ans)
ans=tmp;
pos[i]=RIGHT;
pos[j]=RIGHT;
}
return ans;
}
if(stage==LEFT_TO_RIGHT)
{
ans=INFINITY;
for(i=1;i<=n;i++)
if( ③ )
{
pos[i]=RIGHT;
tmp=④;
if(tmp<ans)
ans=tmp;
⑤;
}
return ans;
}
return 0;
}
int main()
{
int i;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>hour[i];
pos[i]=RIGHT;
}
cout<<go(RIGHT_TO_LEFT)<<endl;
return 0;
}