1002,字符串存储数时,要使用其当成数进行运算时需进行以下操作:str[I]-‘0’;
1008,m位数组向右移动n位就从m-n位开始输出;通过n=n%m的代码保证n<m;
1036,四舍五入
(int)(n/2.0+0.5)
其他:十进制转二进制:
int shu,a[1000],j=0;
while(shu)
{
a[j]=shu%2;
shu/=2;
j++;
}
for(;j>0;j--)
{
cout<<a[j];
}
1087.数组计数法;输入编号 和分数时统计相同编号的总分(1047,1032);统计分数出现的次数(1087);
运行时间的不同:
短:
for( i=0;i<m;i++)
{
cin>>temp;
if(i!=m-1)
cout<<count[temp]<<" ";
else
cout<<count[temp]<<endl;
}
长:
for( i=0;i<m;i++)
{
cin>>temp;
if(i==m-1)
cout<<count[temp]<<endl;
else
cout<<count[temp]<<" ";
}