ural 1038. Spell Checker
2015-08-11 10:54
302 查看
就是字符串问题嘛。。。。。
注意出错的方式很少很少,,,,,
我之前的问题都出在了每读入一个新单词的时候不知道之前是单词还是已经结束了
还有句子最后要有结尾
可能有换行符什么的
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int tot;
bool over=true;
bool cap(char c)
{
if(c>='A'&&c<='Z') return true;
else return false;
}
bool letter(char c)
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z') return true;
return false;
}
int main()
{
int i,j,k;
char c;
while((c=getchar())!=EOF)
{
if(c=='.'||c=='!'||c=='?') { over=true; continue; }
if(!letter(c)) continue;
if(over&&!cap(c)) tot++;
over=false;
c=getchar();
while(letter(c))
{
if(cap(c)) tot++;
c=getchar();
}
if(c=='.'||c=='!'||c=='?') over=true;
}
printf("%d\n",tot);
return 0;
}
就是字符串问题嘛。。。。。
注意出错的方式很少很少,,,,,
我之前的问题都出在了每读入一个新单词的时候不知道之前是单词还是已经结束了
还有句子最后要有结尾
可能有换行符什么的
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int tot;
bool over=true;
bool cap(char c)
{
if(c>='A'&&c<='Z') return true;
else return false;
}
bool letter(char c)
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z') return true;
return false;
}
int main()
{
int i,j,k;
char c;
while((c=getchar())!=EOF)
{
if(c=='.'||c=='!'||c=='?') { over=true; continue; }
if(!letter(c)) continue;
if(over&&!cap(c)) tot++;
over=false;
c=getchar();
while(letter(c))
{
if(cap(c)) tot++;
c=getchar();
}
if(c=='.'||c=='!'||c=='?') over=true;
}
printf("%d\n",tot);
return 0;
}
相关文章推荐
- 如何精心设计CDN架构?
- 如何获取linux 命令源码
- vimdiff 命令使用技巧
- HDOJ 1233 还是畅通工程(最小生成树)
- HDU_1558_SegmentSet
- 算法竞赛入门经典: 第四章 函数与递归 4.1求两点之间距离
- 21-IO流-21-IO流(字节流-操作文件基本演示)
- makefile的语法及写法
- android 内存管理机制、异常、垃圾回收
- iOS 9 分屏多任务(2):Slide Over & Split View快速入门
- iOS开发:创建真机调试证书
- swift-01-简述swift与OC区别
- 修改tomcat浏览器地址栏图标
- swift-01-简述swift与OC区别
- 如何在Ubuntu 14.04中安装最新版Eclipse
- IOS开发笔记之常用的第三方库(太多了。)
- 编程小技巧
- mysql复合索引、普通索引总结
- Android Interface Definition Language (AIDL)
- String、StringBuffer与StringBuilder之间区别