201612
- 中间数:开设数组记录每个数出现的次数,遍历就好,当左边>=右边break
- 工资计算:模拟+打表
从编程方法上来说,一种是将工资段和税率写到程序逻辑中,这种做法修改程序比较难,逻辑也比较复杂。另外一种是查表法,通过查表来计算最后的结果。
不过本题需注意的是,慎用浮点数,既然本题已经保证小明的税前工资为一个整百的数,因此在税率表中采取整数而非小数。
using namespace std;
int s, t;
int res[10] = {0, 1500, 4500, 9000, 35000, 55000, 80000};
float rate[10]={0, 0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45};
int rich[10];
int main()
{
I(t);
rich[0]=3500;
for(int i=1; i<7; i++)
{
rich[i] = rich[i-1]+(res[i]-res[i-1])*(1-rate[i]);
//此处若是rich[i] = rich[i-1]+(res[i]-res[i-1])*(1.0-rate[i])就会出现误差,目前笔者还未搞清为何如此
}
if(t<=3500)
{
O(t),puts("");
return 0;
}
int index;
for(index=1;index<7;index++)
{
if(t>rich[index-1] &&t<=rich[index]) break;
}
int rest = t-rich[index-1];
int ans = 3500+res[index-1]+rest/(100-(int)(rate[index]*100))*100;
O(ans);puts("");
return 0;
}
- 权限查询
#include <bits/stdc++.h>
using namespace std;
map<string,int> pri;
map<string,map<string,int> > rol;
map<string,map<string,int> > usr;
void find(string u,string x,int lev)
{
if(usr.count(u)>0&&usr[u].count(x)>0)
{
if(lev==-1)
{
if(usr[u][x]>-1) cout<<usr[u][x]<<endl;
else cout<<"true\n";
}
else
{
if(usr[u][x]>=lev) cout<<"true\n";
else cout<<"false\n";
}
}
else cout<<"false\n";
}
int main()
{
int n;
cin>>n;
while(n--)
{
string x;
cin>>x;
size_t pos=x.find(":");
if(pos==string::npos) pri[x]=-1;
else
{
int lev=x[pos+1]-'0';
x=x.substr(0,pos);
pri[x]=max(pri[x],lev);
}
}
cin>>n;
while(n--)
{
string role;
int k;
cin>>role>>k;
while(k--)
{
string x;
cin>>x;
size_t pos=x.find(":");
if(pos==string::npos) rol[role][x]=-1;
else
{
int lev=x[pos+1]-'0';
x=x.substr(0,pos);
rol[role][x]=max(rol[role][x],lev);
}
}
}
cin>>n;
while(n--)
{
string u;
int k;
cin>>u>>k;
while(k--)
{
string x;
cin>>x;
map<string,int>::iterator it=rol[x].begin();
while(it!=rol[x].end())
{
if(usr[u].count(it->first)>0)
usr[u][it->first]=max(usr[u][it->first],it->second);
else
usr[u][it->first]=it->second;
++it;
}
}
}
cin>>n;
while(n--)
{
string u,x;
cin>>u>>x;
size_t pos=x.find(":");
if(pos==string::npos) find(u,x,-1);
else find(u,x.substr(0,pos),x[pos+1]-'0');
}
return 0;
}