Description
Many classmates said to me that A+B is must needs. If you can’t AC this problem, you would invite me for night meal. ^_^
Input
Input may contain multiple test cases. Each case contains A and B in one line. A, B are hexadecimal number. Input terminates by EOF.
Output
Output A+B in decimal number in one line.
Sample Input
1 9 A B a b
Sample Output
10 21 21
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%x %x",&a,&b)!=EOF)//直接用十六进制输入,如果有输入则scanf有返回值
// 此循环会一直进行
{
printf("%d\n",a+b);
}
return 0;
}
Description
Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked. You are a sub captain of Caesar's army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is 'A', the cipher text would be 'F'). Since you are creating plain text out of Caesar's messages, you will do the opposite: Cipher text A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Plain text V W X Y Z A B C D E F G H I J K L M N O P Q R S T U Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase. A single data set has 3 components: Start line - A single line, "START" Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar End line - A single line, "END" Following the final data set will be a single line, "ENDOFINPUT".
Output
For each data set, there will be exactly one line of output. This is the original message by Caesar.
Sample Input
START NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX END START N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ END START IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ END ENDOFINPUT
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
(以上说这么多,其实就是把一段密文给破解出来,将每个字符往前移5个即可,如果是A~E之间,移到A之后接着从Z往前移,所以ASCII码要+26-5。输入密文之前要先输入START,密文输入结束要输入END表示该行密文结束,输入ENDOFINPUT表示所有的密文全都输入完毕。)
#include<stdio.h>
#include<string.h>
int main()
{
int i;
char a[100],b[100],c[100];
gets(a);
while(strcmp(a,"ENDOFINPUT")){
if(strcmp(a,"START")==0)
{
gets(b);
}
gets(c);
if(strcmp(c,"END")==0)
{
int len=strlen(b);
for(i=0;i<len;i++)
{
if(b[i]>='F'&&b[i]<='Z')
b[i]=b[i]-5;
else
if(b[i]>='A'&&b[i]<='E')
b[i]=b[i]+26-5;
}
}
puts(b);
gets(a);
}
return 0;
}
Description
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。
Input
输入包括一行。 第一行输入的字符串。
Output
输出转换好的逆序字符串。
Sample Input
I am a student
Sample Output
tneduts a ma I
#include<stdio.h>
#include<string.h>
int main()
{
char a[100],c[100];
int b;
int j=0,i=0;
gets(a);
b=strlen(a);
for(i=0;i<b;i++)
{
c[i]=a[b-1-i];
}
c[b]=0;
puts(c);
return 0;
}
Description
问题很简单,求x^n.请编写pow()函数.
声明如下:
int pow(int x,int n,int p)
//pow的功能是实现x^n,最后1个参数p没有用。
系统会自动在程序的最后加上如下代码:
int main()
{
int x,n;
scanf("%d %d",&x,&n);
printf("%d\n",pow(x,n,1));
return 0;
}
Input
x和n 0 < x,n < 2^31-1
Output
x^n .最后结果小于 2^31-1
Sample Input
2 3
Sample Output
8
#include<stdio.h>
#include<string.h>
int pow(int x,int n,int p)
{
int a;
if(n==0)
return 1;
a=pow(x,n/2,1);
if(n%2!=0)
return a*a*x;
else
return a*a;
return a;
}
int main()
{
int x,n;
scanf("%d %d",&x,&n);
printf("%d\n",pow(x,n,1));
return 0;
}
Description
字符串的输入输出处理。
Input
第一行是一个正整数N,最大为100。之后是多行字符串(行数大于N), 每一行字符串可能含有空格,字符数不超过1000。
Output
先将输入中的前N行字符串(可能含有空格)原样输出,再将余下的字符串(不含有空格)以空格或回车分割依次按行输出。每行输出之间输出一个空行。
Sample Input
2 www.njupt.edu.cn NUPT A C M N U P Ter
Sample Output
www.njupt.edu.cn NUPT A C M N U P Ter
#include<stdio.h>
#include<string.h>
int main()
{
int n,i;
scanf("%d",&n);
getchar();//取走空字符
char a[1000];
for(i=0;i<n;i++){
gets(a);
puts(a);
printf("\n");
}
char b[1000];
while(scanf("%s",b)!=EOF)//有空字符(空格)scanf就认为该字符串结束
{
puts(b);
printf("\n");
}
return 0;
}
最后的循环用了scanf,它只能读取到第一个空格之前的内容,当一行字符串被几个空格隔开之后,会先输出第一个空格之前的字符串N。而它本来会继续等待下一次输入,但下一次输入已经存在了,所以会继续输出下一行字符串U。以此类推。