HDU 2017 (水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2017
题目大意:给你段字符串,求出字符串中含有数字字符的个数
解题思路:
字符串输入输出的基本应用:http://c.biancheng.net/cpp/html/3106.html https://blog.csdn.net/qq_29924041/article/details/54351384
scanf() 只吃实体字符串,空格回车不吃
gets() 空格回车都吃,吃到回车为止
getchar() 啥都吃,一次吃一个
PS: 本题用到的不太多,所以只是肤浅介绍的写一下本题相关,有什么更好的以后再更新
代码:
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n;
char str[];
while(cin >> n)
{
getchar();
while(n --)
{
int q = ;
gets(str);
int len = strlen(str);
for(int i = ; i < len; i ++)
{
if(str[i] >= '' && str[i] <= '')
q ++;
}
cout << q << endl;
}
}
}
***************更新*************
思路扩展:
23行 cin 也可以输入字符串(除了 scanf() ,gets(() )
4行 不用开数组法
5行 isdiget() 函数
char c;
char str[];
cin >> str;
for (int i = ; (c = getchar()) != '\n'; i ++){
...isdigit() // 判断是数字的函数
}
scanf格式
char str[...];
scanf(.. ,str);
while(st[i]!='\0'){
...
}
几个不太常用:
1.cin.getline(str,M); 取前 M 个字符:https://www.cnblogs.com/flatfoosie/archive/2010/12/22/1914055.html
2.http://www.voidcn.com/article/p-qchoewcs-kc.html,其中 cin.ignore(); 不带参数默认为(1,EOF)就是去掉头一个字符 :https://www.cnblogs.com/ranjiewen/p/5582601.html
3.char *s = str; 表示 s 指针指向 str 数组:https://blog.csdn.net/qq_21794823/article/details/53316853,其中while(*s)表示当 s 数组不为空
4.学到 string https://blog.csdn.net/tengfei461807914/article/details/52203202
string a;
cin>>a;
不吃空格回车
HDU 2017 (水)的更多相关文章
- HDU-1042-N!(Java大法好 && HDU大数水题)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...
- hdu 4464 水
http://acm.hdu.edu.cn/showproblem.php?pid=4464 现场赛总会有水题,这就是最水的一道,预计也就是能当高校的上机题,保研用,呵呵~~~ #include &l ...
- World Finals 2017 (水题题解)
看大佬做2017-WF,我这种菜鸡,只能刷刷水题,勉强维持生活. 赛后补补水题. 题目pdf链接,中文的,tls翻译的,链接在这里 个人喜欢在vjudge上面刷题. E Need for Speed ...
- HDU 5391 水题。
E - 5 Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1544 水题
水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...
- hdu 3357 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...
- hdu 5007 水 弦
http://acm.hdu.edu.cn/showproblem.php?pid=5007 纯粹的联系String的substr 什么时候substr拦截比写短话 string te; int n; ...
- Tickets HDU - 1260 水DP
HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...
- HDU排序水题
1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...
随机推荐
- 被折磨致死的heroku——herku部署
最近一直在弄heroku部署上线,但是因为中国墙和英语问题,一直弄不好,,很是烦躁,所有暂时先放弃了,但是因为查询了一些资料,有些文档链接有必要放到下面,方便各位和自己查看: heroku官方网站: ...
- 负载均衡服务之HAProxy基础配置(二)
前文我们聊了下haproxy的global配置段中的常用参数的说明以及使用,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12763245.html:今天我们来 ...
- Calendar日历类
package com.yhqtv.demo02.ThreadPool; import java.util.Calendar; import java.util.Date; /* * java.uti ...
- python慎用os.getcwd() ,除非你知道【文件路径与当前工作路径的区别】
当你搜索 "获取当前文件路径" 时,有的文章会提到用os.getcwd(),但是这玩意要慎用! 废话不多说,直接上例子: E:\program_software\Pycharm\y ...
- Qt 用户通过对话框选择文件
void class::on_pushButton_clicked() { fileFullPath = QFileDialog::getOpenFileName(this, tr("Sel ...
- 透彻理解C++11新特性:右值引用、std::move、std::forward
目录 浅拷贝.深拷贝 左值.右值 右值引用类型 强转右值 std::move 重新审视右值引用 右值引用类型和右值的关系 函数参数传递 函数返还值传递 万能引用 引用折叠 完美转发 std::forw ...
- UVALive 7501 Business Cycle
细心题 #include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<=b;++i) # ...
- SQL之常用函数
表8-2 中的SOUNDEX 需要做进一步的解释.SOUNDEX 是一个将任何文本串转换为描述其语音表示的字母数字模式的算法.SOUNDEX 考虑了类似的发音字符和音节,使得能对字符串进行发音比较而不 ...
- 开始导入第一个第三方库jieba
在做python的练习题,想看看运行结果. 谁知,有道题,不能识别jieba,原来要导入,因为是第三方库,照着书里面的导入方法,有三种,一种是用pip,在命令行里面安装,使用pip - p 可以查看p ...
- CF1324D Pair of Topics
好像题解里都是树状数组(起码我翻到的是 说一种cdq分治的(这应该算是cdq分治了 用cdq比较简单,所以可以作为一个练手题 cdq分治其实是一种模糊的思想,处理\([l,r]\)区间内,有多少\(( ...