Ural1094 && Ural1038(简单字符串)
2014-10-15 21:14
330 查看
1094. E-screen
Time limit: 0.25 secondMemory limit: 64 MB
A new one-line electronic screen (e-screen) especially designed for quick input and change of information was installed at a supermarket. All information is entered by an operator. Every time the operator presses a button corresponding
to a symbol this symbol is shown on the e-screen at the position where the cursor is located at that moment (therefore the symbol that was shown at that position earlier is erased) and then the cursor moves one position to the right.
The keyboard contains letters a-z, A-Z, digits 0-9, punctuation signs (:;-!?.,), and the space button. There are also two keys that move the cursor one position to the right and to the left without erasing anything. The width
of the screen is 80 symbols. When the cursor reaches left or right edge of the screen it is automatically placed at the first position to the left.
The new e-screen had worked perfectly when it was run by its seller, but when the seller had gone it was found that nobody could operate the e-screen properly. Besides, the e-screen was installed in such a place that the operator
could not see it. Your task is to make a program emulation of the e-screen so that the operator could see the results of his or her actions.
Input
The single line of the input contains a sequence of the buttons pressed by the operator. The symbol '>' stands for the move of the cursor one position to the right and the symbol '<' stands for the move of the cursor one positionto the left. There are no more than 10000 symbols at the input.
Output
The output should contain the line that would be shown on the e-screen after pressing the given sequence of the buttons. Assume that at the beginning the e-screen contains 80 spaces and the cursor is placed at the first positionto the left.
Sample
input |
---|
>><<<Look for clothes at the <<<<<<<<<<<<<<<second flo or. <<<<<<<Fresh pizza and <<<<<<<<<<<<<<<<hamburger a t a shop right to <<<<<<<<<<<<<the entrance. Call <<<< <<<<<< 123<-456<-8790 <<<<<<<<<<<<<<<<to order <<<<<<< <<<<<<<<<<computers< and office<<<<<<< chairs. |
output |
Look for second hamburger at computer and chairs.790 |
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char ch[10005]; char ans[85]; int main() { // freopen("q.in","r",stdin); int i,j=0,len; memset(ans,' ',sizeof(ans)); while(gets(ch)) { len=strlen(ch); for(i=0;i<len;i++) { if(ch[i]=='<') { j--; if(j==-1)j=0; } else if(ch[i]=='>') { j++; if(j==80)j=0; } else { ans[j++]=ch[i]; //这里不能直接取余,而是变成0 if(j==80)j=0; } } } for(i=0;i<80;i++) printf("%c",ans[i]); printf("\n"); }
1038. Spell Checker
Time limit: 0.5 secondMemory limit: 64 MB
The boss of a firm that you are employed with is dissatisfied with the text processor Word. He wants you to write a better text processor by tomorrow. The interface of the new processor should be clearer, there should be more
options, and the resulting text should be more beautiful. You told the boss that this work would take not less than four days. Then your boss asked you to begin with a spell checking program. This program should check capital and small letters. It should detect
a mistake in each of the following cases.
The first letter in a sentence is small.
A capital letter is not the first letter in a word.
A word is a sequence of letters not containing any other symbols or ends of line.
The end of a sentence is defined a full stop, a question-mark or an exclamation mark.
Input
Input contains a text that consists of capital and small letters of the Latin alphabet (A–Z, a–z), digits (0–9), punctuation marks (.,;:-!?) and space characters. The text length is not more than 10000.Output
Output should contain a number of mistakes in the input text.Sample
input | output |
---|---|
This sentence iz correkt! -It Has,No mista;.Kes et oll. But there are two BIG mistakes in this one! and here is one more. | 3 |
话说这还和AC自动机的原理扯上边了,但是听说自动机很难,渣渣还没学。。。用一个变量over标示状态,over==0,表示处于单词状态,over==1表示处于句首状态,分别判断字母是否符合规定就好,其他字符直接略过。
#include<iostream> #include<cstdio> #include<cctype> #include<cstring> using namespace std; //原来审题出错啦。。。。o(╯□╰)o int main() { freopen("q.in","r",stdin); int i,j,res=0; char ch; bool over=true;//over=1,表示处于单词结束状态,over=0 表示处于单词状态 while((ch=getchar())!=EOF) { if(ch=='.' || ch=='?' || ch=='!') { over=true; // cout<<"......"<<endl; continue; } if(!isalpha(ch))continue; if(over && !isupper(ch)) //判断句首是否是小写错误了 { res++; // cout<<ch<<endl; } over=false; ch=getchar(); while(isalpha(ch)) { if(isupper(ch)) { res++; cout<<ch<<endl; } ch=getchar(); } if(ch=='.' || ch=='?' || ch=='!')over=true; } cout<<res<<endl; }
相关文章推荐
- 南阳oj 400 I'll play a trick on you (细节规律题 简单的字符串处理)
- hdu 1038 Biker's Trip Odometer(简单计算题)
- 问题1:java中没有实现这种“byte a = 0xB2 --> String b = “B2””转换的简单实现需要自己实现。 答:自己编写的转换函数,思路将byte的高低4位分开,分别转换为对应的字符然后合成返回的字符串。 java 代码 1.
- 字符串(流操作)fafu - 1543 -简单求和 && hdu 1106 排序
- Redis之简单动态字符串&链表
- 华为 oj 简单密码破解&&汽水瓶&&删除字符串中出现次数最少的字符&&字符串排序
- python中使用状态机的简单例子---截取'/x00'之前的字符串
- 字符串反转 "you are beautiful" 转为 "beautiful are you" 方法二 更为简单
- IOS中json字符串原生数据请求&IOS跨平台AES128字符串加解密&AFNetworking框架的简单封装使用
- URAL 1989 Subpalindromes(字符串HASH&线段树单点更新)
- uva10815 Andy's First Dictionary(字符串的简单处理)
- HDU(简单题目) 1038 Biker's Trip Odometer 1039 Easier Done Than Said?
- 最简单的字符串加密C#实现-移位加密
- 字符串转换的类,如230991.291==&amp;gt;230,991.291
- 用于执行(计算) "字符串表达式" 的 T-SQL 存储过程
- [Boost]一种简单的批分字符串的办法
- 更简单的办法 分解字符串,找到字符串中的汉字(宽字符)
- delphi中将UCS2编码的字符串转化为GB2312编码的简单方法
- 输入一个汉字字符串'我爱中国',怎么返回他的首拼'WAZG'
- 一段简单对话,关于 2>&1