#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[5]={6,3,2,8,5};
string b[101];
int k=0;
int t=0; //临时变量
bool flag;
//She wants to go to Peking University to study Chinese
int main ()
{
//①cin >>获取到有 空格/回车
//②cin.peek()则取最后1个字符 => 空格/回车
while(cin >> b[k] && cin.peek()!= '\n'){
//cout << "1:" << cin.peek() << endl;
//cout << "2:" << cin.peek() << endl;
flag = false; //判断是否有重复
for(int i=0;i<k;i++){
if(b[i].compare(b[k]) == 0){ //compare比较有重复
flag = true;
break;
}
}
if(!flag)k++; //用下标偏移 = 数组偏移
}
//cout << "3:" << cin.peek() << endl;
k++;
sort(b,b+k);
for(int i=0;i<=k;i++){
cout << b[i] << " ";
}
return 0;
}
练习10 - 单词排序(cin.peek()觉醒)
最新推荐文章于 2023-11-29 11:26:15 发布