Your Ride Is Here
/*
PROG:ride
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include<fstream>
using namespace std;
string s1,s2;
int main()
{
ifstream fin("ride.in");
ofstream fout("ride.out");
while(fin>>s1>>s2)
{
int sum1=,sum2=;
for(int i=;i<s1.length();i++)
sum1=(sum1*(s1[i]-'A'+))%;
for(int i=;i<s2.length();i++)
sum2=(sum2*(s2[i]-'A'+))%;
if(sum1==sum2)
fout<<"GO"<<endl;
else
fout<<"STAY"<<endl;
} return ;
}
ride
Greedy Gift Givers
分析:模拟,开一个map维护名字和对应的收支即可,注意结束条件
/*
PROG:gift1
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include<fstream>
using namespace std;
const int maxn=;
string x[maxn];
typedef pair<int,int> p;
map<string,p> mp;
int main()
{
ifstream fin("gift1.in");
ofstream fout("gift1.out");
int t;
fin>>t;
for(int i=;i<t;i++){
fin>>x[i];
mp[x[i]].first=; //收入
mp[x[i]].second=; //支出
}
int n=t;
while(n--){
string name;
fin>>name;
int money,num;
fin>>money>>num;
if(num==) continue;
int div=money/num;
int mod=money%num;
mp[name].second+=(money-mod);
for(int i=;i<num;i++){
string ch;
fin>>ch;
mp[ch].first+=div;
}
}
for(int i=;i<t;i++){
fout<<x[i]<<" ";
fout<<mp[x[i]].first-mp[x[i]].second<<endl;
}
return ;
}
gift1