注意:

  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. Jmeter 爬Boss中注册和登录

    图文验证码生成部分: Get请求到 https://m.zhipin.com/captcha/?randomKey=9dHY2lyVpxg0wFQRmzJqE5bpL4iRkhhR 每次访问新生成一个 ...

  2. js 去重

        function unique(array) { let obj = {}; return array.filter((item, index, array) => { let newI ...

  3. robotframework安装与配置--学习第一天

    刚刚入职公司,之前学的是Java+selenium自动化测试,但公司要求使用robot framework,所以找了些资料学习.刚开始觉得为什么不用java.python等开发语言+selenium做 ...

  4. TP5框架whereor

    whereOr方法 Db::table('think_user') ->where('name','like','%thinkphp') ->whereOr('title','like', ...

  5. SpringBoot 中常用注解@Controller/@RestController/@RequestMapping介绍

    原文 SpringBoot 中常用注解 @Controller/@RestController/@RequestMapping介绍 @Controller 处理http请求 @Controller / ...

  6. English trip -- VC(情景课)5 Around Town

     Around Town  城市周围 Talk about the picture 看图说话 sentences Where are you? I'm in the Meten classroom. ...

  7. 『Python』pycharm常用设置

    学习一下pycharm的快捷操作,提升速度,也提升舒适度,笑. 常用快捷键 ctrl + d :复制粘贴本行到下一行 ctrl + y :删除本行 ctrl + 鼠标点击 :跳转 ctrl + / : ...

  8. ASE加解密算法详细介绍

    AEC扫盲主要增对CBC模式做详细讲解: https://blog.csdn.net/qq_28205153/article/details/55798628 AEC其他几种模式详细介绍 https: ...

  9. PHP:第四章——PHP数组array_intersect计算数组交集

    <pre> <?php //array_intersect计算数组交集 header("Content-Type:text/html;charset=utf-8" ...

  10. jquery条形码生成器

    <!DOCTYPE html><html> <head>        <meta charset="UTF-8">         ...