Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first line of the inpu…
Text Reverse                                                                                  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description Ignatius likes to write words in reverse way. Given…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. #include<cstdio> #include<string.h> #include<iostream> #include<algorithm> #include<cmath> #include<deque> #include<cstdlib>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input con…
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.   Input The input contains several test cases. The first line of the input is a single inte…
题意 : 给出你一个句子,让你把句子中每个单词的字母顺序颠倒一下输出. 思路 : 用栈即可,就是注意原来在哪儿有空格就要输出空格. //hdu1062 #include <iostream> #include <stdio.h> #include <string.h> #include <stack> using namespace std ; int main() { int n ; scanf("%d",&n) ; getch…
原题 题目大意: t组数据,每组为一行,遇到空格时讲前面的单词反转输出. 题解: 显然的栈题,遇到空格时将当前栈输出清空即可 #include<cstdio> #include<stack> #include<cstring> using namespace std; int t,l; char s[1010]; stack <char> stk; int main() { scanf("%d",&t); getchar(); w…
Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12577    Accepted Submission(s): 4743 Problem Description Ignatius likes to write words in reverse way. Given a single line of text w…
http://acm.hdu.edu.cn/showproblem.php?pid=1062 思路: 最主要的是通过getline函数存取字符串. 如何读取单个单词,并且反向输出? 用\n作为单个单词的判定. 扩展: getline函数的用法,详解 int main() { string line; while(getline(cin,line)) cout<<line<<endl; ; } 大家会发现运行时怎么也跳不出循环,甚至会发生各种莫名其妙的错误.why? getline(…
Problem Description Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user's result file, then the system compare the two files. If the two f…
头文件 algorithm string s="hello"; reverse(s.begin(),s.end()); char c[]="hello"; reverse(c,c+strlen(c)); 这个函数只要有区间就可以了. 很简单的.…
虽然这个题目一遍AC,但是心里还是忍不住骂了句shit! 花了一个小时,这个题目已经水到一定程度了,但是我却在反转这个操作上含糊不清,并且还是在采用了辅助数组的情况下,关系的理顺都如此之难. 其实我是想到了之前那次保研考试,让给数组里面的数换k位,我也是纠结好久没有写出个所以然,郁闷. #include<stdio.h> #include<string.h> #include<stdlib.h> ]; ]; void divide(char a[],int n) { ,…
Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13524    Accepted Submission(s): 5161 Problem Description Ignatius likes to write words in reverse way. Given a single line of text w…
Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35208    Accepted Submission(s): 13824 Problem Description Ignatius likes to write words in reverse way. Given a single line of text…
Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51495    Accepted Submission(s): 19692 Problem Description Ignatius likes to write words in reverse way. Given a single line of text…
实现字符串翻转,思路很简单,就是首尾字符对调. void reverse(char* str){ char* p = str + strlen(str) - 1;//最后一个字符地址 char temp; while (str<p) { temp = *p;//获取p指向字符串 *p-- = *str;//p 往左边移动,设置值为*str *str++ = temp; } } 注意str<p 这里,代表指针变量的大小,因为同一个字符串的地址,str指向首字母的指针变量的值,p是指向末尾字符的指…
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). Follow up:If this function…
文章目录 1.Java笔试算法题:字符串翻转 2.单选题: 2.1.同一进程下的多个线程可以共享哪一种资源:data section 2.2.一个树形的叶结点在前序遍历和后序遍历下,可以相同的相对位置出现(√ ) 说理证明: 举例证明: 2.3.下列哪一个命令为删除 sample 数据库的 tb_ame 表(D:drop table sample. tb_ ame) 2.4.在重载运算符函数时,下面(->)运算符必须重载为类成员函数形式 2.5.在对一组记录(54,38,96,23,15,72,…
2013-10-25 最近碰到一道笔试题,是关于字符串翻转的.题目是:将一段英文翻转,但保留单词拼写,如给定字符串str="I am a student",返回为"student a am I".(为简单代码,设给定字符串由' '和字母组成). 对于这个题目我的思路是,先不管单词拼写,将str完全翻转得到str="tneduts a ma I",然后再对str中每个单词逐个翻转.代码实现如下 #include<stdio.h> #in…
Reverse Pairs 翻转对 题意 计算数组里面下标i小于j,但是i的值要大于j的值的两倍的搭配的个数(也就是可能会有多种搭配):网址 做法 这道题显然是不允许使用最简单的方法:两次循环,逐次进行判断,这样做的时间复杂度就是O(n^2),OJ无法通过,需要考虑另外的实现方式: class Solution(object): def reversePairs(self, nums): """ :type nums: List[int] :rtype: int "…
实现字符串翻转PHP本身自带一个函数就可以解决,strrev函数.这里不适用任何内置函数实现字符串翻转 案例一(纯字母): $str = 'abcdefghig k'; //假设测试的字符串/g与k之间有一个空格 //php中的字符串可以看做数组来处理,比如代码输出 echo $str[4]; ,结果为 e,也就是abcdefghigk的第四个字母 function str_rev ($str) { ; true; $i++) //true模拟死循环 { if (!isset($str[$i])…
字符串翻转 <?php$s = 'strlen,substr,count';$o = '';$i = 0;while(isset($s[$i]) && $s[$i] != null) {$o = $s[$i++].$o;}echo $o;?> 将单词 翻转 <?php $s = 'strlen substr count';$o = '';$i = 0;while($s[$i]) {$o = $s[$i++].$o;}echo $o;…
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <set> #define nmax 20005 using namespace std; s…
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a[k]) k∈[i,j]: 2.U(i,j)代表a[i] = j; 对于询问U,用单点替换的操作维护线段树.对于询问Q,那么除了叶子节点,其他的节点应该保存的是左子树和右子树的最大值,因此pushup函数应该是对最大值的一个维护,query的时候找出的应该是最大值,故改为ans = max(--)…
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i,j)表示 a[i]+=j; 2.Sub(i,j)表示 a[i]-=j; 3.Query(i,j)表示 Σ(a[i],a[j]). Add操作和Sub操作分别是单点更新,Query是区间求和.题目比较裸,但是在写ST模板的时候还是不能一次写对,出的错记录如下: 1.由于对模板的不熟悉,rt打成rn导…
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数.因此用0表示不可以,1表示可以.最后对dp数组扫描一遍即可. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 100…
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那么肯定不能被平分.若为偶数,则对valuesum/2为背包容量,全体石头为商品做完全背包.把完全背包进行二进制优化后,转为01背包即可. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #inclu…
HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化) 题意分析 首先C表示测试数据的组数,然后给出经费的金额和大米的种类.接着是每袋大米的价格,重量和袋数. 每种大米的数量是有限的,应该能看出是多重背包的问题.关键是多重背包的处理方法.对多重背包采用二进制优化的方法.设同种大米的数量为n,每袋的价格为v,那么把同一种大米分别拆成1,2,4,8,16--(直到不够2^n时,剩下的单独分成一组),拆分的价格也分别对应是v,2v,4v,8v…
HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包) 题意分析 与普通的完全背包大同小异,区别就在于多了一个个数限制,那么在普通的完全背包的基础上,增加一维,表示个数.同时for循环多写一层即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 105 using namespace std; int dp[…
HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包) 题意分析 裸完全背包 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 100005 #define nn 105 using namespace std; int dp[nmax]; struct item{ int hap; int kal…