今天下午状态不错,4A。。主要是比较简单。。做出来的中只有一道题不算水题吧。。
比赛地址:点击打开链接
Problem A:Mad Scientist
很水的一道题,读题略微坑人,明白了就好。从一种表示方法转移到另一种表示方法。第一个数表示样例,第二个数K表示小于等于K的总数有几个,数的值等于它下标所在的位置(从1开始)。
#include <iostream>
#include <cstring>
using namespace std;
int tarnum[1009];
int main()
{
int testcase;
while(cin>>testcase && testcase!=0)
{
memset(tarnum,0,sizeof(tarnum));
int totalcounter=0;
int tmp;
for(int i=1;i<=testcase;i++)
{
cin>>tmp;
if(tmp>totalcounter)
totalcounter=tmp;
for(int j=1;j<=tmp;j++)
{
if(tarnum[j]==0)
tarnum[j]=i;
}
}
for(int t=1;t<=totalcounter;t++)
{
if(t!=totalcounter)
cout<<tarnum[t]<<" ";
else
cout<<tarnum[t]<<endl;
}
}
return 0;
}
Problem B: Mirror on the Wall
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string tar;
while(cin>>tar && tar!="#")
{
string res;
int inlaw=1;
for(int i=0;i<tar.size();i++)
{
if(tar[i]!='b'&&tar[i]!='d'&&tar[i]!='p'&&tar[i]!='q'&&tar[i]!='i'&&tar[i]!='o'&&tar[i]!='v'&&tar[i]!='w'&&tar[i]!='x')
inlaw=0;
}
reverse(tar.begin(),tar.end());
for(int i=0;i<tar.size();i++)
{
if(tar[i]=='p')
res+='q';
else if(tar[i]=='q')
res+='p';
else if(tar[i]=='b')
res+='d';
else if(tar[i]=='d')
res+='b';
else
res+=tar[i];
}
if(inlaw==1)
{
cout<<res<<endl;
}
else
cout<<"INVALID"<<endl;
}
return 0;
}
Problem D: Voting
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cmath>
using namespace std;
int main()
{
string tar;
while(cin>>tar && tar!="#")
{
int totalpeople=tar.size();
double halfman=totalpeople/2.0;
int yesvote=0;
int novote=0;
int absent=0;
for(int i=0;i<tar.size();i++)
{
if(tar[i]=='Y')
yesvote+=1;
else if(tar[i]=='N')
novote+=1;
else if(tar[i]=='A')
absent+=1;
}
if(totalpeople-absent>halfman)
{
if(yesvote>novote)
cout<<"yes"<<endl;
else if(novote>yesvote)
cout<<"no"<<endl;
else
cout<<"tie"<<endl;
}
else
{
cout<<"need quorum"<<endl;
}
}
return 0;
}