Problem F: 字符串类(I)
来源:互联网 发布:知乎 资产比例 编辑:程序博客网 时间:2024/06/05 16:08
HomeWeb BoardProblemSetStandingStatusStatistics
Submit: 4684 Solved: 2302
[Submit][Status][Web Board][Submit][Status][Web Board]
Problem F: 字符串类(I)
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4684 Solved: 2302
[Submit][Status][Web Board]
Description
封装一个字符串类,用于存储字符串和处理的相关功能,支持以下操作:
1. STR::STR()构造方法:创建一个空的字符串对象。
2. STR::STR(const char *)构造方法:创建一个字符串对象,串的内容由参数给出。
3. STR::length()方法:返回字符串的长度。
4. STR::putline()方法:输出串的内容,并换行。
-----------------------------------------------------------------------------
你设计一个字符串类STR,使得main()函数能够正确运行。
函数调用格式见append.cc。
append.cc中已给出main()函数。
-----------------------------------------------------------------------------
Invalid Word(禁用单词)错误:“string”、“vector”等被禁用。
Input
输入有若干行,每行一个字符串。
Output
每组测试数据对应输出一行,包含两部分内容,首先是一个整数,表示输入串的长度,然后是输入的字符串,两者用一个空格分开。格式见sample。
Sample Input
A123456789
Sample Output
0 12 Hello World!1 A9 123456789
HINT
Append Code
append.cc,
한국어< 中文 فارسی English ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#include <iostream>#include <stdio.h>using namespace std;int len(char * s){ int i = 0; int len_ = 0; while(s[i] != '\0' ) { len_++; i++; } return len_;}void strcpy_(char *s, char *t){ int i = 0; while(t[i] != '\0') { s[i] = t[i]; i++; } s[i] = '\0';}class STR{public: int length() const { return len(stl); } void putline() const { cout << stl << endl; }public: STR(char *s = NULL ) { if(s == NULL) { stl = new char[1]; stl[0] = '\0'; } else { stl = new char[len(s) + 1]; strcpy_(stl,s); } }private: char *stl;};int main(){ STR e; STR h("Hello World!"); char s[100001]; cout << e.length() << " "; e.putline(); cout << h.length() << " "; h.putline(); while(gets(s) != NULL) { STR str(s); cout << str.length() << " "; str.putline(); }}
0 0
- Problem F: 字符串类(I)
- Problem A: 字符串类(I)
- Problem A: 字符串类(I)
- Problem A: 字符串类(I)
- Problem F 字符串替换
- F -- HDU 1022 Train Problem I
- Hihocoder 挑战赛17 String Problem I (字符串HASH)
- 第15周 oj Problem F: 将字符串格式化后输出(串)
- Problem F
- ProBlem F
- Problem F
- Problem F
- Problem F
- Problem F
- problem F
- Problem f
- Problem F
- Problem F
- Set集合的遍历
- 用python做http协议的api自动化测试三
- Problem E: STL——呵呵型自动机
- 二叉搜索树的构建与判别--是否为同一棵二叉搜索树
- MQ日志配置
- Problem F: 字符串类(I)
- 图像处理之图像亮度调节
- 微信小程序-阅读小程序demo
- Android进程间通信详细介绍
- web登录
- eayUI中测试《一》获取数据和展示在列表中的数据展示,删除数据,修改数据,增加数据
- Problem G: 字符串类(II)
- 深入理解ServletRequest与ServletResponse
- 【Java工具类】----产生随机数