#16430: 求解


asddzxcc1856 (嚕踢)

學校 : 國立中興大學
編號 : 86097
來源 : [61.223.99.184]
最後登入時間 :
2023-08-21 21:25:52
d430. 第二題: 計算字數 (count) -- 92學年度北基區資訊學科能力競賽 | From: [36.235.5.60] | 發表日期 : 2018-12-30 12:15

#include <iostream>
#include <sstream>
using namespace std;

int main ()
{
int n=0;
string s;
while (getline(cin,s))
{

string t;
stringstream s1(s);
while (s1>>t)
{
int i,f=0;
for (i=0;i<t.length();i++)
{
if ((t.at(i)>='0' && t.at(i)<='9')|| (t.at(i)>='A' && t.at(i)<='Z')||(t.at(i)>='a' && t.at(i)<='z'))
f+=1;
if (f==1) n++;
}
}
cout << n << endl;
}
}

 

請問有什麼寫法可以讓n 等到讀取完全部的文章在輸出

 

 

跪求教學

 
#16433: Re:求解


asddzxcc1856 (嚕踢)

學校 : 國立中興大學
編號 : 86097
來源 : [61.223.99.184]
最後登入時間 :
2023-08-21 21:25:52
d430. 第二題: 計算字數 (count) -- 92學年度北基區資訊學科能力競賽 | From: [36.235.5.60] | 發表日期 : 2018-12-30 12:34

#include
#include
using namespace std;

int main ()
{
int n=0;
string s;
while (getline(cin,s))
{

string t;
stringstream s1(s);
while (s1>>t)
{
int i,f=0;
for (i=0;i<t.length();i++)
{
if ((t.at(i)>='0' && t.at(i)<='9')|| (t.at(i)>='A' && t.at(i)<='Z')||(t.at(i)>='a' && t.at(i)<='z'))
f+=1;
if (f==1) n++;
}
}
cout << n << endl;
}
}

 

請問有什麼寫法可以讓n 等到讀取完全部的文章在輸出

 

 

跪求教學

  ------>>>> 各位 大大 有沒有 比較好的寫法 可以給個建議嗎


 
#16438: Re:求解


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
d430. 第二題: 計算字數 (count) -- 92學年度北基區資訊學科能力競賽 | From: [114.42.220.78] | 發表日期 : 2018-12-31 15:22

#include
#include
using namespace std;

int main ()
{
int n=0;
string s;
while (getline(cin,s))
{

string t;
stringstream s1(s);
while (s1>>t)
{
int i,f=0;
for (i=0;i<t.length();i++)
{
if ((t.at(i)>='0' && t.at(i)<='9')|| (t.at(i)>='A' && t.at(i)<='Z')||(t.at(i)>='a' && t.at(i)<='z'))
f+=1;
if (f==1) n++;
}
}
cout << n << endl;
}
}

 

請問有什麼寫法可以讓n 等到讀取完全部的文章在輸出

 

 

跪求教學

  ------>>>> 各位 大大 有沒有 比較好的寫法 可以給個建議嗎


我有一個想法,值得一試,算他的空格數,但我還不熟char。


 
ZeroJudge Forum