北航上机测试准备 程序3

/*
//成绩排序   成绩 姓名 年龄
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
struct std
{
int score;
char name[10];
int age;
bool operator < (const std &A)const{
if(score!=A.score)  return score<A.score;
int tmp=strcmp(name,A.name);
if(tmp!=0) return tmp<0;
else return age<A.age;
}
}buf[100];
void main()
{
int N;
scanf("%d",&N);
for(int i=0;i<N;i++)
scanf("%d%s%d",&buf[i].score,&buf[i].name,&buf[i].age);
sort(buf,buf+N);
for(int i=0;i<N;i++)
}




//日期wenti
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define IsYEAR(x) x%100!=0&&x%4==0||x%400==0?1:0
int dayofmonth[13][2]={
0,0,31,31,28,29,31,31,30,30,31,31,30,30,31,31,
31,31,30,30,31,31,30,30,31,31};
struct Date{
int Day;
int Month;
int Year;
void nextday(){
Day++;
if(Day>dayofmonth[Month][ISYEAR(Year)]){
Day=1;
Month++;
if(Month>12){
Year++:
Month=1;
}
}
}
};
int buf[5001][13][32];
int Abs(int x)
return x<0?-x:x;
int main()
{
Date tmp;
int cnt=0;
tmp.Day=1;
tmp.Month=1;
tmp.Year=0;
while(tmp.Year!=5001){
buf[tmp.year][tmp.month][tmp.day]=cnt;
tmp.nextday();
cnt++;
}
int d1,m1,y1;
int d2,m2,y2;
while(scanf("%4d%2d%2d",&y1,&m1,&d1)!=EOF)
{
scanf("%4d%2d%2d",&y2,&m2,&d2);
printf(Abs(buf[y1][m1][d1]-buf[y2][m2][d2]));
}
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ISYEAR(x) x%4==0&&x%100!=0||x%400==0?1:0
int dayofmonth[13][2]={
0,0,31,31,28,29,31,31,30,30,31,31,30,30,31,31,31,31,30,30,31,31,30,30,31,31};
struct next{
int day;
int month;
int year;
void nextday()
{
day++;
if(day>dayofmonth[month][ISYEAR(year)])
{
day=1;
month++;
if(month>12)
{
month=1;year++;
}
}
}
};
int buf[5001][13][32];
int Abs(int x){
return x>0?x:-x;}
void main()
{
next tmp;
tmp.day=1;
tmp.month=1;
tmp.year=0;
int cnt=0;
printf("22222222");
while(tmp.year!=5000)
{
buf[tmp.year][tmp.month][tmp.day]=cnt;
tmp.nextday();
cnt++;//printf("%d\n",cnt);
}
printf("333");
int d1,m1,y1,d2,m2,y2;
while(scanf("%4d%2d%2d",&y1,&m1,&d1)!=EOF){
scanf("%4d%2d%2d",&y2,&m2,&d2);
printf("%d",Abs(buf[y1][m1][d1]-buf[y2][m2][d2])+1);
}
}


*/
/*
//二分查找
#include<stdio.h>
#include<stdlib.h>
void main()
{
int buf[100];
int x;
scanf("%d",&x);
int n;
scanf("%d",&n);
int i;
for(i=0;i<n;i++)
scanf("%d",&buf[i]);
for(i=0;i<n;i++)
{
if(x==buf[i])
{


printf("%d",i);
break;
}
}
}


#include<stdio.h>
#include<stdlib.h>
void main()
{
int buf[100];
int x;
scanf("%d",&x);
int n;
scanf("%d",&n);
int i;
for(i=0;i<n;i++)
scanf("%d",&buf[i]);
std::sort(buf,buf+n);
int low=0,high=n-1,mid=(low+high)/2;
while(high>=low)
{
if(x>buf[mid]){
low=mid+1;mid=(low+high)/2;}
else high=mid-1;mid=(low+high)/2;
}
printf("%d\n",mid);
}


#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
struct student{
char no[100];
char name[100];
int age;
char sex[5];
bool operator <(const student&A)const{
return strcmp(no,A.no)<0;
}
}buf[500];
void main()
{
int n;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
scanf("%s%s%s%d",buf[i].no,buf[i].name,buf[i].sex,buf[i].age);
}
sort(buf,buf+n);
int t;
scanf("%d",&t);
while(t--!=0){
int ans=-1;
char x[30];
scanf("%s",x);
int top=n-1,base=0;
while(top>=base){
int mid=(top+base)/2;
int tmp=strcmp(buf[mid].no,x);
if(tmp==0){
ans=mid;
break;
}
else if(tmp>0) top=mid-1;
else base=mid+1;
}
if(ans==-1) printf("no");
else printf("%s %s %s %d\n",buf[ans].no,buf[ans].name,buf[ans].sex,buf[ans].age);
}
}




#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
struct goods{
double j;
double f;
double s;
bool operator<(const goods&A)const{
return s>A.s;
}
}buf[1000];
int main()
{
double m;
int n;
while(scanf("%lf%d",&m,&n)!=EOF){
if(m==-1&&n==-1) break;
for(int i=0;i<n;i++){
scanf("%lf%lf",&buf[i].j,buf[i].f);
buf[i].sex=buf[i].j/buf[i].f;
}
sort(buf,buf+n);
int idx=0;
double ans==0;
while(m>0&&idx<n){
if(m>buf[idx].f)
{
ans+=buf[idx].j;
m-buf[idx].f;
}
else{
ans+=buf[idx].j*m/buf[idx].f;
m==0;
}
idx++;
}
printf("%.3lf\n",ans);
}
}




#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
struct program{
int starttime;
int endtime;
bool operator<(const program&A)const{
return endtime<A.endtime;
}
}buf[100];
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
if(n==0)break;
for(int i=0;i<n;i++)
scanf("%d%d",buf[i].starttime,&buf[i].endtime);
sort(buf,buf+n);
int currenttime=0,ans=0;
for(int i=0;i<n;i++)
{
if(currenttime<=buf[i].starttime){
currenttime=buf[i].endtime;
ans++;
}
}
printf("%d\n",ans);
}
}
#include<stdio.h>
#include<stdlib.h>
#include<stack>
stack<int>s;
char str[100];
char ans[100];
void main()
{
while(scanf("%s",str)!=EOF)
{
int i;
for(i=0;str[i]!=0;i++){
if(str[i]=='('){
s.push(i);
ans[i]=' ';
}
else if(str[i]==')'){
if(s.empty()==false)
s.pop();
   ans[i]=' ';
   else ans[i]='?';
}
else ans[i]=' ';
}
while(!s.empty()){
ans[s.top()]='$';
s.pop();
}
ans[i]=0;
puts(str);
puts(ans);
}
}


*/
#include<stdio.h>
#include<stdlib.h>
#include<stack>
char str[220];
int mat[][5]={
1,0,0,0,0,
1,0,0,0,0,
1,0,0,0,0,
1,1,1,0,0,
1,1,1,0,0
};
stack<int>op;
stack<double>in;
void getop(bool&reto,int &retn,int &i){
if(i==0&&op.empty()==true){
reto=true;
retn=0;
return;
}
if(str[i]==0){
reto=true;
retn=0;
return;
}
if(str[i]>='0'&&str[i]<='9'){
reto=false;
}
else{
reto=true;
if(str[i]=='+')
retn=1;
else if(str[i]=='-')
retn=2;
else if(str[i]=='*')
retn=3;
else if(str[i]=='/')
retn=4;
i+=2;
return;
}
retn=0;
for(;str[i]!=' '&&str[i]!-0;i++){
retn*=10;
retn+=str[i]-'0';
}
if(str[i]==' ')
i++;
return;
}
void main()
{
while(gets(str)){
if(str[0]=='0'&&str[1]==0)break;
bool retop;int retnum;
int idx=0;
while(!op.empty()) op.pop();
while(!in.empty()) in.pop();
while(true)
{
getop(retop,retnum,idx);
if(retop==false){
in.push((double)retnum);
}
else{
double tmp;
if(op.empty()==true||mat[retnum][op.top()]==1){
op.push(retnum);
}
else{
while(mat[retnum][op.top()]==0){
int ret=op.top();
op.pop();
double b=in.top();
in.pop();
double a=in.top();
in.pop();
if(ret==1) tmp=a+b;
else if(ret==2) tmp=a-b;
else if(ret==3) tmp=a*b;
else tmp=a/b;
in.push(tmp);
}
op.push(retnum);
}
}
if(op.size()==2&&op.top()==0) break;
}
printf("%.2f\n",in.top());
}
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值