以打印规定的输出
to print the output prescribed
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
main()
{
int q,a,b,i,number;
cin>>q;
while(q--)
{
cin>>a>>b;
int a[b];
int number=1;
for(i=0;i<b;i++)
{
if(i==0)
{
a[i]=number;
number++;
}
a[i]=number;
if(number>0)
number=number*-1;
}
}
}
/*the above code i tried a little bit , but it's incomplete and may be incorrect too, you may help
i want to print the sequence as 1,2,-2,3,-3,3,4,-4,4,-4,5,-5,5,-5,5..... till n , where n is size of array in c++?*/
厨师的孩子,初级厨师喜欢玩不同的系列。厨师被儿子的好奇心所打动,在他生日那天送给他一个特别系列的S。S=1,2,-2,3,-3,3,4,-4,4,-4,.............现在厨师急于检查儿子的智商,给他q查询解决。每个查询由两个位置 a 和 b 组成,需要 Junior_chef 来计算从 a 到 b 的所有整数的总和。输入
输入的第一行包含一个整数 q,表示查询数。接下来的 q 行由两个整数组成,a 和 b。输出
在一行中打印答案。约束
1<=q<=10 , 1<=a,b<=10^12示例输入
11 4示例输出
四说明:由于序列是 1,2,-2,3,因此总和将是 4。
你的意思是以下内容吗?
#include <iostream>
int main()
{
while ( true )
{
std::cout << "Enter a non-negative number (0-exit): ";
int n = 0;
std::cin >> n;
if ( n <= 0 ) break;
for ( int i = 1; i <= n; i++ )
{
for ( int j = 0; j < i; j++ ) std::cout << ( j % 2 ? -i : i ) << ' ';
}
std::endl( std::cout );
}
return 0;
}
如果按顺序输入 1 2 3 4 5 6 7 0,则输出将是
Enter a non-negative number (0-exit): 1
1
Enter a non-negative number (0-exit): 2
1 2 -2
Enter a non-negative number (0-exit): 3
1 2 -2 3 -3 3
Enter a non-negative number (0-exit): 4
1 2 -2 3 -3 3 4 -4 4 -4
Enter a non-negative number (0-exit): 5
1 2 -2 3 -3 3 4 -4 4 -4 5 -5 5 -5 5
Enter a non-negative number (0-exit): 6
1 2 -2 3 -3 3 4 -4 4 -4 5 -5 5 -5 5 6 -6 6 -6 6 -6
Enter a non-negative number (0-exit): 7
1 2 -2 3 -3 3 4 -4 4 -4 5 -5 5 -5 5 6 -6 6 -6 6 -6 7 -7 7 -7 7 -7 7
Enter a non-negative number (0-exit): 0
相关文章:
- 数组类 阵列的打印输出
- 我要求用户输入大小和数组,但是当我打印矢量时,它仅显示'0'作为输出
- 程序打印 % 后预期输出
- 为什么Qt Creator的应用程序输出不能从spdlog记录器打印
- 为什么打印 c 样式字符串的'address of index n'会导致子字符串的输出
- 为什么打印"OK"会改变输出?
- 打印输出在主,而不是在函数中
- 该程序没有产生输出,而是卡在一个循环中,几秒钟后消失并打印被杀死?
- 存储和打印字符,但输出不是预期的
- 执行ls命令并打印输出
- 为什么如果我从键盘输入EOF克里昂不要在运行窗口打印程序的输出?
- 将C++输出打印到文本文件
- 如何仅使输出打印一次
- 以未格式化的输出 c++ 打印输出
- 如何将谷歌测试输出打印到文本文件
- 为类打印输出(打印调试信息)的最佳实践是什么?
- 将命令行输出打印到Linux(Ubuntu)的文本文件中
- 输出打印地址而不是3D数组指针中的值
- 将Qt C++输出打印到QML中写入的应用程序屏幕
- 多线程文本输出打印到dos控制台重叠/混乱输出