D - Counterfeit Dollar(第二季水)
Description
Input
Output
Sample Input
1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even
Sample Output
K is the counterfeit coin and it is light. 这道题如果找不到方法那么分好多种情况一种一种来分析很麻烦
开始写的代码就没有找到方法,将题目样例中的情况分析完结果还有好多种情况 以下代码只考虑了样例情况 分析第二种情况时 发现太麻烦了 就停下来了
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int t;
char f1(char* a,char* b,char* c,char* d,char* e,char* f) //a、b、c、d四个even,e、f为up||down
{
int n1=strlen(e),n2=strlen(f);
for(int i=;i<n1;i++){
if(strchr(a,e[i])==NULL&&strchr(b,e[i])==NULL&&strchr(c,e[i])==NULL&&strchr(d,e[i])==NULL){
t=;
return e[i];
}
}
for(int i=;i<n2;i++){
if(strchr(a,f[i])==NULL&&strchr(b,f[i])==NULL&&strchr(c,f[i])==NULL&&strchr(d,f[i])==NULL){
t=;
return f[i];
}
}
}
/*char f2(char* a,char* b,char* c,char* d,char* e,char* f) //a、b为even,其他为up||down
{ }*/
int main()
{
int n,i;
cin>>n; while(n--)
{
char str[][];
char k;
for(i=;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
//for(i=0;i<9;i++)cout<<i<<" "<<str[i]<<endl;
if(str[][]=='e'&&str[][]=='e'&&(str[][]=='u'||str[][]=='d')){
k=f1(str[],str[],str[],str[],str[],str[]);
cout<<k<<" is the counterfeit coin and it is ";
if(str[][]=='u'){
if(t==)cout<<"heavy. ";
else cout<<"light. ";
}
else{
if(t==)cout<<"light. ";
else cout<<"heavy. ";
}
}
else if(str[][]='e'&&str[][]=='e'&&(str[][]=='u'||str[][]=='d')){
k=f1(str[],str[],str[],str[],str[],str[]);
cout<<k<<" is the counterfeit coin and it is ";
if(str[][]=='u'){
if(t==)cout<<"heavy. ";
else cout<<"light. ";
}
else{
if(t==)cout<<"light. ";
else cout<<"heavy. ";
}
}
else if(str[][]=='e'&&str[][]=='e'&&(str[][]=='u'||str[][]=='d')){
k=f1(str[],str[],str[],str[],str[],str[]);
cout<<k<<" is the counterfeit coin and it is ";
if(str[][]=='u'){
if(t==)cout<<"heavy. ";
else cout<<"light. ";
}
else{
if(t==)cout<<"light. ";
else cout<<"heavy. ";
}
}
/* else if(str[2][0]=='e'&&str[5][0]!='e'&&str[8][0]!='e'){
}
else if(str[5][0]=='e'&&str[2][0]!='e'&&str[8][0]!='e'){
}
else if(str[8][0]=='e'&&str[5][0]!='e'&&str[2][0]!='e'){
}
*/
}
//system("pause");
return ;
}
找找方法 换一种简单的方法来做
给所有银币赋值1
从A开始给银币赋值0或 2 天平两端相加判断是否符合even up down的条件 若符合 则得出结果
#include<iostream>
#include<string>
using namespace std;
int s[];
int f(string a,string b,int n)
{
int p=,q=;
for(int j=;j<n;j++){
p+=s[a[j]-'A'];
q+=s[b[j]-'A'];
}
if(p==q)return ;
if(p>q)return ;
else return -;
}
int main()
{
int n,i;
cin>>n;
while(n--)
{
for(i=;i<;i++)s[i]=;
string str[];
int k;
bool flag=false;
for(i=;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
for(;i<;i++)cin>>str[i];
int n1=str[].length(),n2=str[].length(),n3=str[].length();
for(i=;i<;i++){
s[i]=;
k=f(str[],str[],n1);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n2);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n3);
if((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d')){
flag=true;
cout<<(char)(i+'A')<<" is the counterfeit coin and it is light. "<<endl;
}
s[i]=;
}
if(!flag){
for(i=;i<;i++){
s[i]=;
k=f(str[],str[],n1);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n2);
if(!((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d'))){
s[i]=;
continue;
}
k=f(str[],str[],n3);
if((k==&&str[][]=='e')||(k==&&str[][]=='u')||(k==-&&str[][]=='d')){
cout<<(char)(i+'A')<<" is the counterfeit coin and it is heavy. "<<endl;
}
s[i]=;
}
}
}
//system("pause");
return ;
}
D - Counterfeit Dollar(第二季水)的更多相关文章
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- I - Long Distance Racing(第二季水)
Description Bessie is training for her next race by running on a path that includes hills so that sh ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- N - Robot Motion(第二季水)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- T - 阿牛的EOF牛肉串(第二季水)
Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的 ...
- E - Number Sequence(第二季水)
Description A single positive integer i is given. Write a program to find the digit located in the p ...
随机推荐
- Java Timer触发定时器
XML: <!-- Java Timer定时 --> <!-- <bean id="shortUrlTask" class=" com.sprin ...
- 并行查询提高sql查询速度
新项目在使用Oracle开发中遇到测试库千万级数据导致数据慢,除去加索引和存储过程可以明显提速外,使用并行也可以提速 select /*+parallel(a,8)*/ a.* from a 加上/* ...
- codeforces432D Prefixes and Suffixes(kmp+dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud D. Prefixes and Suffixes You have a strin ...
- QTestlib Manual翻译
Trolltech公司提供的QTestlib框架,是一种针对基于QT编写的程序或库的单元测试工具.QTestLib提供了单元测试框架的基本功能,并提供了针对GUI测试的扩展功能. 目录: QtestL ...
- (原)VS2013在Release情况下使用vector有时候会崩溃的一个可能原因
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5016352.html 参考网址: http://www.cnblogs.com/BryZ/archiv ...
- vb.net中存储过程的使用
在机房收费系统过程中,试着使用了存储过程,离之前数据库的学习已经有些日子了.之前对于存储过程的了解也是听过而已,非常不清楚.因此,写这篇博客! 专业概念:存储过程是一个SQL语句和控制结构的集合,创建 ...
- 关于反射中获取Fields,method,Construts简单介绍
* getFields()与getDeclaredFields()区别:getFields()只能访问类中声明为公有的字段,私有的字段它无法访问,能访问从其它类继承来的公有方法.getDeclared ...
- 夏宇闻教授谈FPGA工程师的入门学习
1. 必须清楚自己究竟适合不适合做工程师. 看看自己的性格特点,是不是特别安静,又耐得住寂寞.因为FPGA工程师是一个辛苦的工作,不但要通过不断学习研究提升自己的设计水平,还要经常性的熬夜加班敲写代码 ...
- 压缩、解压缩流GZipStream
如果要在压缩过程中检查错误或要与其他操作系统所用程序共享压缩数据,则要是用GZipStream类.GZipStream类包含是用GZip数据格式进行压缩和解压缩文件的方法,该类不能用于解压缩大于4GB ...
- SQL 通配符
在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符.SQL 通配符必须与 LIKE 运算符一起使用,必须放在引号内. 在 SQL 中,可使用以下通配符: %:替代一个或多个字符. _:仅替代 ...