注意:

  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

In most languages, text is written from left to right. However,
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的更多相关文章

  1. 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 ...

  2. zoj 1295 Reverse Text

    Reverse Text Time Limit: 2 Seconds      Memory Limit: 65536 KB In most languages, text is written fr ...

  3. HDOJ/HDU 1321 Reverse Text(倒序输出~)

    Problem Description In most languages, text is written from left to right. However, there are other ...

  4. 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 ...

  5. TJU Problem 2101 Bullseye

    注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...

  6. TJU Problem 2548 Celebrity jeopardy

    下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548.   Celebrity jeopardy Time Limit: 1.0 Seconds   Memory Lim ...

  7. [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 ...

  8. [LeetCode&Python] Problem 206. Reverse Linked List

    Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...

  9. TJU Problem 2857 Digit Sorting

    原题: 2857.   Digit Sorting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3234   Accepted ...

随机推荐

  1. Android网络多线程断点续传下载

    本示例介绍在Android平台下通过HTTP协议实现断点续传下载. 我们编写的是Andorid的HTTP协议多线程断点下载应用程序.直接使用单线程下载HTTP文件对我们来说是一件非常简单的事.那么,多 ...

  2. Codeforces 38B - Chess

    38B - Chess 思路:懂点象棋的规则就可以,看看哪些点可以放马. 代码: #include<bits/stdc++.h> using namespace std; #define ...

  3. robot脚本编写规范

    一个robot脚本主要有四部分组成: ***settings*** 设置 ***keywords*** 关键词 ***variables*** 变量 ***test cases*** 测试用例 一般, ...

  4. 监督学习--k近邻算法

    2017-07-20 15:18:25 k近邻(k-Nearest Neighbour, 简称kNN)学习是一种常用的监督学习方法,其工作机制非常简单,对某个给定的测试样本,基于某种距离度量找出训练集 ...

  5. 新视觉影院yy6080.org视频的抓取

    用fiddler 分析了一下, 从点连接 到 视频播放的过程 http://yy6080.org/v/103390 http://id.jiathis.com/id.php?u=http%3A%2F% ...

  6. centos7: svbversion版本的安装配置+tortoisesvn登录验证

    centos7: svbversion版本的安装配置+tortoisesvn登录验证 命令工具:svnadmin create #创建版本库 hotcopy #版本库热备份 Islocks #打印所有 ...

  7. 雷林鹏分享:Ruby 安装 - Unix

    Ruby 安装 - Unix 下面列出了在 Unix 机器上安装 Ruby 的步骤. 注意:在安装之前,请确保您有 root 权限. 下载最新版的 Ruby 压缩文件.请点击这里下载. 下载 Ruby ...

  8. python-day47--mysql数据备份与恢复

    一.IDE工具介绍 掌握: #1. 测试+链接数据库 #2. 新建库 #3. 新建表,新增字段+类型+约束 #4. 设计表:外键 #5. 新建查询 #6. 备份库/表 #注意: 批量加注释:ctrl+ ...

  9. thinkphp3.2分页

    在ThinkPHP 3.1及之前,分页功能可能是放在/Lib/Org/Util中的,到了ThinkPHP 3.2后,分页功能已经整合到了Library/Think中了.而且ThinkPHP 3.2已经 ...

  10. OA项目(MVC项目)

    1. 新建,项目,其他项目类型,空白解决方案 2. 选中解决方案,添加,新建项目,类库: (1)添加OA.Model,删除其中的Class1.cs (2)添加OA.DAL(数据访问层),删除Class ...