TJU Problem 1644 Reverse Text
注意:
int N; cin >> N; cin.ignore();
同于
int N; scanf("%d\n",&N);
另:关于 cin 与 scanf:
scanf是格式化输入,printf是格式化输出。
cin是输入流,cout是输出流。效率稍低,但书写简便。
格式化输出效率比较高,但是写代码麻烦。
流输出操作效率稍低,但书写简便。
cout之所以效率低,正如一楼所说,是先把要输出的东西存入缓冲区,再输出,导致效率降低。缓冲区比较抽象,举个例子吧:
曾经就遇到过这样的情况(类似的),
int i;
cout<<'a';
cin>>i;
cout<<'b';
运行结果什么都没看到输出,输入一个整型比如3再按回车后ab同时显示出来了。
但是这样的情况并不是经常发生,是在一些比较大型的工程中偶尔出现,原因是字符a先到了缓冲区,但是没输出,等输入了i,b进入
缓冲区后再一并输出的。
流输入也是差不多的。cin的实时性较差,因为它使用了缓冲区,一般情况下满了才刷新的。
对于字符:cin的输入忽略空格和回车。scanf("%c",&i)等价于i = getchar(),换行符和回车都会被读入。
原题:
1644. Reverse Text
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 7899 Accepted Runs: 2891
there are other languages where text is read and written from right to left. As
a first step towards a program that automatically translates from a
left-to-right language into a right-to-left language and back, you are to write
a program that changes the direction of a given text.
Input Specification
The input contains several test cases. The first line contains an integer
specifying the number of test cases. Each test case consists of a single line of
text which contains at most 70 characters. However, the newline character at the
end of each line is not considered to be part of the line.
Output Specification
For each test case, print a line containing the characters of the input line
in reverse order.
Sample Input
3
Frankly, I don't think we'll make much
money out of this scheme.
madam I'm adam
Sample Output
hcum ekam ll'ew kniht t'nod I ,ylknarF
.emehcs siht fo tuo yenom
mada m'I madam
Source: Western
and Southwestern European Regionals 1996 Practice
源代码:
我的:
#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std; char aaa[]; int main() {
int N; cin >> N; cin.ignore();
while (N--) {
gets(aaa);
int len = strlen(aaa);
for (int i = len - ; i >= ; i--) {
cout << aaa[i];
}
cout << endl;
}
return ;
}
网上的:
注意学习其中 reverse 函数:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std; int main() { int cases;
cin >> cases;
string s;
getline(cin, s);
while (cases-- && getline(cin, s)) {
reverse(s.begin(), s.end());
cout<< s << endl;
}
return ;
}
TJU Problem 1644 Reverse Text的更多相关文章
- Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...
- zoj 1295 Reverse Text
Reverse Text Time Limit: 2 Seconds Memory Limit: 65536 KB In most languages, text is written fr ...
- HDOJ/HDU 1321 Reverse Text(倒序输出~)
Problem Description In most languages, text is written from left to right. However, there are other ...
- Google APAC----Africa 2010, Qualification Round(Problem B. Reverse Words)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p1 问题描述: Problem Given a list of s ...
- TJU Problem 2101 Bullseye
注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...
- TJU Problem 2548 Celebrity jeopardy
下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548. Celebrity jeopardy Time Limit: 1.0 Seconds Memory Lim ...
- [LeetCode&Python] Problem 541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...
- [LeetCode&Python] Problem 206. Reverse Linked List
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...
- TJU Problem 2857 Digit Sorting
原题: 2857. Digit Sorting Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 3234 Accepted ...
随机推荐
- Spring Boot中注解事务
- 算法笔记--lca倍增算法
算法笔记 模板: vector<int>g[N]; vector<int>edge[N]; ][N]; int deep[N]; int h[N]; void dfs(int ...
- ArcGIS API for Silverlight——小滑块
Widgets翻译过来是小玩具.如果使用过Dojo或者ExtJS等js框架肯定会了解到这个“小玩具”也有大用处,能够在很大程度上减少我们的工作量,快速完成功能需求.能减少多大工作量呢?让我们先来,点击 ...
- git查看本地分支关联(跟踪)的远程分支之间的对应关系,本地分支对应哪个远程分支
git branch -vv: [root@realserver git-test]# git branch -vv bug 23043a7 add new.txt master.* dev ...
- 『Re』知识工程作业_主体识别
作业要求 环境路径 类似于这样的,一共50篇文档, 均为中文文档,是法院判决书的合集. 程序 程序如下,我完全使用正则表达式来实现功能, import re import glob import co ...
- node搭建本地服务器
随着前端不断发展,node基本已经成为必备,在调试的时候经常需要服务器,在之前的做法通常是去下载一个phpstudy 或者 xampp等启动一个服务,作为一个前端人虽然可以借助各种工具,但是怎么能不懂 ...
- 基础最短路(模板 bellman_ford)
Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店 ...
- Java容器——Set接口
1.定义 set中不允许放入重复的元素(元素相同时只取一个).它使用equals()方法进行比较,如果返回true,两个对象的HashCode值也应该相等. 2.方法 TreeSet中常用的方法: b ...
- Windows系统下修改Erlang默认路径
新建.erlang文件: io:format("consulting .erlang in ~p~n",[element(2, file:get_cwd())]). c:cd(&q ...
- wordpress 使用less 样式无法及时刷新
wordpress 样式无法及时刷新 wordpress编写style样式时,无法及时刷新页面,因此特意记录一番如何处理较好,网友的建议清除Chrome缓存,实时修改style携带的参数 折腾之旅开启 ...