codeup1967 数组逆置

//基本都是多组数据测试,所以不要写一组数据的代码格式!!!//全排列next_permutation()函数还真得用do{}while()循环格式来写;#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	string str;
	while (getline(cin, str))//cin读字符串遇到空格就截止,用getline是考虑到字符串可能有空格
	{
		reverse(str.begin(), str.end());//翻转函数是左闭右开,可见end是结尾的下一个位置
		cout << str << endl;
	}
	return 0;
}
时间: 2024-08-24 20:55:55

codeup1967 数组逆置的相关文章

九度OJ—题目1055:数组逆置

题目描述: 输入一个字符串,长度小于等于200,然后将数组逆置输出. 输入: 测试数据有多组,每组输入一个字符串. 输出: 对于每组输入,请输出逆置后的结果. 样例输入: hdssg 样例输出: gssdh 来源: 2011年哈尔滨工业大学计算机研究生机试真题 答疑: 解题遇到问题?分享解题心得?讨论本题请访问:http://t.jobdu.com/thread-7779-1-1.html #include<stdlib.h> #include<stdio.h> #include

求数组逆置(数组与指针实现)

数组逆置 ??基本思路: ??将a[0]与a[n-1]对换,再将a[1]与a[n-2]对换-直到将a[int(n-1)]与a[int((n-1)/2)-1]对换. ??如图所示: ??使用数组来实现: //数组实现逆置 void conver_arr(int c,int a[]) { int low =0; int high = c -1; for(int i =0; i < c/2; i++) { if(low < high) { int temp = a[c - i -1]; a[c -

用异或操作实现的交换函数用以实现数组逆置中须要注意的问题

用元素交换函数实现数组逆置非常easy,如以下代码:(数组左右元素交换) #include<iostream> #include<stdlib.h> using namespace std; void swap(int &a, int &b) { int tmp = a; a = b; b = tmp; } int main() { int a[5] = { 1, 2, 3, 4, 5 }; int lenth = sizeof(a) / sizeof(a[0]);

哈工大机考:数组逆置

时间限制:1秒 空间限制:32768K 题目描述 输入一个字符串,长度小于等于200,然后将数组逆置输出. 输入描述: 测试数据有多组,每组输入一个字符串. 输出描述: 对于每组输入,请输出逆置后的结果. 输入例子: hdssg 输出例子: gssdh 代码: #include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main(){ char a[210]; w

用异或操作实现的交换函数用以实现数组逆置中需要注意的问题

用元素交换函数实现数组逆置很简单,如下面代码:(数组左右元素交换) #include<iostream> #include<stdlib.h> using namespace std; void swap(int &a, int &b) { int tmp = a; a = b; b = tmp; } int main() { int a[5] = { 1, 2, 3, 4, 5 }; int lenth = sizeof(a) / sizeof(a[0]); in

数组逆置

1 public class Reverse { 2 3 /** 4 * 逆置函数 5 * 6 * @param array 7 * 需要逆置的数组 8 * @return 逆置后的数组 9 */ 10 public int[] reverse(int[] array) { 11 int size = array.length; 12 for (int i = 0; i < size / 2; i++) { 13 /* array[size - 1 - i]:下标为i值的对称下标的值 */ 14

【LeetCode】10.Array and String —Reverse String 字符数组逆置

Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. You may assume all the

用函数调用的方法实现数组的 初始化、逆置、清零

4. #include<stdio.h> void init(int arr[], int size){ int i = 0; for (i = 0; i < size; i++)  scanf("%d", &arr[i]); }void empty(int arr[], int size){ int i = 0; for (i = 0; i < size; i++) {  arr[i] = 0; } }void reverse(int arr[], i

字符数组,初始化,修改,结束测试 逆置 BGK

//GCC 编译方式: C:\MinGW\project>gcc -std=c99 main.c //编码环境 GBK #include <stdio.h> int main(){ int array[3][4]={{0,1,2,3},{4,5,6,7},{8,9,10,11}};      //遍历二维数组,并打印  for(int i=0;i< 3;i++){ for(int j=0;j<4;j++){ printf("array[%d][%d]=%d\n&qu