C++数据结构-结构体

学生信息

http://oj.61coding.cn/problem.php?cid=1028&pid=0

#include<bits/stdc++.h>
using namespace std;
struct student{
string name;
char sex;
int age;
double weight;
};
int main(){
student stu;
cin >> stu.name >> stu.sex >> stu.age >> stu.weight;
cout << stu.name <<" "<< stu.sex <<" "<< stu.age <<" ";
cout << fixed << setprecision(1) << stu.weight << endl;
return 0;
}

年龄排序

http://oj.61coding.cn/problem.php?cid=1028&pid=1

#include<bits/stdc++.h>
using namespace std;
struct stu{
string name;
string sex;
int year,month;
};
const int MAXN = 110;
stu a[MAXN]; bool cmp(stu stu1,stu stu2){
if(stu1.year!=stu2.year){
return stu1.year>stu2.year;
}
return stu1.month>stu2.month;
}
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i].name >> a[i].sex >> a[i].year >> a[i].month;
sort(a+1,a+n+1,cmp);
for(int i = 1; i <= n; i++){
cout<< a[i].name <<" "<< a[i].sex<<" ";
cout<< a[i].year <<" "<< a[i].month<<endl;
}
return 0;
}

猴子选大王

#include<bits/stdc++.h>
using namespace std;
int m,n;
bool a[101];
int main(){
cin>>m>>n;
int num=0,w=m,t=0;
while(m>1){
t++;
if(a[t]==false){
num++;
}
if(num==n){
a[t]=true;
num=0;
m--;
}
if(t==w){
t=0;
}
}
for(int i=1;i<=w;i++){
if(a[i]==false){
cout<<i;
break;
}
}
}
#include<bits/stdc++.h>
using namespace std;
int m,n;
bool a[1001];
int main(){
cin>>m>>n;
int num=0,w=m,t=0;
int nn=n%m;
if(nn==0){
nn=m;
}while(m>1){
t++;
if(a[t]==false){
num++;
} if(num==nn){
a[t]=true;
num=0;
m--;
nn=n%m;
if(nn==0){
nn=m;
}

}
if(t==w){
t=0;
}
}
for(int i=1;i<=w;i++){
if(a[i]==false){
cout<<i;
break;
}
}
}
#include<bits/stdc++.h>
using namespace std;
struct monkey{
int num;
int next;
}a[1010]; int main(){
int n,k,count=0,remain,cur,pre;
cin>>n>>k;
for(int i=1;i<n;i++){
a[i].num=i;
a[i].next=i+1;
} a[n].num=n;
a[n].next=1;
remain=n;
cur=1;
pre=n;
while(remain>1){
count++;
if(count==k){
a[pre].next=a[cur].next;
remain--;
count=0;
}else{
pre = cur;
}
cur=a[cur].next;
}
cout<<a[cur].num<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct monkey{
int num;//当前猴子位置
int next;//下一个猴子位置
}a[1010]; int main(){
//n只猴子 报数到k时出圈
int n,k;
//从0报数开始计数到count=k时出圈 remain当前还剩余可报数的猴子
int count=0,remain;
// 当前猴子位置和前一个猴子位置 当前出队,需要修改pre的next
int cur,pre; cin>>n>>k;
for(int i=1;i<n;i++){//n-1个点建立循环链表
a[i].num=i;
a[i].next=i+1;
}
//第n个点特殊处理
a[n].num=n;//第n个点建立循环链表
a[n].next=1;//第n个点建立循环链表 remain=n;//默认剩余可以报数为n int kk=k%remain;
if(kk==0){
kk=remain;
}
cur=1;//当前从第一个开始
pre=n;//删除第一个使用
while(remain>1){//报数到k出圈 剩下最后一个猴子为止
count++;//报数加1
if(count==kk){//报数到k的猴子出圈
a[pre].next=a[cur].next;//链表中删除当前猴子
remain--;//出圈 猴子数减一
count=0;//从0开始重新报数
kk=k%remain;
if(kk==0){
kk=remain;
}
}else{
pre = cur;//记录当前猴子的前一个猴子位置
}
cur=a[cur].next;//当前猴子的下一个位置
}
cout<<a[cur].num<<endl;//剩余最后一个猴子的位置
return 0;
}

奖学金

http://oj.61coding.cn/problem.php?cid=1028&pid=3

#include<bits/stdc++.h>
using namespace std;
struct node{
int num,chi,mat,eng,tot;
};
node a[311];
bool cmp(node x,node y){
if (x.tot !=y.tot){
return x.tot>y.tot;
}else if (x.chi!=y.chi){
return x.chi>y.chi;
} else return x.num<y.num;
}
int main(){
int n; cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i].chi>>a[i].mat>>a[i].eng;
a[i].num=i;
a[i].tot=a[i].chi+a[i].eng+a[i].mat;
}
sort(a+1,a+n+1,cmp);
for (int i=1;i<=5;i++){
cout<<a[i].num<<" "<<a[i].tot<<endl;
}
return 0;
}

桌面窗体重叠

http://oj.61coding.cn/problem.php?cid=1028&pid=4

#include<bits/stdc++.h>
using namespace std;
struct twindow{
int left,right,top,bottom;
};
twindow wina,winb,tmp; twindow indata(){
twindow tmp;
cin >> tmp.left >> tmp.right >> tmp.top >> tmp.bottom;
return tmp;
} int main(){ wina = indata();
winb = indata();
tmp.left = max(wina.left,winb.left);
tmp.right = min(wina.right,winb.right);
tmp.top = max(wina.top,winb.top);
tmp.bottom = min(wina.bottom,winb.bottom);
int s = (tmp.right - tmp.left) * (tmp.bottom - tmp.top);
if((tmp.right <= tmp.left) || (tmp.bottom <= tmp.top)) s = 0;
cout << s << endl;
return 0;
}

最新文章

  1. C++ 之namespace常见用法
  2. 剑指Offer面试题:9.二进制中1的个数
  3. PowerBuilder 简介及应用 - 数据库系统原理
  4. 揭秘PHP匿名函数
  5. BZOJ4551: [Tjoi2016&amp;Heoi2016]树
  6. TADOTable 用过滤事件 后 记录数据和 记录的内容
  7. centos7 搭建docker内运行rabbitmq,然后再镜像ha方案的完全教程,暂时一个宿主机只能运行一个docker的rabbitmq,但是集群 ha都正常
  8. (链接保存)CentOS 6.6下yum快速升级内核
  9. Linux下gcc和g++编译helloworld
  10. DB天气app冲刺二阶段第三天
  11. pm grant 命令
  12. Cplus
  13. 依赖注入及AOP简述(十一)——生命周期管理 .
  14. Android查缺补漏(View篇)--在 Activity 的 onCreate() 方法中为什么获取 View 的宽和高为0?
  15. C#线程同步--线程通信
  16. Nginx使用教程(八):使用Nginx缓存之Memcached缓存
  17. 百度富文本Ueditor编辑器的使用
  18. The packaging and installation process of Android programs
  19. oracle基础——内存管理、优化
  20. linux 打开一个文件现swap文件

热门文章

  1. 基于Unet+opencv实现天空对象的分割、替换和美化
  2. Introduction &amp; Directory
  3. 论文解读(CAN)《Contrastive Adaptation Network for Unsupervised Domain Adaptation》
  4. Spark通信框架RPC介绍
  5. 最最最常用的Git提交规范以及常用命令总结
  6. 电脑微信小程序抓包
  7. final关键字用于修饰局部变量-final关键字用于修饰成员变量
  8. Spring异步Async和事务Transactional注解
  9. Spring中常见的注解
  10. 提供给用户使用的表格样式自定义工具,适用于elementUI表格