284
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
struct Yuebing{
double kucun;
double price;
};
bool cmp_average(const Yuebing &x, const Yuebing &y) {
return (x.price / x.kucun) > (y.price / y.kucun);
}
int main()
{
int N;
double D;
cin>>N>>D;
struct Yuebing y1[N];
for(int i=0;i<N;i++)
{
cin>>y1[i].kucun;
}
for(int i=0;i<N;i++)
{
cin>>y1[i].price;
}
sort(y1,y1+N,cmp_average);
double shouchu=0;
double shouyi=0;
int j=0;
while(shouchu<D&&j<=(N-1))
{
if(y1[j].kucun<=(D-shouchu))
{
shouchu+=y1[j].kucun;
shouyi+=y1[j].price;
j++;
}
else if(y1[j].kucun>(D-shouchu))
{
double temp=y1[j].kucun/(D-shouchu);
shouyi+=y1[j].price/temp;
break;
}
}
cout<<setprecision(2)<<fixed<<shouyi<<endl;
system("pause");
return 0;
}
#include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;
int main()
{
string s;
cin>>s;
set<char> s1;
map<char,int> m1;
for(int i=0;i<s.size();i++)
{
if(s1.count(s[i])==0)
{
m1[s[i]]=1;
s1.insert(s[i]);
}
else
{
m1[s[i]]+=1;
}
}
map<char,int>::iterator it;
for(it=m1.begin();it!=m1.end();it++)
{
cout<<it->first<<":"<<it->second<<endl;
}
system("pause");
return 0;
}
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int A,B,C;
cin>>A>>B>>C;
int sum=A+B;
vector<int> v1;
if(sum==0)
{
cout<<"0"<<endl;
}
while(sum!=0)
{
int temp=sum%C;
v1.push_back(temp);
sum=sum/C;
}
for(int i=v1.size()-1;i!=-1;i--)
{
cout<<v1[i];
}
system("pause");
return 0;
}
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int a;
vector<int> v0;
vector<int> v1;
for(int i=0;i<10;i++)
{
int n;
cin>>n;
v0.push_back(n);
}
for(int i=0;i<10;i++)
{
for(int j=0;j<v0[i];j++)
{
v1.push_back(i);
}
}
int temp=0;
int time=-1;
if(v1[0]==0)
{
temp=1;
}
for(int i=0;i<v1.size();i++)
{
if(temp==1&&v1[i]==0)
{
time+=1;
}
else if(temp==1&&v1[i]!=0)
{
cout<<v1[i];
time+=1;
temp=0;
i=-1;
}
else if(temp==0)
{
if(i==time)
{
continue;
}
cout<<v1[i];
}
}
system("pause");
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s;
cin>>s;
int pos=0;
int start=1;
if(s[0]=='-')
{
cout<<"-";
}
pos=s.find("E",start);
string s1(s,start,pos-start);
start=pos+1;
string fuhao(s,start,1);
start+=1;
string s2;
for(int i=start;i<s.size();i++)
{
s2+=s[i];
}
if(fuhao=="+")
{
int weishu=stoi(s2);
int j=weishu+2-s1.size();
if(j>=0)
{
for(int i=0;i<s1.size();i++)
{
if(i==1)
{
continue;
}
cout<<s1[i];
}
for(int i=0;i<j;i++)
{
cout<<"0";
}
}
else if(j<0)
{
for(int i=0;i<s1.size();i++)
{
if(i==1)
{
continue;
}
cout<<s1[i];
if(i==weishu+1)
{
cout<<".";
}
}
}
}
if(fuhao=="-")
{
int weishu=stoi(s2);
if(weishu==0)
{
cout<<s1;
}
else
{
s1.replace(1,1,"");
cout<<"0.";
for(int i=1;i<weishu;i++)
{
cout<<"0";
}
cout<<s1;
}
}
system("pause");
return 0;
}