2021-01-26

补题:C - Text Reverse

Problem Description

Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single line with several words. There will be at most 1000 characters in a line.

Output

For each test case, you should output the text which is processed.

Sample Input

3
olleh !dlrow
m’I morf .udh
I ekil .mca
**

Sample Output

**
hello world!
I’m from hdu.
I like acm.

[hint]

Remember to use getchar() to read ‘\n’ after the interger T, then you may use gets() to read a line and process it.
[/hint]

题后总结

首先要梳理一下关于栈的基本知识点。
栈:基本的数据结构之一,特点是“先进后出”。

这道题现在来看是没有什么难度的,最主要的还是对栈的理解还停留到简单的i know层面,并没有从真正的掌握其用法,学会了只代表你学会了,和会用是另外一回事。

#include <bits/stdc++.h>//万能头文件

using namespace std;

int main()
{
    int n;
    char ch;
    cin>>n;
    getchar();
    while(n--){
        stack<char>s;
        while(true){
            ch=getchar();//一次读入一个字符
            if(ch==' '||ch=='\n'||ch==EOF){
                while(!s.empty()){
                    cout<<s.top();//出栈
                    s.pop();//清楚栈顶
                }
                if(ch=='\n'||ch==EOF) break;cout<<" ";
            }
            else s.push(ch);//入栈
        }
        cout<<"\n";
    }
    return 0;
}

c++中几个输出的差异

1.cin>>

接收单个数字、字符or接受一个字符数组,遇“空格”、“Tab”、“回车”结束,后面的字符不在读取。

2. cin.get()

一:char ch=cin.get();
a可以是任何字符: 数字,字母,符号,空格,回车,tab
//二:cin.get(字符数组名,接收字符数)用来接收一行字符串,可以接收空格
#include<iostream>
using namespace std;
int main(){
 char c[20];
 cin.get(c,20);//数组被填满,或者遇回车结束,可以读入空格等除回车之外的其他字符
return 0;
}

3. cin.getline()

与cin.get()的功能二基本相同
char c[20];
cin.getline(c,20);//数组被填满,或者遇回车结束,可以读入空格等除回车之外的其他字符

4.getline()

包含在库`#include<string>`中
string str;
getline(cin,str);遇回车结束,可以读入空格等除回车之外的其他字符
#include<iostream>//在比赛中直接用真相的万能头文件,省时省力
#include<string>
using namespace std;
void main()
{
 string str;
 getline(cin, str);
 cout << str << endl;
 }

5.gets()

头文件:stdio.h(c),cstdio(C++)
gets从标准输入设备读字符串函数,其可以无限读取,不会判断上限,以回车结束读取
(参考:https://baike.baidu.com/item/gets/787649?fr=aladdin)

#include <iostream>//在比赛中直接用真相的万能头文件,省时省力
#include <cstdio>
using namespace std;
int main(){    
	char str[100];    
	gets(str);    
	cout<<str<<endl;    
	return 0;
}//gets_s函数用法基本一样,此处略

6.getchar()

getchar()//接受任何一个字符,包括空格、回车、tab键。

#include<iostream>
using namespace std;
void main()
{
 char ch;
 ch = getchar(); //不能写成getchar(ch);
 cout << ch << endl;
}

over

2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值