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. 微信小程序文件预览和下载-文件系统

    文件预览和下载 在下载之前,我们得先调用接口获取文件下载的url 然后通过wx.downloadFile将下载文件资源到本地 wx.downloadFile({ url: res.data.url, ...

  2. 聊聊分布式 SQL 数据库Doris(八)

    稀疏索引 密集索引:文件中的每个搜索码值都对应一个索引值,就是叶子节点保存了整行. 稀疏索引:文件只为索引码的某些值建立索引项. 稀疏索引的创建过程包括将集合中的元素分段,并给每个分段中的最小元素创建 ...

  3. Java八股面试题整理(1)

    1.为什么Java代码可以实现一次编写,到处运行? 参考答案 JVM(Java虚拟机)是Java跨平台的关键. 在程序运行前,Java源代码(.java)需要经过编译器编译成字节码(.class).在 ...

  4. RDBMS与Hbase对比 HDFS与HBase对比 Hive与HBase对比

    RDBMS: HBASE: HDFS与HBase对比: Hive与HBase对比: Hive与HBase总结

  5. Chrome扩展开发实战:快速填充表单

    大家好,我是 dom 哥.我正在写关于 Chrome 扩展开发的系列文章,感兴趣的可以 点个小星星 . 填表单是打工人经常面对的场景,作为一个前端,我经常开发一些PC端的页面,它们主要由表单和表格构成 ...

  6. Colaboratory使用教程

    Google Colaboratory 是一个 Google 研究项目,旨在帮助传播机器学习培训和研究成果.它是一个 Jupyter 笔记本环境,不需要进行任何设置就可以使用,并且完全在云端运行.同时 ...

  7. IDEA创建Springboot项目在application.yml配置文件配置了nacos远程注册中心,启动项目还是找localhost的问题

    项目结构如下: 报错如下: 解决办法: # 错误的 #spring.cloud.nacos.config.server-addr=192.168.137.137:8848 #spring.cloud. ...

  8. C++ Qt开发:Charts绘制各类图表详解

    Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍TreeWid ...

  9. NLP复习之N元文法

    N元文法的统计 二元概率方程: \[P(w_n|w_{n-1}) = \frac{C(w_{n-1}w_n)}{C(w_{n-1})} \] 三元概率估计方程: \[P(w_n|w_{n-2},w_{ ...

  10. CentOS 7 安装 Python 3.X版本

    由于Centos7默认安装了python2.7.5版本,因此想安装python 3.X版本就需要特殊处理. 详情可以参考南宫羽香的技术博客原文:https://www.cnblogs.com/lclq ...