题目1039:Zero-complexity Transposition
题目描述:
You are given a sequence of integer numbers. Zero-complexity transposition of the sequence is the reverse of this sequence. Your task is to write a program that prints zero-complexity transposition of the given sequence.
输入:
For each case, the first line of the input file contains one integer n-length of the sequence (0 < n ≤ 10 000). The second line contains n integers numbers-a1, a2, …, an (-1 000 000 000 000 000 ≤ ai ≤ 1 000 000 000 000 000).
输出:
For each case, on the first line of the output file print the sequence in the reverse order.
样例输入:
5
-3 4 6 -8 9
样例输出:
9 -8 6 4 -3
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int m, n, i;
long long num[10000];
while(scanf("%d",&m)!=EOF){
getchar();
for(i=0;i<m;i++){
scanf("%lld",&num[i]);
}
for(i=m-1; i>=0;i--){
printf("%lld%c",num[i],i==0?'\n':' ');
}
}
return 0;
}
关键点:后面逆序输入的数字的范围需要用long long类型,并且scanf中需要使用%lld
题目1510:替换空格
题目描述:
请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
输入:
每个输入文件仅包含一组测试样例。
对于每组测试案例,输入一行代表要处理的字符串。
输出:
对应每个测试案例,出经过处理后的字符串。
样例输入:
We Are Happy
样例输出:
We%20Are%20Happy
代码:
int main(){
char str[10000];
char tmp[10000];
while(gets(str)!=NULL){
int len = strlen(str);
int j=0;
for(int i=0;i<len;i++){
if(str[i]==' '){
tmp[j++]='%';
tmp[j++]='2';
tmp[j++]='0';
}
else
tmp[j++]=str[i];
}
tmp[j]=0;
printf("%s\n",tmp);
}
return 0;
}
题目1511:从尾到头打印链表
题目描述:
输入一个链表,从尾到头打印链表每个节点的值。
输入:
每个输入文件仅包含一组测试样例。
每一组测试案例包含多行,每行一个大于0的整数,代表一个链表的节点。第一行是链表第一个节点的值,依次类推。当输入到-1时代表链表输入完毕。-1本身不属于链表。
输出:
对应每个测试案例,以从尾到头的顺序输出链表每个节点的值,每个值占一行。
样例输入:
1
2
3
4
5
-1
样例输出:
5
4
3
2
1
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int m, n, i=0;
int num[10000];
while(scanf("%d",&num[i++])!=EOF){
do{
scanf("%d",&num[i++]);
}while(num[i-1]!=-1);
for(int j=i-2;j>=0;j--){
printf("%d\n",num[j]);
}
i=0;
}
return 0;
}
后面两题都还没有提交通过,明天再来修改一下。