并不是很精简,随便改改A过了就没有再简化了。
1020.
Problem Description
Given a string containing only 'A' - 'Z', we could encode it using the following method:
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.
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.
Input
The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.
Output
For each test case, output the encoded string in a line.
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 int main() 5 { 6 int n,count;; 7 cin>>n; 8 while(n--) 9 { 10 string str; 11 cin>>str; 12 for(int i=0;i<(int)str.length();i++) 13 { 14 count=1; 15 while(str[i]==str[i+1]) 16 { 17 count++;i++; 18 } 19 if(count!=1) 20 cout<<count; 21 cout<<str[i]; 22 } 23 cout<<endl; 24 } 25 return 0; 26 }
1039.
Problem Description
Password security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passwords are often insecure. Some sites use random computer-generated passwords (like xvtpzyo), but users have a hard time remembering them and sometimes leave them written on notes stuck to their computer. One potential solution is to generate "pronounceable" passwords that are relatively secure but still easy to remember.
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.
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.
Input
The input consists of one or more potential passwords, one per line, followed by a line containing only the word 'end' that signals the end of the file. Each password is at least one and at most twenty letters long and consists only of lowercase letters.
Output
For each password, output whether or not it is acceptable, using the precise format shown in the example.
Sample Input
a
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end
Sample Output
<a> is acceptable.
<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.
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 bool search1(string str) 5 { 6 for(int i=0;i<=(int)str.length()-1;i++) 7 { 8 if(str[i]=='a'||str[i]=='e') return true; 9 if(str[i]=='i'||str[i]=='o'||str[i]=='u') return true; 10 } 11 return false; 12 } 13 bool search2(string str) 14 { 15 int count1=0,count2=0; 16 for(int i=0;i<=(int)str.length()-1;i++) 17 { 18 if(i!=0&&str[i-1]==str[i]) 19 {if(str[i]=='o'||str[i]=='e'); 20 else return false;} 21 if (str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u') 22 { 23 count1++; 24 count2=0; 25 } 26 else 27 { 28 count2++; 29 count1=0; 30 } 31 if(count1>=3||count2>=3) 32 return false; 33 } 34 return true; 35 } 36 int main() 37 { 38 string str; 39 while(1) 40 { 41 cin>>str; 42 if(str=="end") 43 break; 44 if(search1(str)&&search2(str)) 45 cout<<'<'<<str<<'>'<<" is acceptable."<<endl; 46 else 47 cout<<'<'<<str<<'>'<<" is not acceptable."<<endl; 48 } 49 50 }
1062.
Problem Description
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
Output
For each test case, you should output the text which is processed.
Sample Input
3
olleh !dlrow
m'I morf .udh
I ekil .mca
Sample Output
hello world!
I'm from hdu.
I like acm.
Hint
Remember to use getchar() to read '
' after the interger T, then you may use gets() to read a line and process it.
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 const int maxn=1005; 5 char a[maxn],b[maxn]; 6 void print(char *str) 7 { 8 for(int i=strlen(str)-1;i>=0;i--) 9 cout<<str[i]; 10 } 11 int main() 12 { 13 int n,i,j,len; 14 cin>>n; 15 getchar(); 16 while(n--) 17 { 18 gets(a); 19 len=strlen(a); 20 a[len]=' '; 21 a[len+1]='