A - 圆桌问题: HDU - 4841

#include<iostream>
#include<vector>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
vector<int> table;
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
table.clear();
for(int i=;i<*n;++i)
{
table.push_back(i);
}
int pos = ;
for(int i=;i<n;++i)
{
pos = (pos+m-)%table.size();
table.erase(table.begin()+pos);
}
int j=;
for(int i=;i<*n;++i)
{
if(!(i%)&&i)cout<<endl;
if(j<table.size()&&i==table[j])
{
++j;
cout<<"G";
}
else
{
cout<<"B";
}
}
cout<<endl<<endl;
}
return ;
}

C - 简单计算器 HDU - 1237

好自闭啊,找了半天还是WA了,完全不知道WA在哪里了Orz,先存一个档:

#include<iostream>
#include<stack>
#include<stdio.h>
#include<string>
#include<map>
#define CHECK_NUM(ch) ('0'<=ch&&ch<='9')
#define CHECK_OP(ch) ('+'==ch ||'-'==ch||'*'==ch||'/'==ch ||'\0'==ch)
using namespace std;
map<char,int>dir;
stack<double> num;
stack<char> op;
stack<double> newnum;
stack<char> newop;
double OPT(double one,double two,char temp)
{
// printf("%f",two);
double three=;
switch(temp)
{
case '+':three = two + one;break;
case '-':three = two - one;break;
case '*':three = two * one;break;
case '/':three = two / one;break;
}
// printf("%c %lf = %lf\n",temp,one,three);
return three;
}
void initi()
{
while(!num.empty())num.pop();
while(!op.empty())op.pop();
while(!newop.empty())newop.pop();
while(!newnum.empty())newnum.pop();
}
void STACK(char ch)
{
// cout<<ch<<endl;
if(!op.empty()&&num.size()>)
{
char temp=op.top();
// cout<<"当前栈顶:"<<temp<<",当前扫描:"<<ch<<endl;
if(dir[temp]>=dir[ch])
{
op.pop();
double one=num.top();num.pop();
double two=num.top();num.pop();
num.push(OPT(one,two,temp));
// cout<<"入栈num:"<<num.top()<<endl;
} }
op.push(ch);
}
int main()
{
char ch='\0';
double result=; dir['+']=; dir['-']=;
dir['*']=; dir['/']=;
dir['\0']=;
while()
{
string a="";
getline(cin,a);
initi(); if(a=="")break;
for(int i=;i<=a.length();++i)
{
double nums=;
if(CHECK_NUM(a[i]))
{
while(CHECK_NUM(a[i]))
{
nums+=a[i]-'';
nums*=;
i++;
}
nums/=;
// cout<<"nums"<<nums<<endl;
num.push(nums);
// printf("%.2f\n",num.top());
} if(CHECK_OP(a[i]))
{
STACK(a[i]); //如果是操作数就入操作数栈
}
} while(!op.empty())
{
newop.push(op.top());
op.pop();
}
while(!num.empty())
{
newnum.push(num.top());
num.pop();
}
while(!newop.empty()&&newnum.size()>)
{
char temp=newop.top();newop.pop();
// cout<<"当前弹出:"<<temp<<endl;
double one=newnum.top();newnum.pop();
double two=newnum.top();newnum.pop();
newnum.push(OPT(two,one,temp));
// cout<<"入栈num:"<<newnum.top()<<endl;
}
// printf(">>%.2lf\n",newnum.top());
// cout<<newnum.size();
printf("%.2lf\n",newnum.top());
}
return ;
}

WA

贴一个师傅的AC:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<iomanip>
using namespace std; typedef long long LL;
#define rep(i,a,b) for(int i=a;i<b;++i) const double eps=1e-;
const int N=;
char str[N]; double stk1[N];//操作数栈
int p1;//操作数栈的栈顶指针
char stk2[N];//运算符栈
int p2;//运算符栈的栈顶指针 double op(double a,double b,char ch){
if(ch=='+')return a+b;
else if(ch=='-')return a-b;
else if(ch=='*')return a*b;
else return a/b;
} //优先级比较函数加括号的话,只需要修改这里就好了
//ch1:扫描到的,ch2:栈顶的
int comp(char ch1,char ch2)
{
int a=,b=;
if(ch1=='*'||ch1=='/')a=;
if(ch2=='*'||ch2=='/')b=;
return a<=b;
}
int main()
{
while(gets(str)) //读入一行
{ p1=,p2=;
int len=strlen(str);
if(len==&&str[]=='')break;
int i=;
double sum=;
while(i<len&&str[i]>=''&&str[i]<='')
{
sum=sum*+str[i]-'';
i++;
}
stk1[p1++]=sum;//得到操作数
while(i<len)
{
i++;//跳过空格
char ch=str[i];//读取操作数
i+=;//跳过空格
double sum=;//得到第二个操作数
while(i<len&&str[i]>=''&&str[i]<='')
{
sum=sum*+str[i]-'';
i++;
} if(p2==)//如果操作符栈为空,操作符就进栈
{
stk2[p2++]=ch;
}
else
{
//当前读到的操作数的优先级小于等于栈顶的优先级
//并且运算符栈不为空
while(p2>&&comp(ch,stk2[p2-]))
{ double ans=op(stk1[p1-],stk1[p1-],stk2[p2-]);//计算新的值
p2-=;
p1-=;
stk1[p1++]=ans;//新的值入操作数栈
}
stk2[p2++]=ch;
}
stk1[p1++]=sum;
}
while(p2!=)//当操作符栈不为空
{
double ans=op(stk1[p1-],stk1[p1-],stk2[p2-]);
p1-=;
stk1[p1++]=ans;
p2--;
}
printf("%.2f\n",stk1[]);
}
return ;
}

D - ACboy needs your help again! HDU - 1702

#include<iostream>
#include<string>
#include<queue>
#include<stack>
using namespace std;
int main()
{
int t,n,temp;
cin>>t;
while(t--)
{
string str,str1;
queue<int>Q;
stack<int>S;
cin>>n>>str;
for(int i=;i<n;++i)
{
if(str=="FIFO")
{
cin>>str1;
if(str1=="IN")
{
cin>>temp;
Q.push(temp);
}
if(str1=="OUT")
{
if(Q.empty()) cout<<"None"<<endl;
else
{
cout<<Q.front()<<endl;
Q.pop();
}
}
}
else
{
cin>>str1;
if(str1=="IN")
{
cin>>temp;S.push(temp);
}
if(str1=="OUT")
{
if(S.empty()) cout<<"None"<<endl;
else
{
cout<<S.top()<<endl;
S.pop();
} }
}
}
}
return ;
}

E - 看病要排队 HDU - 1873

#include<iostream>
#include<string>
#include<queue>
#include<stack>
using namespace std; int id;
typedef struct p
{
int id;
int pr;
}people;
bool operator < (const people &a,const people &b)
{
//当a,b的优先级一样的时候,比较a,b的编号
if(a.pr== b.pr) return (a.id > b.id);//当优先级一样的时候,先来的人先看病
return (a.pr < b.pr); }
priority_queue<people> A;
priority_queue<people> B;
priority_queue<people> C;
int intital()
{
while(!A.empty()) A.pop();
while(!B.empty()) B.pop();
while(!C.empty()) C.pop();
id=;
return ;
}
int main()
{
int num=;
while(scanf("%d",&num)!=EOF)
{
intital();
// cout<<"输入的n:"<<num<<endl;
for(int i=;i<num;++i)
{
string str;
people person;
int doctor;
cin>>str>>doctor;
// cout<<"str,doctor:"<<str<<","<<doctor<<endl; if(str=="IN")
{
++id;//人数自增
person.id=id;
cin>>person.pr; // cout<<",person.pr"<<person.pr<<endl;
switch(doctor)
{
case :
{
A.push(person);
break;
}
case :
{
B.push(person);
break;
}
case :
{
C.push(person);
break;
} }
}
else
{
switch(doctor)
{
case :
{
if(A.empty())
{
cout<<"EMPTY"<<endl;
}
else
{
cout<<A.top().id<<endl;
A.pop();
}
break;
}
case :
{
if(B.empty())
{
cout<<"EMPTY"<<endl;
}
else
{
cout<<B.top().id<<endl;
B.pop();
}
break;
}
case :
{
if(C.empty())
{
cout<<"EMPTY"<<endl;
}
else
{
cout<<C.top().id<<endl;
C.pop();
}
break;
} }
}
} }
return ;
}

士兵队列训练问题 HDU - 1276

#include<iostream>
#include<map>
#include<string>
#include<list>
using namespace std;
int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
int k=;
list<int>mylist;
list<int>::iterator it;
for(int i=;i<=n;++i)mylist.push_back(i);
while(mylist.size()>)
{
int num=;
for(it=mylist.begin();it!=mylist.end();)
{
if(num++%k==)
{
it = mylist.erase(it);
}
else
{
++it;
}
}
k==?k=:k=;
}
for(it=mylist.begin();it!=mylist.end();++it)
{
if(it!=mylist.begin())cout<<" ";
cout<<*it;
}
cout<<endl;
}
return ; }

G - 产生冠军 HDU - 2094

#include<iostream>
#include<set>
#include<string>
using namespace std;
int main()
{
set<string>A,B;
string s1,s2;
int n;
while(cin>>n&&n)
{
for(int i=;i<n;++i)
{
cin>>s1>>s2;
A.insert(s1);A.insert(s2);
B.insert(s2);
}
if(A.size()-B.size()==)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
A.clear();
B.clear();
}
return ;
}

H - Shopping HDU - 2648:map的遍历

#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
int n,m,p;
map<string,int>shop;
while(cin>>n)
{
string s;
for(int i=;i<=n;++i)cin>>s;
cin>>m;
while(m--)
{
for(int i=;i<=n;++i)
{
cin>>p>>s;
shop[s]+=p;
}
int rank =;
map<string,int>::iterator it;
for(it=shop.begin();it!=shop.end();it++)
{
if(it->second>shop["memory"])
{
rank++;
}
}
cout<<rank<<endl;
}
shop.clear();
} return ; }

I - Ignatius and the Princess II HDU - 1027:next_permutation

#include<iostream>
#include<map>
#include<string>
#include<list>
#include<algorithm>
using namespace std;
int a[];
int main()
{
int m,n;
while(cin>>n>>m)
{
for(int i=;i<=n;++i) a[i]=i;
int b=;
do
{
if(b==m)break;
b++;
}while(next_permutation(a+,a+n+));
for(int i=;i<n;++i)
{
cout<<a[i]<<" ";
}
cout<<a[n]<<endl;
}
return ;
}

J - 排列2 HDU - 1716

#include<iostream>
#include<map>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include<set>
#include<string.h>
using namespace std;
int main()
{
while()
{
int num[]={};
vector<int> m[];
int index[];
memset(index,,sizeof(int)*);
int count=;
map<int,bool> visit;//标记是否重复出现
set<int>s;
s.clear();
for(int i=;i<;++i)
{
cin>>num[i];
if(num[i]==)++count; //计算0的个数
index[num[i]]=;
}
if(count==)break;//如果有4个0就结束掉
sort(num,num+);
do
{
int str=;
if(num[]==)continue;
for(int i=;i<;++i)
{
str+=num[i];
str*=;
}
str/=;
// cout<<">>"<<str<<","<<visit[str]<<" ";
if(!visit[str])
{
m[num[]].push_back(str);
// cout<<"输入到导出表的:"<<"m["<<num[0]<<"]="<<str<<endl;
visit[str]=;
} }while(next_permutation(num,num+));
int i=,k=;
for(int j=;j<;++j)if(index[j])++k;
for(;i<=;++i)
{
if(index[i])
{
// cout<<"第一组"<<i<<endl;
index[i]=;
cout<<m[i][];
for(int j=;j<m[i].size();++j)
{
cout<<" "<<m[i][j];
}
k--;
cout<<endl;
}
if(k==)break;
}
for(;i<=;++i)
{ if(index[i])
{ index[i]=;
cout<<m[i][];
for(int j=;j<m[i].size();++j)
{
cout<<" "<<m[i][j];
}
}
}
cout<<endl;
} return ;
}

格式错误,不想改了,以后再说

贴一份AC:https://blog.csdn.net/leo6033/article/details/79249163

#include<stdio.h>
int a[],i;
void sum(int num[],int x1, int x2, int x3, int x4)
{
num[i++] = a[x1] * + a[x2] * + a[x3] * + a[x4];
num[i++] = a[x1] * + a[x2] * + a[x4] * + a[x3];
num[i++] = a[x1] * + a[x3] * + a[x2] * + a[x4];
num[i++] = a[x1] * + a[x3] * + a[x4] * + a[x2];
num[i++] = a[x1] * + a[x4] * + a[x2] * + a[x3];
num[i++] = a[x1] * + a[x4] * + a[x3] * + a[x2];
}
int main()
{
int p = ;
while (~scanf("%d %d %d %d", &a[], &a[], &a[], &a[]))
{
int num[] = { };
if (!a[] && !a[] && !a[] && !a[])
{
break;
}
if (p == )p = ;
else printf("\n");
i = ;
sum(num, , , , );
sum(num, , , , );
sum(num, , , , );
sum(num, , , , );
int temp,j;
for (i = ; i >; i--)
{
for (j = ; j < i-; j++)
{
if (num[j] > num[j + ])
{
temp = num[j];
num[j] = num[j + ];
num[j + ] = temp;
}
}
} for (i = ; i < ; i++)
{
//printf("%d ",num[i]);
if (num[i] != num[i + ]&&num[i]>)
{
printf("%d", num[i]);
if (num[i] / != num[i + ] / )
{
printf("\n");
}
else
{
printf(" ");
}
}
}
printf("%d\n", num[i]);
}
return ;
}

最新文章

  1. sublime text2 bracketHighLighter 配置
  2. oracle报错:ORA-28000: the account is locked
  3. 安卓界面篇(一) 自定义一个topbar
  4. UIImageView 点击放大缩小
  5. ssh 框架整合试例 (spring+struts2+hibernate)
  6. [STL]单词转换
  7. android143 360 短信电话拦截
  8. AFNetwork 作用和使用方法具体解释
  9. mac相关
  10. 【界面优化】使用viewpagerindicator添加下划线滑动动画
  11. 更少的直接百度,更多的取看API
  12. Android Studio的使用(四)--生成Get、Set方法
  13. Shiro第六篇【验证码、记住我】
  14. 解决postman环境切换,自动获取api签名时间及签名
  15. eclipse检出SVN项目的正确步骤
  16. GitHub上传本地文件
  17. 大型互联网架构概述 关于架构的架构目标 典型实现 DNS CDN LB WEB APP SOA MQ CACHE STORAGE
  18. 阿里云 CentOS7安装redis4.0.9并开启远程访问
  19. TensorFlow分布式部署【单机多卡】
  20. memcached 学习笔记 1

热门文章

  1. Arduino入门之前
  2. Python3数据分析与挖掘建模实战 学习 教程
  3. mysql 多表查询 以及 concat 、concat_ws和 group_concat
  4. HDU.6186.CSCource.(前缀和数组和后缀和数组)
  5. Vue源码详细解析:transclude,compile,link,依赖,批处理...一网打尽,全解析!
  6. (转载)图解Java多态内存分配以及多态中成员方法的特点
  7. 左侧点击后右侧添加tab标签栏以及内容
  8. c知识点总结2
  9. 搭建Eclipse+pydev+python2.7.5+django1.5.1+mysql5.0.45平台
  10. Tomcat支持SSL加密网站