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 ...
随机推荐
- qq去广告
首先呢,在文件资源管理器中选择查看"隐藏的项目"或"显示隐藏的文件.文件夹和驱动器"(入口不一样,选择显示隐藏文件的方式也不一样),随后进入 C:\Users\ ...
- c_str()函数
#include <string.h> const char *c_str(); 返回字符串地址,是一个c函数,返回类型const char*c_str()函数返回一个指向正规C字符串的指 ...
- hdu3830 (二分+LCA)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Checkers Time Limit: 2000/1000 MS (Java/O ...
- (原)Ubuntu16中卸载并重新安装google的Protocol Buffers
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5782992.html 目前最新的是1.6.1 1. 卸载掉老版本的Protocol: sudo apt ...
- (原+转)VS2013:正在从以下位置加载符号
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5158020.html 这段时间启动调试时,vs2013加载时间很长很长...然后下面网址给出了解决方法 ...
- 异常处理与调试5 - 零基础入门学习Delphi54
调试(Debug) 让编程改变世界 Change the world by program [caption id="attachment_2731" align="al ...
- BC 65 game
主持人一直某个数字在1到n范围,假设甲乙已经知道,甲先猜乙后,都采用最优策略,主持人说偏大还是偏小,不断缩小范围,问最后乙能会获胜的X的取值的个数. 如果n为奇数,那么仅当x=n/2乙必然获胜,若为奇 ...
- request.getParamer()
eturns the value of a request parameter as a String, or null if the parameter does not exist. Reques ...
- Effective Java单元测试JUnit - 就是爱Java
实作了RoleImpl class,现在要开始单元测试了,或许你会觉得奇怪,才刚做好一个class而已,它并没有商业规则,只有getter/setter与clone(),那是要测试什么呢?没错,传统上 ...
- WPF笔记(2.7 文字布局)——Layout
原文:WPF笔记(2.7 文字布局)--Layout 这一节介绍的是文字布局的几个控件:1.TextBlock 最基本的文字控件可以配置5个Font属性.TextWraping属性,&quo ...