HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)
并不是很精简,随便改改A过了就没有再简化了。
1020.
1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
2. If the length of the sub-string is 1, '1' should be ignored.
ABC
ABBCCC
A2B3C
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,count;;
cin>>n;
while(n--)
{
string str;
cin>>str;
for(int i=;i<(int)str.length();i++)
{
count=;
while(str[i]==str[i+])
{
count++;i++;
}
if(count!=)
cout<<count;
cout<<str[i];
}
cout<<endl;
}
return ;
}
1020
1039.
FnordCom is developing such a password generator. You work in the quality control department, and it's your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules:
It must contain at least one vowel.
It cannot contain three consecutive vowels or three consecutive consonants.
It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.
(For the purposes of this problem, the vowels are 'a', 'e', 'i', 'o', and 'u'; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable.
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end
<tv> is not acceptable.
<ptoui> is not acceptable.
<bontres> is not acceptable.
<zoggax> is not acceptable.
<wiinq> is not acceptable.
<eep> is acceptable.
<houctuh> is acceptable.
#include<iostream>
#include<string>
using namespace std;
bool search1(string str)
{
for(int i=;i<=(int)str.length()-;i++)
{
if(str[i]=='a'||str[i]=='e') return true;
if(str[i]=='i'||str[i]=='o'||str[i]=='u') return true;
}
return false;
}
bool search2(string str)
{
int count1=,count2=;
for(int i=;i<=(int)str.length()-;i++)
{
if(i!=&&str[i-]==str[i])
{if(str[i]=='o'||str[i]=='e');
else return false;}
if (str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
{
count1++;
count2=;
}
else
{
count2++;
count1=;
}
if(count1>=||count2>=)
return false;
}
return true;
}
int main()
{
string str;
while()
{
cin>>str;
if(str=="end")
break;
if(search1(str)&&search2(str))
cout<<'<'<<str<<'>'<<" is acceptable."<<endl;
else
cout<<'<'<<str<<'>'<<" is not acceptable."<<endl;
} }
1062.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
olleh !dlrow
m'I morf .udh
I ekil .mca
I'm from hdu.
I like acm.
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
#include<iostream>
#include<string>
using namespace std;
const int maxn=;
char a[maxn],b[maxn];
void print(char *str)
{
for(int i=strlen(str)-;i>=;i--)
cout<<str[i];
}
int main()
{
int n,i,j,len;
cin>>n;
getchar();
while(n--)
{
gets(a);
len=strlen(a);
a[len]=' ';
a[len+]='\0';
b[]='\0';
for(i=,j=;i<=len;i++)
{
if(a[i]==' ')
{
print(b);
b[]='\0';
cout<<(i==len?'\n':' ');
j=;
}
else
{
b[j]=a[i];
j++;
b[j]='\0';
}
}
}
return ;
}
1088.
Now, who can forget to install a HTML browser? This is very easy because most of the times you don't need one on a MAC because there is a Acrobate Reader which is native to MAC. But if you ever need one, what do you do?
Your task is to write a small html-browser. It should only display the content of the input-file and knows only the html commands (tags) <br> which is a linebreak and <hr> which is a horizontal ruler. Then you should treat all tabulators, spaces and newlines as one space and display the resulting text with no more than 80 characters on a line.
A word is a sequence of letters, numbers and punctuation. For example, "abc,123" is one word, but "abc, 123" are two words, namely "abc," and "123". A word is always shorter than 81 characters and does not contain any '<' or '>'. All HTML tags are either <br> or <hr>.
. If you read a word in the input and the resulting line does not get longer than 80 chars, print it, else print it on a new line.
. If you read a <br> in the input, start a new line.
. If you read a <hr> in the input, start a new line unless you already are at the beginning of a line, display 80 characters of '-' and start a new line (again).
The last line is ended by a newline character.
ziemlich lange Zeile, die in Html
aber nicht umgebrochen wird.
<br>
Zwei <br> <br> produzieren zwei Newlines.
Es gibt auch noch das tag <hr> was einen Trenner darstellt.
Zwei <hr> <hr> produzieren zwei Horizontal Rulers.
Achtung mehrere Leerzeichen irritieren
Html genauso wenig wie
mehrere Leerzeilen.
wird.
Zwei
produzieren zwei Newlines. Es gibt auch noch das tag
--------------------------------------------------------------------------------
was einen Trenner darstellt. Zwei
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
produzieren zwei Horizontal Rulers. Achtung mehrere Leerzeichen irritieren Html
genauso wenig wie mehrere Leerzeilen.
#include<iostream>
char s[];
using namespace std;
int main()
{
int count=;
while(~scanf("%s",s))
{
if(!strcmp(s,"<br>"))
{
cout<<endl;
count=;
}
else if(!strcmp(s,"<hr>"))
{
if(count)
cout<<'\n';
cout<<"--------------------------------------------------------------------------------\n";
count=;
}
else
{
int length=strlen(s);
if(count==)
{
cout<<s;
count=length;
}
else if((count+length+)>=)
{
cout<<endl<<s;
count=length;
}
else
{
cout<<' '<<s;
count+=length+;
}
}
}
cout<<endl;
}
1161.
composition, the writing length does not surpass 1000 characters.
#include<iostream>
const int maxn=;
char str[];
using namespace std;
int main()
{
while(gets(str))
{
for(int i=;str[i]!='\0';i++)
{
if(str[i]>='A'&&str[i]<='Z')
str[i]+=;
}
cout<<str<<endl;
}
}
1200.
t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x
Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character ‘x’ to pad the message out to make a rectangle, although he could have used any letter.
Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would be encrypted as
toioynnkpheleaigshareconhtomesnlewx
Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
#include<iostream>
using namespace std;
#include<string>
int main()
{
// freopen("F:\\in.txt","r",stdin);
//freopen("F:\\ou.txt","w",stdout);
string s;int c,t,count;
while(){
cin>>c;
if(!c) break;
cin>>s;
int n=int(s.length());
for(int k=;k<=c;k++)
{
t=k-;count=;
while(t<=n-)
{
cout<<s[t];
if(count%)
t+=*c--*(k-);
else
t+=*k-;
count++;
}
}
cout<<endl;
}
//fclose(stdin);
//fclose(stdout);
return ;
}
2017.
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf
9
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main()
{
int n,count;
cin>>n;
while(n--)
{
count=;
string str;
cin>>str;
for(string::iterator it=str.begin();it!=str.end();it++)
if(isdigit(*it))
count++;
cout<<count<<endl;
} }
HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)的更多相关文章
- hdu 5326(基础题) work
http://acm.hdu.edu.cn/showproblem.php?pid=5326 一道水题,题目大意是在公司里,给出n个员工和目标人数m,然后下面的n-1行是表示员工a管理b,问在这些员工 ...
- HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads
双向边,基础题,最小生成树 题目 同题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...
- hdu 2089 不要62 (数位dp基础题)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Jam's balance HDU - 5616 (01背包基础题)
Jim has a balance and N weights. (1≤N≤20) The balance can only tell whether things on different side ...
- 小试牛刀3之JavaScript基础题
JavaScript基础题 1.让用户输入两个数字,然后输出相加的结果. *prompt() 方法用于显示可提示用户进行输入的对话框. 语法: prompt(text,defaultText) 说明: ...
- 小试牛刀2:JavaScript基础题
JavaScript基础题 1.网页中有个字符串“我有一个梦想”,使用JavaScript获取该字符串的长度,同时输出字符串最后两个字. 答案: <!DOCTYPE html PUBLIC &q ...
- POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划)
POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Descri ...
- Java面试题以及答案精选(架构师面试题)-基础题1
基础题 一.String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的?1. String是字符串常量,StringBuffer和StringBu ...
- C/C++笔试题(基础题)
为了便于温故而知新,特于此整理 C/C++ 方面相关面试题.分享,共勉. (备注:各题的重要程度与先后顺序无关.不断更新中......欢迎补充) (1)分析下面程序的输出(* 与 -- 运算符优先级问 ...
随机推荐
- linux发行版和内核的关系
转自:http://m.blog.csdn.net/article/details?id=50595230 Linux内核是计算机操作系统的核心.一个完整的 Linux发行版包括了内核与一些其他与文件 ...
- javascript之ProtoBuf在websocket中的使用
因为ProtoBuf的序列化效率和大小都非常好,所以它在网络通信上面应用越来越多:而webosocket也随着web3.0应用越来越广泛,而将这两个结合在一起的也会慢慢形成一种趋势:本人是为了测试自已 ...
- Reflect(反射)
反射.反射,程序员的快乐.反射是无处不在的. 那么什么是反射:通过反射,可以在运行时获得程序或程序集中每一个类型(包括类.结构.委托.接口和枚举等)的成员和成员的信息.有了反射,即可对每一个类型了如指 ...
- CUDA零内存拷贝 疑问考证
今天思考了一下CUDA零内存拷贝的问题,感觉在即将设计的程序中会派上用场,于是就查了一下相关信息. 以下是一些有帮助的链接: cuda中的零拷贝用法--针对二维指针 cuda中的零拷贝用法--针对一维 ...
- HDFS Java API的使用举例
HDFS是Hadoop应用程序使用的主要分布式存储.HDFS集群主要由管理文件系统元数据的NameNode和存储实际数据的DataNodes组成,HDFS架构图描述了NameNode,DataNode ...
- Docker 的两类存储资源 - 每天5分钟玩转 Docker 容器技术(38)
我们从本章开始讨论 Docker 存储. Docker 为容器提供了两种存放数据的资源: 由 storage driver 管理的镜像层和容器层. Data Volume. 我们会详细讨论它们的原理和 ...
- 函数的上下文就是函数里面的this是谁
规律1:函数用圆括号调用,函数的上下文是window对象 比如小题目: function fun(){ var a = 888; alert(this.a); //实际上访问的是window.a } ...
- Azure PowerShell (14) 批量导出Azure ASM ACL和ARM NSG配置信息
<Windows Azure Platform 系列文章目录> 最近有一个客户需求,需要批量导出Azure Classic VM的ACL (Access Control List), 还有 ...
- JavaWeb 后端 <十一> 之 DBUtils 框架 (基本使用 结果集 事务处理 对表读取)
一.数据库操作框架 1.ORM:Object Relation Mapping Hibernate:非常流行 JPA:Java Persistent API.ORM标准 MyBatis:2010年开始 ...
- jdk和jre有什么区别?
简单的说JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环境.SDK是Software Development Kit 一般指软件开发包,可以包括函数库.编译程序等. JDK就是Ja ...