C/C++之(二)洛谷刷题基础 中

简介: C/C++之(二)洛谷刷题基础 中

【P4414】 [COCI2006-2007#2] ABC

 

题目描述

You will be given three integers A, B and C. The numbers will not be given in that exact order, but we do know that A is less than B and B less than C. In order to make for a more pleasant viewing, we want to rearrange them in the given order.

输入格式

The first line contains three positive integers A, B and C, not necessarily in that order. All three numbers will be less than or equal to 100. The second line contains three uppercase letters 'A', 'B' and 'C' (with no spaces between them) representing the desired order.

输出格式

Output the A, B and C in the desired order on a single line, separated by single spaces.

题意翻译

【题目描述】

三个整数分别为 A,B,CA,B,C。这三个数字不会按照这样的顺序给你,但它们始终满足条件:A < B < CA

【输入格式】

第一行包含三个正整数 A,B,CA,B,C,不一定是按这个顺序。这三个数字都小于或等于 100100。第二行包含三个大写字母 AA、BB 和 CC(它们之间没有空格)表示所需的顺序。

【输出格式】

在一行中输出 AA,BB 和 CC,用一个 (空格)隔开。

感谢 @smartzzh 提供的翻译

输入输出样例

输入  

1 5 3

ABC

输出  

1 3 5

输入  

6 4 2

CAB

输出  

6 2 4

#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3],i;
  char x,y,z;
  for(i=0;i<3;i++){
    cin >> a[i]; 
  }
  cin >> x >> y >> z;
  sort(a,a+3);
  if(x=='A'&&y=='B'&&z=='C'){
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
  }  
  if(x=='B'&&y=='A'&&z=='C'){
    cout << a[1] << " " << a[0] << " " << a[2] << endl;
  }
  if(x=='A'&&y=='C'&&z=='B'){
    cout << a[0] << " " << a[2] << " " << a[1] << endl;
  }
  if(x=='B'&&y=='C'&&z=='A'){
    cout << a[1] << " " << a[2] << " " << a[0] << endl;
  }
  if(x=='C'&&y=='A'&&z=='B'){
    cout << a[2] << " " << a[0] << " " << a[1] << endl; 
  }
  if(x=='C'&&y=='B'&&z=='A'){
    cout << a[2] << " " << a[1] << " " << a[0] << endl; 
  }
}

【P5720 】【深基4.例4】一尺之棰

 

题目描述

《庄子》中说到,“一尺之棰,日取其半,万世不竭”。第一天有一根长度为 aa 的木棍,从第二天开始,每天都要将这根木棍锯掉一半(每次除 22,向下取整)。第几天的时候木棍的长度会变为 11?

输入格式

输入一个正整数 aa,表示木棍长度。

输出格式

输出一个正整数,表示要第几天的时候木棍长度会变为 11。

输入输出样例

输入  

100

输出  

7

说明/提示

数据保证,1 \le a\le 10^91≤a≤109。

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,count=0;
  cin >> n;
  while(n>=1){
    n=n/2;
    count++;
  }
  cout << count << endl;
}


相关文章
|
9月前
|
算法 C语言 C++
从C语言的使用转换到C++(上篇)——刷题、竞赛篇
从C语言的使用转换到C++(上篇)——刷题、竞赛篇
237 0
|
9月前
|
存储 C++
【五一创作】C++刷题 【入门4】数组
【五一创作】C++刷题 【入门4】数组
73 0
|
机器学习/深度学习 存储 人工智能
【c++百日刷题计划】 ———— DAY12,奋战百天,带你熟练掌握基本算法
【c++百日刷题计划】 ———— DAY12,奋战百天,带你熟练掌握基本算法
188 0
|
1月前
|
算法 C++
【数据结构与算法】:关于时间复杂度与空间复杂度的计算(C/C++篇)——含Leetcode刷题-2
【数据结构与算法】:关于时间复杂度与空间复杂度的计算(C/C++篇)——含Leetcode刷题
|
1月前
|
算法 C++
【数据结构与算法】:关于时间复杂度与空间复杂度的计算(C/C++篇)——含Leetcode刷题-1
【数据结构与算法】:关于时间复杂度与空间复杂度的计算(C/C++篇)——含Leetcode刷题
|
2月前
|
C语言 C++
【C语言/C++】牛客网刷题训练-12
【C语言/C++】牛客网刷题训练-12
|
9月前
|
存储 C语言 C++
【C/C++刷题——leetcode】查找字符串中最大的子串
【C/C++刷题——leetcode】查找字符串中最大的子串
196 0
|
机器学习/深度学习 人工智能 C++
【c++百日刷题计划】 ———— DAY16,刷题百天,养成刷题好习惯
【c++百日刷题计划】 ———— DAY16,刷题百天,养成刷题好习惯
158 0
【c++百日刷题计划】 ———— DAY16,刷题百天,养成刷题好习惯
|
2月前
|
C++
C++刷题ACM输入数组
C++刷题ACM输入数组
42 0
|
2月前
|
C++
第十三届蓝桥杯B组C++(试题C:刷题统计)
第十三届蓝桥杯B组C++(试题C:刷题统计)
30 0