【2013春季SD高校ACM周赛8(SDUT)】各水题题解

今天下午状态不错,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


依然水题,注意没有投票资格的也算到场了,不计入过半数的50%中。。

#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;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值