题目描述
字符串的输入输出处理。
输入
第一行是一个正整数N,最大为100。之后是多行字符串(行数大于N), 每一行字符串可能含有空格,字符数不超过1000。
输出
先将输入中的前N行字符串(可能含有空格)原样输出,再将余下的字符串(不含有空格)以空格或回车分割依次按行输出。每行输出之间输出一个空行。
样例输入
2
www.njupt.edu.cn NUPT
A C M
N U P Ter
样例输出
www.njupt.edu.cn NUPT
A C M
N
U
P
Ter
参考代码
#include <stdio.h>
int F(int i);
int main()
{
int a,b,i,temp=0,temp1,temp2,a1,a2;
while(scanf("%d %d",&a,&b)==2)
{
a1=a;
a2=b;
if(a>b)
{
temp2=a;
a=b;
b=temp2;
}
for (i=a;i<=b;i++)
{
temp1=F(i);
//printf("%dn",temp1);
if(temp<temp1)
temp=temp1;
}
printf("%d %d %dn",a1,a2,temp);
temp=0;
}
}
int F(int i)
{
int temp=i,j=1;
while(1)
{
if(temp==1)
return j;
if(temp%2==0)
{
temp=temp/2;
}
else
{
temp=temp*3+1;
}
j++;
}
}
解析
暂无