Ural1094 && Ural1038(简单字符串)
来源:互联网 发布:双色球必中六红的算法 编辑:程序博客网 时间:2024/05/07 06:33
1094. E-screen
Time limit: 0.25 second
Memory limit: 64 MB
Memory 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 position to 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 position to the left.
Sample
>><<<Look for clothes at the <<<<<<<<<<<<<<<second floor. <<<<<<<Fresh pizza and <<<<<<<<<<<<<<<<hamburger at a shop right to <<<<<<<<<<<<<the entrance. Call <<<<<<<<<< 123<-456<-8790 <<<<<<<<<<<<<<<<to order <<<<<<<<<<<<<<<<<computers< and office<<<<<<< chairs.
Look for second hamburger at computer and chairs.790直接按照题意模拟就好,刚开始用的取模,老是WA,其实不能用取模,而是直接归零。
#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 second
Memory limit: 64 MB
Memory 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
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; }
0 0
- Ural1094 && Ural1038(简单字符串)
- HDU2567(字符串简单题)
- 字符串连接(简单模拟)
- c#中分割字符串(简单程序)
- 字符串加密的简单实现(练习)
- 简单字符串排序(冒泡法)
- 整数转成字符串 (有简单方法)
- Pixel density(简单的字符串处理)
- UVA 401(palindorme)简单字符串处理
- Redis -- 1、简单动态字符串(sds)
- poj1002 487-3279 (简单字符串处理)
- n a^o7 ! (简单字符串处理)
- Redis数据结构(一)简单动态字符串
- java简单的输入语句(字符串)
- Android Socket(简单的字符串)
- UVa 401 Palindromes(简单字符串)
- C++简单字符串加密(替换)
- poj_1936 All in All(简单字符串)
- 至三年以后的自己
- 数据挖掘四类问题算法归纳
- 判断树a是否是树b的子树--递归递归递归
- Urlrewrite 配置信息写在另外一个文件
- android 获得手机,SD卡的(可用)内存
- Ural1094 && Ural1038(简单字符串)
- 数数小木块
- express使用msyql存储session
- Xcode项目引入外部文件夹,不能引用问题
- socket通讯 http协议 网络抓包
- 华为笔试 C 语言 试题
- 用户需求、功能需求与业务需求的区别
- Hadoop-1.2.1安装HBase(伪分布模式)
- android 短信管理(获取接受到短信的消息)