码迷,mamicode.com
首页 > 其他好文 > 详细

1000. Letters and Words homework 12

时间:2016-10-22 14:39:37      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:work   let   har   i++   letter   str   ring   out   space   

#include<iostream>
#include<sstream>
#include<cstring>
using namespace std;
int main(){
 char s[1000];
 string str;
 int count = 0;
 int count1 = 0;
    cin.get(s,1000,‘\0‘);
    for(int i = 0; i < strlen(s); i++) {
  if((s[i] >= ‘a‘ && s[i] <= ‘z‘ ) || (s[i] >= ‘A‘ && s[i] <= ‘Z‘) || s[i] == ‘ ‘) count++;
 }
 for(int i = 0; i < strlen(s); i++) {
  if(s[i] == ‘\n‘) s[i] = ‘ ‘;
 }
 
 
 stringstream strs1(s);
 while(strs1>>str){
  count1++;
 }
 
 cout<<"Letters: "<<count<<endl;
 cout<<"Words: "<<count1<<endl;
 
}

1000. Letters and Words homework 12

标签:work   let   har   i++   letter   str   ring   out   space   

原文地址:http://www.cnblogs.com/sysu-eeman-yang/p/5987380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!