循环
/*
//九九乘法表第一种
#include<iostream>
using namespace std;
int main()
{
int i = 0;
int j = 0;
for (i = 1; i <= 9; i++)//外层循环变量,控制行
{
for (j = 1; j <= i; j++)//内层循环变量,控制列
{
cout << j << "x" << i << "=" << i*j << '\t';
}
printf("\n");//每行输出完后换行
}
}
*/
/*
//第二种
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
cout << j << "x" << i << "=";
if (i*j >= 1 && i*j <= 9)printf("%1d ", i*j);
else cout << i*j << " ";
}
cout << endl;
}
return 0;
}
*/
/*
//桔子数量
小明数桔子只会从1数到x(x<=10),数了三遍还是不清楚有多少个,发现最后剩余y个,求最少有多少桔子
输入格式
输入参数为6个整数,分别为三遍里每次数到的数量x和剩余的数量y。
输出格式
输出为一个整数,为最少的桔子数量
样例输入
2 1 3 2 5 4
样例输出
29
#include<iostream>
using namespace std;
int main()
{
int x1, x2, x3, y1, y2, y3, s;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
for (s = 0; s < 10000; s++)if (s%x1 == y1&&s%x2 == y2&&s%x3 == y3)break;
cout << s;
return 0;
}
*/
/*
//有多少个7
输入一个4位数的整数,输出7的个数
#include<iostream>
using namespace std;
int main()
{
int a, b, c = 0;
cin >> a;
while (a)
{
b = a % 10;
a = a / 10;
if (b == 7)c++;
}
cout << c;
return 0;
}
*/
/*
//画矩形
输入一行,包括四个参数:前两个参数为整数,依次代表矩形的高和宽(高不少于3行不多于10行,宽不少于5列不多于10列);第三个参数是一个字符,表示用来画图的矩形符号;第四个参数为1或0(0代表空心,1代表实心)
样例输入
7 7 @ 0
样例输出
@@@@@@@
@ @
@ @
@ @
@ @
@ @
@@@@@@@
#include<iostream>
using namespace std;
int main()
{
int a, b, d, j, i;
char c;
cin >> a >> b >> c >> d;
if (d == 1)
for (j = 1; j <= a; j++)
{
for (i = 1; i <= b; i++) cout << c;
cout << endl;
}
else
for (j = 1; j <= a; j++)
{
for (i = 1; i <= b; i++)
{
if (j == 1 || j == a || i == 1 || i == b)cout << c;
else cout << " ";
}
cout << endl;
}
return 0;
}
*/
/*
//金币
//第一天,骑士收到一枚金币;
//之后两天(第二天和第三天)里,每天收到两枚金币;
//之后三天(第四、五、六天)里,每天收到三枚金币;
//之后四天(第七、八、九、十天)里,每天收到四枚金币……
//当连续N天每天收到N枚金币后,骑士会在之后的连续N+1天里,每天收到N+1枚金币(N为任意正整数)。
//问从第一天开始的给定天数内,骑士一共获得了多少金币。
//输入一个整数表示天数,输出获得的金币数。
样例输入
6
样例输出
14
#include<iostream>
using namespace std;
int main()
{
int k,i = 0,a = 0, b = 0;
cin >> k;
while (b <= k)
{
++i;
a += i*i;
b = (i + 1)*i / 2;
}
a = a - (b - k)*i;
cout << a << endl;
return 0;
}
*/
/*
//敲7
//输出7和7的倍数,还有包含7的数字。例如(7,14,17,21,27,28,35,37......)
//输入一个整数N,输出从小到大排列的不大于N的与7有关的数字,每行一个。
样例输入
20
样例输出
7
14
17
#include <iostream>
using namespace std;
int main()
{
int i, n;
cin >> Nn;
for (i = 1; i <= n; i++)
{
if (i % 7 == 0)cout << i << endl;
else
{
int temp = i;
while (temp > 0)
{
if (temp % 10 == 7)
{
cout << i << endl;
break;
}
temp = temp / 10;
}
}
}
}
*/
/*
//蛋糕裱花
//蛋糕总是做成菱形,用“*”画出空心菱形裱花形状
//输入一个正整数,输出由n*2-1层“*”号组成的空心菱形。
样例输入
5
样例输出
*
* *
* *
* *
* *
* *
* *
* *
*
#include<iostream>
using namespace std;
int main()
{
int i, k, a, j;
cin >> a;
for (i = 0; i < 2 * a - 1; i++)
{
for (k = 1; k < 2 * a; k++)if ((k == a - i) || (k == a + i) || (k == 3 * a - i - 2) || (k == i - a + 2))
cout << "*";
else cout << " ";
cout << endl;
}
return 0;
}
*/
/*
//粘墙“三角形”
//输入一个正整数,输出以这些正整数为边长的附着墙而立的字母三角形。
输//入一个正整数,输出每个正整数对应的图案。每组图案之间空一行。
样例输入
3
样例输出
a a
a ab
aabc
#include <iostream>
using namespace std;
int main()
{
int i, a, n, x;
char c;
while (cin >> n)
{
x = n;
for (i = 1; i <= x; i++)
{
cout<< "a";
for (int j = 1; j < n; j++)cout << " ";
n--;
for (a = 0; a < i; a++)
{
c = 97 + a;
cout << c;
}
cout << "\n";
}
cout << endl;
}
return 0;
}
*/
/*
//打印菱形
//输入n,打印规模为n(n为奇数)的菱形。
当n = 3时,菱形如下:
*
***
*
当n = 5时,菱形如下:
*
***
*****
***
*
提示 / 说明
打印菱形分为上下两个三角形,上面三角形中*个数逐渐增加,空格逐渐减少,下面三角形与上相反
#include <iostream>
using namespace std;
int main()
{
int n, i, j, k;
cin >> n;
n = n / 2 + 1;
for (i = 0; i < n; i++)
{
for (j = 1; j < n - i; j++)cout << " ";
for (k = 0; k <= 2 * i; k++)cout << '*';
putchar('\n');
}
for (i = 1; i < n; i++)
{
for (j = 0; j < i; j++)cout << " ";
for (k = 2 * (n - i - 1); k >= 0; k--)cout << '*';
cout << endl;
}
return 0;
}
*/
/*
//11姐妹数对
给定两个不同的正整数x,y,若x + y能被3除尽或能被7除尽,则称x,y为姐妹数对。例如: 2, 4;2, 5;为姐妹数对。 3, 14; 不是姐妹数对。 那么,对给出的一个整数n(1≤n≤1000), 1, 2,…,n之间有多少个姐妹数。
输入格式
一个整数n
输出格式
一个整数,即1~n之间姐妹数对的个数。
样例输入
6
样例输出
8
提示 / 说明
样例说明:1到6之间姐妹数对有 1, 2;1, 5;1, 6;2, 4;2, 5;3, 4;3, 6;4, 5;共8对。其中2, 4和4, 2被认为是相同的一个姐妹数对。
#include<iostream>
using namespace std;
int main()
{
int n, s = 0;
cin >> n;
for (int i = 1; i<n; i++)
for (int j = i + 1; j <= n; j++)
if ((i + j) % 3 == 0 || (i + j) % 7 == 0)s = s + 1;
cout << s;
return 0;
}
*/
/*
//11回文素数
题目描述
如果一个数从左边读和从右边读都是同一个数, 就称为回文数,既是素数又是回文数的数,称为回文素数。找出某个范围内的回文素数。
输入格式
整数m和n,2 = <m<n <= 106。
输出格式
m~n范围内的所有回文素数,从小大到排列,每行10个数。
样例输入
5 500
样例输出
5 7 11 101 131 151 181 191 313 353
373 383
#include<iostream>
using namespace std;
int huiwen(int n)
{
int x = 0;
int s = n;
while (s > 0)
{
x = x * 10 + s % 10;
s = s / 10;
}
if (x == n)return 1;
else return 0;
}
int sushu(int n)
{
int x = n;
int i;
for (i = 2; i <= n - 1; i++)
{
if (x%i == 0)return 0;
}
return 1;
}
int main()
{
int n, m;
cin >> n >> m;
int ans = 0;
for (int i = n; i <= m; i++)
{
if (huiwen(i) && sushu(i))cout << i << " ";
ans++;
if (ans % 10 == 0)cout << " ";
}
return 0;
}
*/