CCF基础P54练习题解
来源:互联网 发布:网络创业的优点 编辑:程序博客网 时间:2024/06/16 23:43
练习1
#include <string>#include <iostream>#include <cctype>using namespace std;bool judge(string s) { if(!isalpha(s[0])) { return false; } string::iterator it = s.begin(); for(; it != s.end(); ++it) if(!isdigit(*it) && !isalpha(*it) && *it != '_') return false; return true;}int main() { string s; cin >> s; cout << (judge(s) ? "yes" : "no"); return 0;}
练习2
#include <string>#include <iostream>#include <cctype>using namespace std;int number[30] = {0};void count(string s) { string::iterator it = s.begin(); for(; it != s.end(); it++) { if(isupper(*it)) number[*it - 'A']++; }}int main() { string s; while(getline(cin, s)) { count(s); } int max = 0, i; for(i = 0; i < 26; i++) if(number[i] > max) max = number[i]; int j; for(i = max; i > 0; i--) { for(j = 0; j < 26; j++) printf("%c ", (number[j] >= i) ? '*' : ' '); printf("\n"); } printf("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"); return 0;}
输入样例
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THIS IS AN EXAMPLE TO TEST FOR YOUR
HISTOGRAM PROGRAM.
HELLO!
[EOF]
输出样例
练习3
#include <string>#include <iostream>#include <cctype>using namespace std;void print(int p1, int p2, int p3, char front, char back) { if(back >= front) { printf("-"); return; } if(p3 == 1) { for(int i = front; i < back; i++) { for(int j = p2; j > 0; j--) printf("%c", ) } }}int main() { int p1, p2, p3; cin >> p1 >> p2 >> p3; string s; cin >> s; string::iterator it = s.begin(); for(; it != s.end(); it++) { if(*it == '-') print(p1, p2, p3, *(it - 1), *(it + 1)); else printf("%c", *it); } return 0;}
0 0
- CCF基础P54练习题解
- CCF基础P29练习题解
- CCF基础P226练习题解
- ccf题解
- 【基础练习】codevs1506 传话题解
- 【基础练习】【模拟】Uva489 - Hangman Judge题解
- 【基础练习】【贪心】codevs1214 线段覆盖题解
- 【基础练习】【栈】codevs2058 括号匹配题解
- 【基础练习】【贪心】codevs1214 线段覆盖题解
- 【基础练习】【堆】codevs1063 合并果子题解
- 【基础练习】【模拟】codevs1053 笨小猴题解
- 【基础练习】【倍增LCA】codevs1036 商务旅行题解
- 【基础练习】【模拟】codevs1704 卡片游戏题解
- 【基础练习】【SPFA】codevs1557 热浪题解
- 【基础练习】【二分】codevs1766 装果子题解
- 【基础练习】【搜索】codevs1008 选数题解
- 【基础练习】【二分】codevs2072 分配房间题解
- 【基础练习】【IDA*】codevs1288 埃及分数题解
- Jquery选择器操作select、checkbox、radio
- Linux_Hi3518E开发_SPI Flash程序下载成功后串口打印信息
- RedHat7 与 Windows 使用XShell连接
- 学习正则表达式
- VS2010中添加webbrowser的控件变量,一直提示该变量ID没有未声明
- CCF基础P54练习题解
- Spring工作原理
- 09 JavaScirpt
- 用ZXING生成二维码的工具类(可以去掉白边,添加logo)
- 浅谈javascript垃圾收集机制
- iOS ViewController点击空白处收起键盘
- AWS DMS操作示例
- 一个复杂系统的拆分改造实践
- Eclipse下改配置,修改Java代码不必重启tomcat