https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/103/
对于这种题要引起重视了
- 傻逼代码
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 100
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;
using namespace std;
typedef long long ll;
const double pi=acos(-1);
char buf[1010];
int main()
{
// freopen("./in","r",stdin);
char line[1010];
vector<string> v;
while(scanf("%s",buf)){
v.push_back(string(buf));
memset(buf,0,sizeof buf); //没有就会用上次的数据,贼傻逼
char c=getchar();
if(c=='\n' ||c==EOF ){
reverse(v.begin(),v.end());
FF(i,v.size()){
printf("%s",v[i].c_str());
if(i!=v.size()-1)
printf(" ");
}
puts("");
v.clear();
if( c==EOF)
break;
}
}
return 0;
}
- cin的现代化版本
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 100
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;
using namespace std;
typedef long long ll;
const double pi=acos(-1);
char buf[1010];
int main()
{
// freopen("./in","r",stdin);
ios::sync_with_stdio(false);//这东西开了,stdio的东西都别想用了
string s;
vector<string> v;
while(cin>>s){
v.clear();
v.push_back(s);
while(1){
// char c=getchar();
char c=cin.get();//老老实实用这个,上一行读出来的都是EOF
if(c=='\n' || c==EOF)
break;
cin>>s;
v.push_back(s);
}
reverse(v.begin(),v.end());
FF(i,v.size()){
cout<<v[i];
if(i!=v.size()-1)
cout<<' ';
}
cout<<endl;
}
return 0;
}
数据量很小,差异不大
- 读一行做split的信息化版本
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 100
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;
using namespace std;
typedef long long ll;
const double pi=acos(-1);
void split(string s,char splitchar,vector<string>& vec)
{
int L = s.length();
int start=0;
string topush;
for(int i=0; i<L; i++)
{
if(s[i] == splitchar && i == 0)//第一个就遇到分割符
{
start += 1;
}
else if(s[i] == splitchar)
{
topush=s.substr(start,i - start);
if(topush.length()>0)
vec.push_back(topush);
start = i+1;
}
else if(i == L-1)//到达尾部
{
topush=s.substr(start,i+1 - start);
if(topush.length()>0)
vec.push_back(topush);
}
}
}
int main()
{
freopen("./in","r",stdin);
string s;
vector<string> v;
char line[1010];
while(gets(line)){
vector<string> v;
split(string(line),' ',v);
reverse(v.begin(),v.end());
FF(i,v.size()){
printf("%s",v[i].c_str());
if(i!=v.size()-1)
printf(" ");
}
puts("");
}
return 0;
}
C++真是个垃圾语言,连split都没有