標題:
e307. 請讓我留在你的回憶裡
[打印本頁]
作者:
李知易
時間:
2025-2-22 11:35
標題:
e307. 請讓我留在你的回憶裡
[attach]20672[/attach]
mmap解法參考:
#include<bits/stdc++.h>
#include<sys/mman.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
using namespace std;
int main()
{
int fd = fileno(stdin);
struct stat sb;
fstat(fd, &sb);
size_t length = sb.st_size;//以上是獲取檔案描述符
char *buffer = (char *)mmap(nullptr, length, PROT_READ, MAP_PRIVATE, fd, 0);
int c = 0;
vector<char> ans;
for (int i = 0; i < length; i++) {
if (buffer[i] != ' ') {
if(c % 2 == 1)
ans.push_back(' ');
ans.push_back(buffer[i]);
c = 0;
} else {
c++;
}
}
cout.write(ans.data(), ans.size());
cout << '\n';
return 0;
}
複製代碼
作者:
高鋐鈞
時間:
2025-2-22 11:56
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
getline(cin,str);
int a=0;
for(int i=0;i<str.length();i++){
char c=str[i];
if(c==' '){
a++;
}else{
if(a%2==0){
}else{
cout<<" ";
}
cout<<c;
a=0;
}
}
}
複製代碼
作者:
洪承廷
時間:
2025-2-22 11:56
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
getline(cin,a);
int sum=0;
for(int i=0;i<a.length();i++)
{
if(a[i]==' ')
{
sum++;
if(a[i+1]!=' ')
{
if(sum%2==1)
cout<<" ";
sum=0;
}
else
continue;
}
else
cout<<a[i];
}
return 0;
}
複製代碼
作者:
楊惇翔
時間:
2025-2-22 12:00
#include <bits/stdc++.h>
using namespace std;
string str,ans;
int main()
{
getline(cin,str);
int cnt=0;
for(int i=0;i<str.length();i++)
{
if(str[i]!=' ')
{
if(cnt%2!=0)
ans+=' ';
ans+=str[i];
cnt=0;
}
if(str[i]==' ')
cnt++;
}
cout<<ans;
return 0;
}
複製代碼
作者:
孫子傑
時間:
2025-2-22 12:02
#include<bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin,str);
int space=0;
for(int i=0;i<str.length();i++)
{
if(str[i]==' ')
{
space++;
}
if(str[i]!=' ')
{
if(space%2!=0)
{
cout<<" ";
}
cout<<str[i];
space=0;
}
}
return 0;
}
複製代碼
作者:
張駿霖
時間:
2025-2-22 12:03
#include <bits/stdc++.h>
using namespace std;
string str,ans;
int main()
{
getline(cin,str);
int c=0;
for(int i=0;i<str.length();i++)
{
if(str[i]!=' ')
{
if(c%2!=0)
ans+=' ';
ans+=str[i];
c=0;
}
if(str[i]==' ')
c++;
}
cout<<ans;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2