#16984: 不存字串的做法依然TLE


vincent97198 (Alchemist)

School : 國立嘉義高級中學
ID : 50683
IP address : [114.33.208.245]
Last Login :
2019-04-22 01:26:46
e080. read and write -- it's david | From: [114.33.208.245] | Post Date : 2019-02-25 20:09

#include <bits/stdc++.h> #define ll long long #define endl '\n' #define loop(i,x,y) for(ll i=x;i<y;i++) #define N 1000+5 using namespace std; int main() { //cin.tie( 0 ); //ios_base::sync_with_stdio( false ); streambuf *pbuf = cin.rdbuf(); int count = 1; do { char ch = pbuf->sgetc(); count++; } while (pbuf->snextc() != ' '); pbuf->snextc(); do { char ch = pbuf->sgetc(); cout << ch; count++; } while (pbuf->snextc() != '\n'); cout << " "; while (count--) { pbuf->sungetc(); } do { char ch = pbuf->sgetc(); cout << ch; } while (pbuf->snextc() != ' '); }

 

沒有存字串卻還是TLE......這題怎麼做啊

 
#16985: Re:不存字串的做法依然TLE


vincent97198 (Alchemist)

School : 國立嘉義高級中學
ID : 50683
IP address : [114.33.208.245]
Last Login :
2019-04-22 01:26:46
e080. read and write -- it's david | From: [114.33.208.245] | Post Date : 2019-02-25 20:11

#include <bits/stdc++.h>

#define ll long long

#define endl '\n'

#define loop(i,x,y) for(ll i=x;i<y;i++)

#define N 1000+5

 

using namespace std;

 

int main()

{

//cin.tie( 0 );

//ios_base::sync_with_stdio( false );

streambuf *pbuf = cin.rdbuf();

int count = 1;

do {

char ch = pbuf->sgetc();

count++;

} while (pbuf->snextc() != ' ');

pbuf->snextc();

do {

char ch = pbuf->sgetc();

cout << ch;

count++;

} while (pbuf->snextc() != EOF);

cout << " ";

while (count--) {

pbuf->sungetc();

}

do {

char ch = pbuf->sgetc();

cout << ch;

} while (pbuf->snextc() != ' ');

}

 

沒有存字串卻還是TLE......這題怎麼做啊





 
#16986: Re:不存字串的做法依然TLE


asnewchien@gmail.com (david)

School : Not Student
ID : 68108
IP address : [122.118.81.57]
Last Login :
2019-04-22 14:24:54
e080. read and write -- it's david | From: [61.223.54.106] | Post Date : 2019-02-25 20:24

 

請問這樣的寫法,一次是讀取多長的字。

 
#16987: Re:不存字串的做法依然TLE


vincent97198 (Alchemist)

School : 國立嘉義高級中學
ID : 50683
IP address : [114.33.208.245]
Last Login :
2019-04-22 01:26:46
e080. read and write -- it's david | From: [114.33.208.245] | Post Date : 2019-02-25 20:29

 

請問這樣的寫法,一次是讀取多長的字。




讀過去找到空格後開始輸出,然後倒轉回開頭在輸出到有空格的前面(中間有插一個空格)

 
#16988: Re:不存字串的做法依然TLE


vincent97198 (Alchemist)

School : 國立嘉義高級中學
ID : 50683
IP address : [114.33.208.245]
Last Login :
2019-04-22 01:26:46
e080. read and write -- it's david | From: [114.33.208.245] | Post Date : 2019-02-25 20:34

 

請問這樣的寫法,一次是讀取多長的字。




讀過去找到空格後開始輸出,然後倒轉回開頭在輸出到有空格的前面(中間有插一個空格)




試著用putchar取代cout還是一樣

 
#16989: Re:不存字串的做法依然TLE


asnewchien@gmail.com (david)

School : Not Student
ID : 68108
IP address : [122.118.81.57]
Last Login :
2019-04-22 14:24:54
e080. read and write -- it's david | From: [61.223.54.106] | Post Date : 2019-02-25 20:37

 

請問這樣的寫法,一次是讀取多長的字。




讀過去找到空格後開始輸出,然後倒轉回開頭在輸出到有空格的前面(中間有插一個空格)




試著用putchar取代cout還是一樣




我是說 input

 
#16990: Re:不存字串的做法依然TLE


vincent97198 (Alchemist)

School : 國立嘉義高級中學
ID : 50683
IP address : [114.33.208.245]
Last Login :
2019-04-22 01:26:46
e080. read and write -- it's david | From: [114.33.208.245] | Post Date : 2019-02-25 20:41

 

請問這樣的寫法,一次是讀取多長的字。




讀過去找到空格後開始輸出,然後倒轉回開頭在輸出到有空格的前面(中間有插一個空格)




試著用putchar取代cout還是一樣




我是說 input




一次讀取一個char

 
#16991: Re:不存字串的做法依然TLE


asnewchien@gmail.com (david)

School : Not Student
ID : 68108
IP address : [122.118.81.57]
Last Login :
2019-04-22 14:24:54
e080. read and write -- it's david | From: [61.223.54.106] | Post Date : 2019-02-25 20:50

 

可以試試 5000

 
#17018: Re:不存字串的做法依然TLE


314159265358979323846264338327... (少年π)

School : 臺北市私立延平高級中學
ID : 69058
IP address : [42.73.155.17]
Last Login :
2019-04-21 21:25:21
e080. read and write -- it's david | From: [42.72.160.79] | Post Date : 2019-02-28 21:39

 

可以試試 5000


可以用cin.ignore嗎?
如果像這樣呢

我以前沒用過這些函式,如果用錯請糾正

#include<iostream>

using namespace std;

int main(){

string s;

streambuf *pbuf = cin.rdbuf();

int count = 1;

cin.ignore(25000000,' ');

cin>>s;

cout<<s<<' ';

while (count--) {

pbuf->sungetc();

}

do {

char ch = pbuf->sgetc();

cout << ch;

} while (pbuf->snextc() != ' ');

}

還是TLE...

 
#17020: Re:不存字串的做法依然TLE


asnewchien@gmail.com (david)

School : Not Student
ID : 68108
IP address : [122.118.81.57]
Last Login :
2019-04-22 14:24:54
e080. read and write -- it's david | From: [1.168.18.119] | Post Date : 2019-02-28 23:18

 

可以試試 5000


可以用cin.ignore嗎?
如果像這樣呢

我以前沒用過這些函式,如果用錯請糾正

#include

using namespace std;

int main(){

string s;

streambuf *pbuf = cin.rdbuf();

int count = 1;

cin.ignore(25000000,' ');

cin>>s;

cout<<s<<' ';

while (count--) {

pbuf->sungetc();

}

do {

char ch = pbuf->sgetc();

cout << ch;

} while (pbuf->snextc() != ' ');

}

還是TLE...


我的想法在 c631 的解題報告裡。


 
ZeroJudge Forum