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. 【免费】小傅哥 DDD 开发小册

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 大家好,我是技术UP主小傅哥. 如果在面试的时候,面试官问你DDD是什么,你怎么解释?是不是感 ...

  2. [GitOps] 白嫖神器Github Actions,构建、推送Docker镜像一路畅通无阻

    [GitOps] 白嫖神器Github Actions,构建.推送Docker镜像一路畅通无阻 引言   当你没找到合适的基础的Docker镜像时,是否会一时冲动,想去自己构建.然而因为网络问题,各种 ...

  3. Flask SocketIO 实现动态绘图

    Flask-SocketIO 是基于 Flask 的一个扩展,用于简化在 Flask 应用中集成 WebSocket 功能.WebSocket 是一种在客户端和服务器之间实现实时双向通信的协议,常用于 ...

  4. 华企盾DSC由于proevhost.exe进程未添加导致rhino的文件无法预览

    解决方法:用procmon监控文件目录,然后搜索readfile,查看除了explorer.dllhost.rentimebroker是否还有其它进程添加,查到proevhost进程也读取了文件添加加 ...

  5. 《最新出炉》系列初窥篇-Python+Playwright自动化测试-36-处理web页面定位toast-下篇

    1.简介 按理说,现在这种一闪而过的toast的已经相当普及或者是见怪不怪了,应该网上的大网站会用到的,偶然的在一次租房中,看到了这种场景,所以宏哥决定将其拿来主义,进行演示实践一下. 2.租房网站 ...

  6. NC65获取Token以及相关信息

    private static void setToken() { IPriviledgedGenerator tokenGenerator = (IPriviledgedGenerator) Busi ...

  7. 已解决:若依更换日志EasyExcel框架导出报错 java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader

    先描述一下当时的场景 回忆 看到出错了,我就想可能是哪个路径写错了,或者导依赖名字写对,或者说是多了少了标点符号什么的. 然而,还是想简单了,检查重启后发现问题并没有解决. 于是就把所有我改过的地方检 ...

  8. 【笔记】springSecurity-OAuth2.0-授权模式演示

    SpringSecurityOauth2架构 介绍 流程: 用户访问,此时没有Token.Oauth2RestTemplate会报错,这个报错信息会被Oauth2ClientContextFilter ...

  9. 这些常见的python编码习惯,你都会吗

    本文分享自华为云社区<不得不知的十个常见PY编码习惯>,作者:码乐. 简介 语言在发展和变化,编码习惯也在发生改变.这里简单聊聊 17个python中常见的编码习惯或者风格. 1,可变数据 ...

  10. 一文带你了解GaussDB(DWS) 的Roach逻辑备份实现原理

    摘要:Roach工具是GaussDB(DWS)推出的一款主力的备份恢复工具,包含物理与逻辑备份两种主要能力,本文着重于讲解Roach逻辑备份的实现原理. 一.简介 在大数据时代,数据的完整和可靠性成为 ...