首页 > 其他分享 >由于string不能输入空格,和cin不能输入空格;用了map和vector和cin.get()的题;本题都正确

由于string不能输入空格,和cin不能输入空格;用了map和vector和cin.get()的题;本题都正确

时间:2023-05-15 20:12:32浏览次数:36  
标签:get s1 cin 空格 输入 size

1.cin是C++中最常用的输入语句,当遇到空格或者回车键即停止。无法解决。

2.cin.get()函数可以接收空格,遇回车结束输入。

3.string也不能输入空格

给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集。要求先输出 A,再输出 B,但重复的字符必须被剔除。

输入格式:

输入在两行中分别给出 A 和 B,均为长度不超过 106的、由可见 ASCII 字符 (即码值为32~126)和空格组成的、由回车标识结束的非空字符串。

输出格式:

在一行中输出题面要求的 A 和 B 的和。

输入样例:

This is a sample test
to show you_How it works

输出样例:

This ampletowyu_Hrk
  代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MB

#include<vector>
#include<set>
#include<iostream>
using namespace std;
int main()
{
set<char>s1;
vector<char>v1;
char x,y;
cin.get(x);
while (x!='\n')
{
int a=s1.size();
s1.insert(x);
if (s1.size() - a == 1)
{
v1.push_back(x);
}
cin.get(x);
}
cin.get(y);
while (y != '\n')
{
int b = s1.size();
s1.insert(y);
if (s1.size() - b == 1)
{
v1.push_back(y);
}
cin.get(y);
}
for (vector<char>::iterator it = v1.begin(); it != v1.end(); it++)
{
cout << *it;
}
return 0;
}

标签:get,s1,cin,空格,输入,size
From: https://www.cnblogs.com/zhaoqianwan/p/17402940.html

相关文章