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 ...
随机推荐
- XML_CPP_资料_libXml2_01_Code_ZC(?.pro)
ZC:最下面有 ?.pro文件的设置写法 ZC: Win7x64,qt-opensource-windows-x86-msvc2010_opengl-5.3.2.exe,cn_visual_studi ...
- 推荐一款基于Angular实现的企业级中后台前端/设计解决方案脚手架
ng-alain 是一个企业级中后台前端/设计解决方案脚手架,我们秉承 Ant Design 的设计价值观,目标也非常简单,希望在Angular上面开发企业后台更简单.更快速.随着『设计者』的不断反馈 ...
- js和css兼容问题
(一)html部分 1.H5新标签在IE9以下的浏览器识别 <!--[if lt IE 9]> <script type="text/javascript" s ...
- Longest Repeating Character Replacement
2018-06-29 22:56:24 问题描述: 问题求解: 本题是一条字符串问题,且是求Optimal,自然最初想到的是使用DP来进行求解,但是问题就是如果采用DP的话,前一个状态也太多了,和替换 ...
- WCF配置后支持通过URL进行http方式调用
最近遇到一个小型项目,主要就是通过手机写入NFC信息,思考许久后决定就写一个简单的CS程序来搞定这个问题,可是当涉及到手机和PC通信的时候首先考虑到的就是IIS,同时因为数据库是SQLite,思前想后 ...
- 雷林鹏分享:Ruby 字符串(String)
Ruby 字符串(String) Ruby 中的 String 对象存储并操作一个或多个字节的任意序列,通常表示那些代表人类语言的字符. 最简单的字符串是括在单引号(单引号字符)内.在引号标记内的文本 ...
- English trip -- VC(情景课) 6 C Is your class at 11:00? 你的课11点开始吗?
Grammar focus 语法点 Is your class at 11:00 ? # 带be动词的一般疑问句 Yes, it is No, it isn't 相当于 is not Pra ...
- python-day64--web框架
http协议. 一.HTTP简介 1.HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输 ...
- view_countInfo
create view view_countInfo as SELECT a.dwmch, b.dwbh, b.djbh, c.rq, c.shl, c.djbh AS Expr1, d.sp ...
- 44. Wildcard Matching *HARD*
'?' Matches any single character. '*' Matches any sequence of characters (including the empty sequen ...