123

DongDong prefers English words to English sentences, so he wants to count the words of a sentence. Could you help him?

输入

The first line contains a positive integer T (T<=1000), which means T test cases. Then comes T lines, each line contains a string which combines with several words separated by spaces. Note that there may be more than one space to separate two words.

输出

For each test case, please print the number of words of the sentence.

样例输入

3 
Every night in my dreams  
 I see you  I feel you   
That  is  how I know you go on

样例输出

5
6
8

2

c++  有一个函数 叫做 stringsteam  统计单词个数  头文件 <sstream>

#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define S1(n)    scanf("%d",&n)
#define SL1(n)   scanf("%I64d",&n)
#define S2(n,m)  scanf("%d%d",&n,&m)
#define SL2(n,m)  scanf("%I64d%I64d",&n,&m)
#define Pr(n)     printf("%d\n",n)
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=50005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};namespace IO {const int MT = 5e7;char buf[MT]; int c,sz;void begin(){c = 0;sz = fread(buf, 1, MT, stdin);//一次性输入}template<class T>inline bool read(T &t){while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;if( c>=sz) return false;bool flag = 0; if( buf[c]== '-') flag = 1,c++;for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';if(flag) t=-t;return true;}
}
ll inv[maxn*2];
inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
inline ll inv2(ll b){return qpow(b,MOD-2);}int main()
{int T;cin>>T;getchar();while(T--){int ans=0;char str[maxn];char temp[maxn];gets(str);stringstream ss(str);while(ss>>temp)ans++;printf("%d\n",ans);}return 0;
}

转载于:https://www.cnblogs.com/sizaif/p/9078416.html

c++ 新技能get 统计单词数相关推荐

  1. linux统计单词程序,linux统计单词数

    sort +awk+uniq 统计文件中出现次数最多的前10个单词 实例 cat logt.log|sort -s -t '-' -k1n |awk '{print $1;}'|uniq -c|sor ...

  2. 信息学奥赛一本通 1400:统计单词数 | 1954:【11NOIP普及组】统计单词数 | OpenJudge NOI 1.12 05 | 洛谷 P1308 [NOIP2011 普及组] 统计单词数

    [题目链接] ybt 1400:统计单词数 ybt 1954:[11NOIP普及组]统计单词数 OpenJudge NOI 1.12 05:统计单词数 洛谷 P1308 [NOIP2011 普及组] ...

  3. python【蓝桥杯vip练习题库】ADV-17统计单词数

    试题 算法提高 统计单词数 资源限制 时间限制:1.0s 内存限制:512.0MB 问题描述 统计输入英文文章段落中不同单词(单词有大小写之分, 但统计时忽略大小写)各自出现的次数. 输入段落中所含单 ...

  4. 信息学奥赛一本通(1400:统计单词数)

    1400:统计单词数 时间限制: 1000 ms         内存限制: 65536 KB 提交数: 21054     通过数: 6817 [题目描述] 一般的文本编辑器都有查找单词的功能,该功 ...

  5. 1.12.05 统计单词数

    05:统计单词数 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出 ...

  6. P1308 统计单词数

    P1308 统计单词数 题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定 ...

  7. openjudge 7920 统计单词数

    统计单词数 链接 这道题曾经卡死蒻蒟的我 后来才发现这是一道水题 思路 没什么思路这是道水题 把每个单词搞出来对比一下就行 代码 #include <cstdio> #include &l ...

  8. 14-luogu-P1308 [NOIP2011 普及组] 统计单词数

    文章目录 问题 [NOIP2011 普及组] 统计单词数 题目描述 输入格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 样例 #2 样例输入 #2 样例输出 #2 提示 我的错误代码 大神 ...

  9. [NOIP2011]统计单词数

    题目:[NOIP2011]统计单词数 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是: ...

最新文章

  1. 758.6G每秒:阿里云成功防御国内最大规模Memcached DDoS反射攻击
  2. python怎么安装到d盘-python必须装在c盘吗
  3. WPF学习笔记(03) - 华丽的HelloWorld
  4. LUOGU P4195 Spoj3105 Mod
  5. 大数据时代数据中心的发展思考
  6. CVPR 2021 | 如何让GAN的训练更加高效优雅
  7. python 浏览器显示本地文件夹_浏览器读取本地文件
  8. JS之获取指定位置Unicode的charCodeAt()方法
  9. ajax同步导致ajax上面的代码不执行?
  10. 2.第一个页面amp;amp;分辨率和rpx
  11. SoapUI使用以及常见错误解决
  12. 平面三角形外心坐标推导
  13. mysql定时自动备份数据库
  14. python编程基础-上海交通大学版答案
  15. Swagger 分组配置
  16. 用max的角度来解析blender建模!
  17. exe文件关联被更改的解决方法
  18. python条形图参数_更改水平条形图大小matplotlib
  19. 【解析无线路由器信号消失原因】
  20. WordPress 安全漏洞

热门文章

  1. HTTP错误代码对应
  2. TCP,IP,HTTP,SOCKET区别和联系
  3. windows server 2003 安装显卡驱动
  4. 今天写了个Win32服务设置软件,呵呵,纯绿色软件
  5. 【剑指offer】面试题 5. 替换空格
  6. Android_设备隐私获取,忽略6.0权限管理
  7. 获得WebApi用Post方法获得新增数据的信息
  8. MySQL的binlog日志
  9. 【LeetCode】309. Best Time to Buy and Sell Stock with Cooldown
  10. 数据库的内连接和外连接区别?