上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页
  2014年2月19日
摘要: // string::rbegin and string::rend#include #include using namespace std;int main (){ string str ("now step live..."); string::reverse_iterator rit; for ( rit=str.rbegin() ; rit < str.rend(); rit++ ) cout << *rit; return 0;} The actual output is:...evil pets won 阅读全文
posted @ 2014-02-19 20:41 长木Qiu 阅读(390) 评论(0) 推荐(0) 编辑
摘要: string类string对象是一个特殊的容器,它的设计主要是为了方便对字符串的操作。string类来自于这个类模板typedef basic_string string;成员函数:ITERATORS:begin 返回首个迭代器end 返回哨兵迭代器rbegin返回倒序的首个迭代器rend返回返回倒序的哨兵迭代器CAPACITY:size 返回字符串长度,不包括'\0'length 同上max_size 返回string对象所能容纳的最大字符个数resize 调整字符串长度capacity 返回所分配内存的大小reserve 设置capacity的最小值clear 清除stri 阅读全文
posted @ 2014-02-19 20:10 长木Qiu 阅读(840) 评论(0) 推荐(0) 编辑
摘要: 语法:#include char *strstr(char *s1, char *s2);作用:在s1中查找s2子串返回s2在s1中第一次出现的地址,如果没找到则返回NULL。匹配过程不包括NULL字符。例子:#include #include int main (){ char str[] ="This is a simple string"; char *pch; pch = strstr(str, "simple"); strncpy(pch, "sample", 5); puts(str); return 0;}输出结果:Th 阅读全文
posted @ 2014-02-19 17:56 长木Qiu 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 原题链接#include bool run( int n ){ if( ( n % 4 == 0 && n % 100 != 0 ) || ( n % 400 == 0 ) ) return true; return false;}int main(){ int t, y, m, d, s; scanf( "%d", &t ); while( t-- ){ scanf( "%d-%d-%d", &y, &m, &d ); if( 2 == m && 29 == d ) if( !run( y 阅读全文
posted @ 2014-02-19 16:18 长木Qiu 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 2012年浙江大学计算机及软件工程研究生机试真题考察对字符串的操作。#include #include char str[81];int main(){ int len, n1, n2, n3, i, j, count; while(scanf("%s", str) == 1){ len = strlen(str); n1 = n3 = len / 3; n2 = len - n1 - n3; if(n1 == n2){ --n1; --n3; n2 += 2; } count = 0; for(i = 1; i <= n1; ++i){ for(j = 1; j & 阅读全文
posted @ 2014-02-19 14:54 长木Qiu 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 原题链接这题要用到栈,由于递归与栈的亲密关系所以可以用递归。参考了原题的标程。#include #include char str[301];int start;int max(int a, int b){ return a > b ? a : b;}int min(int a, int b){ return a < b ? a : b;}int val(){ int v, n; switch(str[start]){ case 'm': start += 4; if(str[start - 2] == 'n') return min(val(), 阅读全文
posted @ 2014-02-19 13:24 长木Qiu 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 语法:#include int scanf(const char *format, ...);解析:scanf()函数根据给定的格式从STDIN中读取输入,把数据存储到其他参数中。它的工作方式和printf()函数很像,格式串包含控制字符,空白字符和非空白字符,控制字符前面都有一个'%'符号。就像下面这样:控制字符 解释%c 一个字符%d 一个十进制整数%i 一个整数%e,%f,%g 一个浮点数%o 一个八进制数%s 一个字符串%x 一个十六进制数%p 一个指针%n 一个和目前为止接收到的字符数相等的整数%u 一个无符号整数%[] 一组字符%% 一个... 阅读全文
posted @ 2014-02-19 12:42 长木Qiu 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 1. 常见用法。char buf[512] ;sscanf("123456 ", "%s", buf);//此处buf是数组名,它的意思是将123456以%s的形式存入buf中!printf("%s\n", buf);结果为:1234562. 取指定长度的字符串。如在下例中,取最大长度为4字节的字符串。sscanf("123456 ", "%4s", buf);printf("%s\n", buf);结果为:12343. 取到指定字符为止的字符串。如在下例中,取遇到空格为止字 阅读全文
posted @ 2014-02-19 11:37 长木Qiu 阅读(187) 评论(0) 推荐(0) 编辑
  2014年2月18日
摘要: 原题链接附ac代码:#include #include #include int main(){ char s[15]; int t, len, i, sum; scanf("%d", &t); while(t-- && scanf("%s", s)){ if(isalpha(s[0])){ len = strlen(s); for(i = sum = 0; i != len; ++i) sum = sum * 26 + (s[i] - 'A' + 1); printf("%d\n", sum) 阅读全文
posted @ 2014-02-18 19:20 长木Qiu 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 原题链接简单题。附ac代码:#include #include #include #include using namespace std;int main(){ int n; vector vec; vector inde; string str; cin >> n; while(n--){ cin >> str; vector::iterator fin; fin = find(vec.begin(), vec.end(), str); if(fin != vec.end()) ++inde[fin - vec.begin()]; else{ vec.push_ba 阅读全文
posted @ 2014-02-18 10:11 长木Qiu 阅读(137) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页