A - 雷同检测
考试的时候老师最讨厌有人抄袭了。自从有了电子评卷,老师要查找雷同卷,就容易多了,只要将两个人的答案输入计算机,进行逐个字符的比对,把相同的位置都找出来,就一目了然了。
输入格式
22 行,每行包含一串字符(长度不超过 200200)。
输出格式
11 行,包含若干个以空格分隔的数字,表示出现相同字符的位置。
Sample Input
I am suantoujun. I am huayemei.
Sample Output
1 2 3 4 5 6 8 9
#include <iostream>
#include<string>
using namespace std;
int main(){
string a,b;
getline(cin,a);
getline(cin,b);
int c=a.size();
int d=b.size();
int i;
for(i=0;i<c||i<d;i++){
if(a[i]==b[i]){
cout<<i+1<<' ';
}
}
return 0;
}
B - 首字母大写
对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\t')、回车符('\r')、换行符('\n')。
Input
输入一行:待处理的字符串(长度小于80)。
Output
输出一行:转换后的字符串。
Sample Input
if so, you already have a google account. you can sign in on the right.
Sample Output
If So, You Already Have A Google Account. You Can Sign In On The Right.
#include <iostream>
#include<string>
using namespace std;
int main(){
string a;
getline(cin,a);
if(a[0]<='z'&&a[0]>='a'){
a[0]=toupper(a[0]);
}
for(int i=0;i<a.size();i++){
if((a[i-1]==' '||a[i-1]=='\t'||a[i-1]=='\r'||a[i-1]=='\n')&&a[i]<='z'&&a[i]>='a'){
a[i]=toupper(a[i]);
}
}
cout<<a;
}
C - 大小写转换
读入一些字符串,将其中的小写字母转成大写字母(其他字符不变)。
输入
输入为多行,每行为一个字符串,字符串只由字母和数字组成,长度不超过80。输入以“End of file”结束。
输出
对于每行输入,输出转换后的字符串。
输入示例
Hello ICPC2004 12345abcde
输出示例
HELLO ICPC2004 12345ABCDE
提示
用“scanf("%s", str) == 1”这个条件可以判断输入是否结束。如果此条件为假,则输入结束(对于本题)。
姜边 2004.3
#include <string>
#include <iostream>
using namespace std;
int main(){
char str[10000];
int len;
while(scanf("%s",str)==1){
len=sizeof(str);
for(int i=0;i<len;i++)
if(str[i]>='a'&&str[i]<='z'){
str[i]=str[i]-32;
}
cout<<str<<endl;
}
}
D - 数字反转
给定一个整数,请将该数各个位上数字反转得到一个新数。新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零(参见样例 22)。
输入格式
输入共 11 行,一个整数 NN。
输出格式
输出共 1 行,一个整数,表示反转后的新数。
数据范围
-1,000,000,000 \le N \le 1,000,000,000−1,000,000,000≤N≤1,000,000,000。
Sample Input
123
Sample Output
321
Sample Input 2
-380
Sample Output 2
-83
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
int a,b=0,c;
for(int i=0;;i++){
c=b;
a=x/10;
b=x%10;
x=a;
b=b+c*10;
if(a==0){
break;
}
}
cout<<b<<endl;
}
E - 删除单词后缀
给定一个单词,如果该单词以er
、ly
或者ing
后缀结尾, 则删除该后缀(题目保证删除后缀后的单词长度不为 00),否则不进行任何操作。
输入格式
输入一行,包含一个单词(单词中间没有空格,每个单词最大长度为 3232)。
输出格式
输出按照题目要求处理后的单词。
Sample Input
referer
Sample Output
refer
#include <iostream>
#include <string>
using namespace std;
string str;
int main(){
cin>>str;
if(str.find("ing",str.size()-3)!=-1){
str=str.substr(0,str.size()-3);
}
else if(str.find("ly",str.size()-2)!=-1){
str=str.substr(0,str.size()-2);
}
else if(str.find("er",str.size()-2)!=-1){
str=str.substr(0,str.size()-2);
}
cout<<str;
}
F - 判断字符串是否为回文
输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。
输入格式
输入为一行字符串(字符串中没有空白字符,字符串长度不超过 100100)。
输出格式
如果字符串是回文,输出"yes"
;否则,输出"no"
。
Sample Input
abcdedcba
Sample Output
yes
#include <iostream>
#include<algorithm>
#include <string>
using namespace std;
int main(){
string str;
string str1;
cin >> str;
str1=str;
reverse(str.begin(),str.end());
if(str1==str){
cout<<"yes"<<endl;
}
else{
cout<<"no"<<endl;
}
}