锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
綆絳旓細
/*
ID: lixianm1
PROG: friday
LANG: C++
*/
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cassert>
inline bool IsLeapYear(unsigned int nYear) {return ((!(nYear&3))&&(0!=nYear%100))||(0==nYear%400);}
int main(int argc, char* argv[])
{
//////////////////////////////////////////////////////////////////////////open the file
std::string strInFile = "friday.in";
std::string strOutFile = "friday.out";
std::ifstream fin(strInFile.c_str());
std::ofstream fout(strOutFile.c_str());
if (!fin)
{
std::cout<<"failed to open file for read"<<std::endl;
return 1;
}
if (!fout)
{
std::cout<<"failed to open file for write"<<std::endl;
fin.close();
return 1;
}
//////////////////////////////////////////////////////////////////////////read file and init all variables
int N;
fin>>N;
//////////////////////////////////////////////////////////////////////////process
static int month_day[]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static int month_day2[]={0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int aWeekCount[7]={0};
unsigned int nTotalDays= 0;
for (int i=0; i<N; ++i)
{
for (int nMonth=1; nMonth<13; ++nMonth)
{
++aWeekCount[(nTotalDays+12)%7];
if (!IsLeapYear(1900+i))
{
nTotalDays+=month_day[nMonth];
}else
{
nTotalDays+=month_day2[nMonth];
}
}
}
//////////////////////////////////////////////////////////////////////////write the process result
for (int i=0; i<6; ++i)
{
fout<<aWeekCount[(i+5)%7]<<" ";
}
fout<<aWeekCount[4]<<std::endl;
//////////////////////////////////////////////////////////////////////////end and exit
fin.close();
fout.close();
//system("pause");
return 0;
}
]]>
榪樻槸姣旇緝綆鍗曠殑
綆絳旓細
/*
ID: lixianm1
PROG: ride
LANG: C++
*/
#include <fstream>
#include <iostream>
#include <string>
unsigned int hash(const std::string& s)
{
unsigned int nNum = 1;
unsigned int nSize = s.length();
for (int i= 0; i<nSize; ++i)
{
nNum*=(s[i]-'A'+1);
}
return nNum%47;
}
int main(int argc, char* argv[])
{
std::string strInFile = "ride.in";
std::string strOutFile = "ride.out";
std::ifstream fin(strInFile.c_str());
if (!fin)
{
std::cout<<"failed to open file for read"<<std::endl;
return 1;
}
std::string strComet, strGroup;
std::getline(fin, strComet);
std::getline(fin, strGroup);
fin.close();
std::ofstream fout(strOutFile.c_str());
if (!fout)
{
std::cout<<"failed to open file for write"<<std::endl;
return 1;
}
if (hash(strComet)==hash(strGroup))
{
fout<<"GO"<<std::endl;
}else
{
fout<<"STAY"<<std::endl;
}
fout.close();
return 0;
}
]]>
棰樼洰鏈瘮杈冪畝鍗曪紝浣嗘垜璇諱簡鍗婂ぉ鎵嶇畻璇繪噦錛岃嫳鏂囨按騫寵窡涓嶄笂浜嗐?br> 棰樼洰澶ф剰錛氭湁NP涓漢錛屾瘡涓漢閮藉悜鍏朵粬浜洪侀挶錛屽悓鏃朵粬鍙堜細鏀跺埌鍒漢閫佺粰浠栫殑閽便傞鐩姹傝綆楁瘡涓漢鏀跺埌鐨勯挶姣旈佸嚭鐨勯挶澶氬灝戙?br>
瑙g瓟錛?br>
/*
ID: lixianm1
PROG: gift1
LANG: C++
*/
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cassert>
typedef std::vector<std::string> StrVector;
struct Person
{
std::string name; // name
int money_send; // money for sending
int money_receive; // money received
StrVector receiver; // all receivers
Person()
{
money_send = 0;
money_receive = 0;
}
};
typedef std::map<std::string, Person> PersonMap;
int main(int argc, char* argv[])
{
//////////////////////////////////////////////////////////////////////////open the file
std::string strInFile = "gift1.in";
std::string strOutFile = "gift1.out";
std::ifstream fin(strInFile.c_str());
std::ofstream fout(strOutFile.c_str());
if (!fin)
{
std::cout<<"failed to open file for read"<<std::endl;
return 1;
}
if (!fout)
{
std::cout<<"failed to open file for write"<<std::endl;
fin.close();
return 1;
}
//////////////////////////////////////////////////////////////////////////read file and init all variables
int nPersonNum;
PersonMap mPerson;
StrVector vPersonName;
fin>>nPersonNum;
assert(nPersonNum>0);
for(int i=0; i<nPersonNum; ++i)
{
Person person;
fin>>person.name;
mPerson[person.name]= person;
vPersonName.push_back(person.name);
}
std::string strName;
while(fin>>strName)
{
fin>>mPerson[strName].money_send;
int nReceiver;
fin>>nReceiver;
std::string strReceiverName;
for (int i=0; i<nReceiver; ++i)
{
fin>>strReceiverName;
mPerson[strName].receiver.push_back(strReceiverName);
}
}
//////////////////////////////////////////////////////////////////////////process
for (PersonMap::iterator iter= mPerson.begin(); mPerson.end()!=iter; ++iter)
{
Person& person = iter->second;
int nReceiverNum = person.receiver.size();
if ((0!=nReceiverNum))
{
int nMoneySend = person.money_send/nReceiverNum;
for (int i=0; i<nReceiverNum; ++i)
{
mPerson[person.receiver[i]].money_receive+= nMoneySend;
}
person.money_send = nMoneySend*nReceiverNum;
}
}
//////////////////////////////////////////////////////////////////////////write the process result
for (StrVector::iterator iter= vPersonName.begin(); vPersonName.end()!=iter; ++iter)
{
fout<<*iter<<" "<<mPerson[*iter].money_receive-mPerson[*iter].money_send<<std::endl;
}
//////////////////////////////////////////////////////////////////////////end and exit
fin.close();
fout.close();
//system("pause");
return 0;
}
]]>