1. 4A.Watermelon

题目链接:https // s.com/problemset/problem/4/A

题意:两人分瓜,但每一部分都得是偶数

分析:直接 对2取余,且 w != 2

#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0 && n != 2)cout << "YES\n";
else cout << "NO" << endl;
return 0;
}

2. 1A.Theatre Square

题目链接:https // s.com/problemset/problem/1/A

题意:铺地板,给定边长为a的正方形砖块。允许铺的面积大于广场面积

分析:注意数据很大 用__int64 存储,向上取整$ (n + a - 1) / a $

#include <iostream>
using namespace std;
int main() {
__int64 a, n, m;
cin >> n >> m >> a;
cout << ((n + a - 1) / a) * ((m + a - 1) / a) << endl;
return 0;
}

3. 71A.Way Too Long Words

题目链接:https // s.com/problemset/problem/71/A

题意:如果字符串长度大于10则需要压缩长度

分析:水题

#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> n;
while (n--) {
cin >> s;
int len = s.length();
if (len > 10) cout << s[0] << len - 2 << s[len - 1] << endl;
else cout << s << endl;
}
return 0;
}

4. 158A.Next Round

题目链接:https // s.com/problemset/problem/158/A

题目描述:题意很简单,要求按照大小顺序输入n个数据并判断大于第k个数据的非零数字个数

#include<bits/stdc++.h>
using namespace std;
int main() {
int n, k, c = 0, t, a[51];
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
if (a[i] >= a[k - 1] && a[i] > 0)
c++;
cout << c << '\n';
return 0;
}

5. 231A. Team

题目链接:https // s.com/problemset/problem/231/A

#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, cnt = 0;
for (scanf("%d", &n); n; --n) {
scanf("%d %d %d", &a, &b, &c); if (a + b + c >= 2)++cnt;
}
cout << cnt << endl;
return 0;
}

6. 118A.String Task

题目链接:https // s.com/problemset/problem/118/A

题目描述:输入一串字符,如果英文字母是大写则转换为小写,是元音则去掉,是辅音则在前加“.”,输出处理后的字母。

分析:先判断字符串种是否为英文字母,然后将大写转换为小写,利用第二个字符串,是元音则跳过,是辅音则先加“.”再加上辅音字母,最后输出处理后的字符串。

#include<bits/stdc++.h>
using namespace std;
int main() {
char s;
while (cin >> s) {
s = tolower(s);
if (!(s == 'e' || s == 'a' || s == 'y' || s == 'u' || s == 'o' || s == 'i')) { cout << "." << s; }
}
cout << endl;
return 0;
}

7. 50A.Domino piling

题目链接:https // s.com/problemset/problem/50/A

#include<bits/stdc++.h>
using namespace std;
int n, m;
int main() {
cin >> n >> m;
cout << ((n * m) >> 1) << endl;
return 0;
}

8. 282A.Bit++

题目链接:https // s.com/problemset/problem/282/A

#include <iostream>
#include <string>
#define LL long long
using namespace std;
int main()
{
string str;
LL x = 0 , n, a;
cin >> n;
for (a = 1; a <= n; a++)
{
cin >> str;
if (str == "++X" || str == "X++")
x++;
else x--;
}
cout << x;
return 0; }

9. 112A.Petya and Strings

题目链接:https // s.com/problemset/problem/112/A

分析:比较字符串,两个字符串都变为小写,然后通过str自带的字典序比较输出结果

#include<bits/stdc++.h>
using namespace std;
string s1, s2;
int main() {
cin >> s1 >> s2;
for (auto& p s1)p = tolower(p);
for (auto& p s2)p = tolower(p);
if (s1 > s2)cout << 1;
else if (s1 == s2)cout << 0;
else cout << -1;
return 0;
}

10. 263A.Beautiful Matrix

题目链接:https // s.com/problemset/problem/263/A

分析:找到唯一的1,计算坐标到中心的距离即 $ abs(i - 3) + abs(j - 3) $

#include<bits/stdc++.h>
using namespace std;
int main(){
int ans, a;
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 5; j++){
cin >> a;
if (a == 1) { ans = abs(i - 3) + abs(j - 3); break; }
}
cout << ans;
return 0;
}

11 339A - Helpful Maths

#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
int len = s.length();
if (len == 1)cout << s;
else {
for (int i = len / 2; i < len; ++i)
if (i != s.length() - 1)cout << s[i] << "+";
else cout << s[i];
}
return 0;
}

看dalao题解的时候发现了一个cin函数 - cin.ignore() [讲解](https //blog.csdn.net/qq_36274515/article/details/77714152)

#include <bits/stdc++.h>
using namespace std;
int main(){
int a[100],i=0,j;
while(cin>>a[i++])cin.ignore(1);//读入数字后ignore +
sort(a,a+--i);
for(j=0;j<i;j++){cout<<a[j];if(j<i-1)cout<<'+';}
return 0;
}

12. 281A - Word Capitalization

#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
s[0] = toupper(s[0]);
cout << s;
return 0;
}

13. 96A - Football

字符串查找:find函数,这里有个技巧,find返回值为 size_type 如果在字符串中未找到即返回npos4294967295)== -1 ,而找到了就会返回下标。

#include<bits/stdc++.h>
using namespace std;
int main() {
string s1 = "1111111", s2 = "0000000", s;
cin >> s;
//令返回值 +1 , -1 -> 0 or 下标变为正数 再配合 || 即可判断
printf("%s", s.find(s1) + 1 || s.find(s2) + 1 ? "YES" "NO");
return 0;
}
//当然正常写法也是可以的利用for循环

14. 266A - Stones on the Table

#include <bits/stdc++.h>
using namespace std;
int main() {
char a, b; int c = 0,t;
cin >> t >> a; //不断读入并比较
while (t--) { b = getchar(); a == b ? c++ : a = b; }
cout << c << endl;
}

15. 236A - Boy or Girl

#include<bits/stdc++.h>
using namespace std;
int main() {
string s; set<char>_set;
cin >> s;
for (auto c : s)_set.insert(c);
if (_set.size() % 2 == 0)cout << "CHAT WITH HER!";
else cout << "IGNORE HIM!";
return 0;
}

优化

#include<bits/stdc++.h>
using namespace std;
int main() {
char ch; string s;
while (cin >> ch) if (s.find(ch) == -1) s += ch;
if (s.size() % 2 == 0) cout << "CHAT WITH HER!";
else cout << "IGNORE HIM!";
}

16. 69A - Young Physicist

#include<bits/stdc++.h>
using namespace std;
int n, a, b, c, x, y, z;
int main() {
cin >> n;
while (n--) { cin >> a >> b >> c; x += a, y += b, z += c; }
if (x == 0 && y == 0 && z == 0)cout << "YES";
else cout << "NO";
return 0;
}

17. 122A - Lucky Division

//根据题意发现是对一些数是否除尽
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n % 4 == 0 || n % 7 == 0 || n % 47 == 0 || n % 74 == 0 || n % 477 == 0 ? "YES" : "NO");
return 0;
}

18. 58A - Chat room

#include<bits/stdc++.h>
using namespace std;
int main(){
string s, A = "hello"; int i = 0;
cin >> s;
for (auto c : s)if (c == A[i])++i;
if (i == 5)cout << "YES";
else cout << "NO";
}

19. 546A - Soldier and Bananas

#include<bits/stdc++.h>
using namespace std;
int main() {
long long n, k, w, t;
cin >> k >> n >> w;
t = (1 + w) * w * k / 2;
if (n >= t)cout << 0;
else cout << t - n;
return 0;
}

20. 116A - Tram

#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, Max = 0,t = 0; cin >> n;
while (n--) { cin >> a >> b; t += b - a; Max = max(Max, t); }
cout << Max;
return 0;
}

21. 791A - Bear and Big Brother

#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, t = 0; cin >> a >> b;
while (a <= b) { a *= 3, b *= 2; ++t; }
cout << t;
return 0;
}

22. 160A - Twins

#include<bits/stdc++.h>
using namespace std;
int main(){
int t, n = 0, h = 0, i, j, a[105];
cin >> t;
for (i = 0; i < t; i++){
cin >> a[i];
h += a[i];
}
sort(a, a + t);
for (i = 0; 2 * n <= h; i++) n += a[t - i - 1];
cout << i << endl;
}

23. 977A.Wrong Subtraction

#include<bits/stdc++.h>
using namespace std;
int main() {
__int64 n; int k;cin >> n >> k;
while (k--) if (n % 10 == 0)n /= 10; else n--;
cout << n;
return 0;
}

24.617A.Elephant

#include<bits/stdc++.h>
using namespace std;
int main() {
__int64 n; cin >> n;
cout << (n + 4) / 5;
return 0;
}

25. 133A. HQ9+

#include<bits/stdc++.h>
using namespace std;
int main() {
string s; bool flag = false; cin >> s;
for (auto c : s)if (c == 'H' || c == 'Q' || c == '9') { flag = true; break; }
if (flag)cout << "YES";
else cout << "NO";
return 0;
}

26. 158B - Taxi

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
while (cin >> n){
int a[5] = { 0 }, cnt,sum = 0;
while(cin >> cnt)a[cnt]++;
for (int i = 4; i >= 1; i--){
if (i == 4)
sum += a[i];
else if (i == 3){
sum += a[3];
a[1] -= min(a[3], a[1]);
}
else if (i == 2){
sum += a[2] / 2;
if (a[2] % 2 == 0)
a[2] = 0;
else{
a[2] = 1;
a[1] -= 2;
sum++;
}
}
else{
if (a[1] > 0){
if (a[1] % 4 == 0)
sum += a[1] / 4;
else sum += a[1] / 4 + 1;
}
}
}
cout << sum << endl;
}
return 0;
}

转化为数论解法

#include<iostream>
#include<algorithm>
using namespace std;
int A[5], N, t;
int main() {
cin >> N; while (std::cin >> t)A[t]++;
A[1] = max(A[1] - A[3], 0);
cout << A[3] + A[4] + (A[1] + 2 * A[2] + 3) / 4;
return 0;
}

27. 266B - Queue at the School

#include<bits/stdc++.h>
using namespace std;
int main() {
string s; int n, m;
cin >> n >> m >> s;
while (m--) for (int i = 0; i < n - 1; ++i)if (s[i] == 'B' && s[i + 1] == 'G') { swap(s[i], s[i + 1]); ++i; }
cout << s;
return 0;
}

28. 110A - Nearly Lucky Number

#include<bits/stdc++.h>
using namespace std;
int main() {
string s; int i = 0; cin >> s;
for (auto c : s)i += (c == '4' || c == '7');
if (i == 4 || i == 7)cout << "YES";
else cout << "NO";
return 0;
}

29. 41A - Translation

#include<bits/stdc++.h>
using namespace std;
int main() {
string s, ss; cin >> s >> ss;
int len = s.length();
for (int i = 0; i < len; ++i)if (s[i] != ss[len - i - 1]) { cout << "NO"; return 0; }
cout << "YES";
return 0;
}

30. 59A - Word

#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
int uc = 0, lc = 0;
for (char c : s)(isupper(c) ? uc : lc)++;
for (char c : s) cout << char(lc >= uc ? tolower(c) : toupper(c));
return 0;
}

Hottest 30 of codeforce的更多相关文章

  1. 总结30个CSS3选择器

    或许大家平时总是在用的选择器都是:#id  .class  以及标签选择器.可是这些还远远不够,为了在开发中更加得心应手,本文总结了30个CSS3选择器,希望对大家有所帮助. 1 *:通用选择器 ;; ...

  2. 值得收藏!国外最佳互联网安全博客TOP 30

    如果你是网络安全从业人员,其中重要的工作便是了解安全行业的最新资讯以及技术趋势,那么浏览各大安全博客网站或许是信息来源最好的方法之一.最近有国外网站对50多个互联网安全博客做了相关排名,小编整理其中排 ...

  3. CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率

    CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率 当场景中有比较复杂的模型时,条件渲染能够加速对复杂模型的渲染. 条件渲染(Conditio ...

  4. 30分钟学会XAML

    1.狂妄的WPF 相对传统的Windows图形编程,需要做很多复杂的工作,引用许多不同的API.例如:WinForm(带控件表单).GDI+(2D图形).DirectX API(3D图形)以及流媒体和 ...

  5. Shell脚本编程30分钟入门

    Shell脚本编程30分钟入门 转载地址: Shell脚本编程30分钟入门 什么是Shell脚本 示例 看个例子吧: #!/bin/sh cd ~ mkdir shell_tut cd shell_t ...

  6. ViEmu 3.6.0 过期 解除30天限制的方法

    下载:链接: http://pan.baidu.com/s/1c2HUuWw 密码: sak8 删除下面2个地方 HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{B9CDA4 ...

  7. AlloyTouch全屏滚动插件发布--30秒搞定顺滑H5页

    原文链接:https://github.com/AlloyTeam/AlloyTouch/wiki/AlloyTouch-FullPage-Plugin 先验货 插件代码可以在这里找到. 注意,虽然是 ...

  8. C#求斐波那契数列第30项的值(递归和非递归)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. JS组件系列——又一款MVVM组件:Vue(一:30分钟搞定前端增删改查)

    前言:关于Vue框架,好几个月之前就听说过,了解一项新技术之后,总是处于观望状态,一直在犹豫要不要系统学习下.正好最近有点空,就去官网了解了下,看上去还不错的一个组件,就抽空研究了下.最近园子里vue ...

  10. 精选30道Java笔试题解答

    转自:http://www.cnblogs.com/lanxuezaipiao/p/3371224.html 都 是一些非常非常基础的题,是我最近参加各大IT公司笔试后靠记忆记下来的,经过整理献给与我 ...

随机推荐

  1. 4个LED流水灯

    #include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器 #include<intrins.h> //因为要用到左右移函数,所以加入这个头文件 ...

  2. TPC-DS工具介绍及性能测试

    一. Hive-testbench工具介绍 TPC-DS:https://www.cnblogs.com/webDepOfQWS/p/10544528.html 由于原生态工具生产测试数据表存在bug ...

  3. 0x01.web请求、web环境、抓包技巧

    网站搭建 DNS解析 域名选择 http/https 证书 服务器 web应用环境架构 操作系统 linux windows 开发语言 php java ASP/ASPX python等 程序源码 C ...

  4. uniapp---wap2app去掉系统自带的导航栏

    在用uniapp进行将wap站转化为app的时候,默认打包后的文件,带有系统的导航栏,下面是去除的办法: 第一步:找到 sitemap.json 设置 titleNView为false:  第二步:在 ...

  5. 【译】拥抱 SQL Server 2022 与 SSDT 17.8:揭示关键更新

    在数据库开发的动态场景中,SQL Server Data Tools(SSDT)是 Visual Studio 生态系统中数据库开发人员的强大工具.SSDT 17.8 包含在最新版本的 Visual ...

  6. .NET周刊【12月第1期 2023-12-06】

    国内文章 .NET 与 OpenEuler 共展翅,昇腾九万里 https://www.cnblogs.com/shanyou/p/17858385.html 本文介绍了openEuler操作系统,它 ...

  7. 在WInform开发中实现工具栏/菜单的动态呈现

    在Winform系统开发中,为了对系统的工具栏/菜单进行动态的控制,我们对系统的工具栏/菜单进行动态配置,这样可以把系统的功能弹性发挥到极致.通过动态工具栏/菜单的配置方式,我们可以很容易的为系统新增 ...

  8. BUUCTF 加固题 Ezsql WriteUp

    文章目录 想直接要加固代码的点这里 题目 一.查看 二.进入目标机器加固 修改前的文件: 添加如下代码: 修改后的文件 三.Check 想直接要加固代码的点这里 题目 靶机地址解释: 第一行:目标机器 ...

  9. 斯坦福 UE4 C++ ActionRoguelike游戏实例教程 15.创建持续效果BUFF

    斯坦福课程 UE4 C++ ActionRoguelike游戏实例教程 0.绪论 概述 本篇文章对应Lecture 18 – Creating Buffs, World Interaction, 71 ...

  10. JVM学习-Class文件结构

    文章原文:https://gaoyubo.cn/blogs/844dc0e7.html 一.Class类文件的结构 任何一个Class文件都对应着唯一的一个类或接口的定义信息. 但是反过来说,类或接口 ...