注意:

  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 JNI学习(二)——实战JNI之“hello world”

    本系列文章如下: Android JNI(一)——NDK与JNI基础 Android JNI学习(二)——实战JNI之“hello world” Android JNI学习(三)——Java与Nati ...

  2. 动态规划-最长可互除子序列 Largest Divisible Subset

    2018-08-28 17:51:04 问题描述: 问题求解: 本题是一个求最优解的问题,很自然的会想到动态规划来进行解决.但是刚开始还是陷入了僵局,直到看到了hint:LIS,才有了进一步的思路.下 ...

  3. Java 包的概述和讲解

    2017-11-02 22:58:45 包(package):其实就是文件夹. 包的作用是对类进行分类的管理,并且区分不同的类名. 举例: 学生:增加,删除,修改,查询 教师:增加,删除,修改,查询 ...

  4. 云服务器ECS挖矿木马病毒处理和解决方案

    云服务器ECS挖矿木马病毒处理和解决方案 最近由于网络环境安全意识低的原因,导致一些云服务器ECS中了挖矿病毒的坑. 总结了一些解决挖矿病毒的一些思路.由于病毒更新速度快仅供参考. 1.查看cpu爆满 ...

  5. dp练习(2)——老鼠的旅行

    1267 老鼠的旅行(来源:codevs) #include "bits/stdc++.h" using namespace std; ][]; ][]; int main() { ...

  6. ASP.NET的内置对象 —— Request 对象

    Request 对象最大的用途在于提交表单信息. (可获取页面间传递的值.客户端的 IP 地址等) 3.2.2 获取页面间传送的值 获取页面传送参数值是 Request 对象最广泛的应用之一. ASP ...

  7. Intel DAAL AI加速——支持从数据预处理到模型预测,数据源必须使用DAAL的底层封装库

    数据源加速见官方文档(必须使用DAAL自己的库): Data Management Numeric Tables Tensors Data Sources Data Dictionaries Data ...

  8. TypeScript安装

    1.Installing Node.js and updating npm Updating npm----npm install npm@latest -g Installing TypeScrip ...

  9. OO第二次单元总结

    OO第二次单元总结 前言 第二单元的三次作业:系列电梯与多线程. 第五次作业 (1)设计策略 电梯的第一次作业是单部傻瓜电梯,采用FAFS调度策略,电梯按队列顺序依次处理请求,单次只处理一个请求.本次 ...

  10. gitlba的搭建与使用

    实验环境继续使用git的实验环境,详情请点击连接https://www.cnblogs.com/cash-su/p/10131632.html 首先给服务器做一个本机的映射 [root@git1 ~] ...