1.阶乘数。输入一个正整数,输出时,先输出这个数本身,跟着一个逗号,再输出这个数的各位数字的阶乘和,等号,阶乘和的计算结果,并判断阶乘和是否等于原数,如果相等输出Yes,否则输出No。各数字均不会超出INT的范围
输出
145,1!+4!+5!=145
Yes
输入 1400
输出
1400,1!+4!+0!+0!=27
No
#include "stdafx.h"
#include <iostream>
#include <string>
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int jiecheng(int n){
int result=1;
for(int i=n;i>0;i--)
result*=i;
return result;
}
int main(int argc, char* argv[])
{
int n,n1;
int num[100];
int m=0;
int sum=0;
scanf("%d",&n);
n1=n;
while(n1!=0){
num[m++]=n1%10;
n1/=10;
}
printf("%d,",n);
for(int i=m-1;i>0;i--){
printf("%d!+",num[i]);
sum+=jiecheng(num[i]);
}
printf("%d!=",num[0]);
sum+=jiecheng(num[0]);
printf("%d\n",sum);
if(sum==n) printf("yes");
else printf("no");
return 0;
}
2.五子棋。输入一个19*19的矩阵,只包含数字0、1、2,表示两人下五子棋的棋牌状态,1、2分别表示两人的棋子,0表示空格。要求判断当前状态下是否有人获胜(横向、竖向或者斜线方向连成5个同色棋子)。题目说明输入样例保证每条线上至多只有连线5个同色棋子,并且保证至多只有1人获胜。如果有人获胜,输出获胜者1或2,加一个冒号,接着输出获胜的五连珠的第一个棋子的坐标,从上到下从左到右序号最小的为第一个,序号从1开始编号。如果无人获胜,输出No。
输入
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0
输出 No
#include "stdafx.h"
#include <iostream>
#include <string>
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int panduan(int qipan[19][19],int &rx,int &ry){
int result=0;
int t;
for(int i=0;i<19;i++){
for(int j=0;j<19;j++){
if(qipan[i][j]!=0){
t=qipan[i][j];
if(j<19-4){
if(t==qipan[i][j+1]&&t==qipan[i][j+2]&&t==qipan[i][j+3]&&t==qipan[i][j+4])
{
rx=i;
ry=j;
return qipan[i][j];
}
}
if(i<19-4){
if(t==qipan[i+1][j]&&t==qipan[i+2][j]&&t==qipan[i+3][j]&&t==qipan[i+4][j])
{
rx=i;
ry=j;
return qipan[i][j];
}
}
if(i<19-4&&j<19-4){
if(t==qipan[i+1][j+1]&&t==qipan[i+2][j+2]&&t==qipan[i+3][j+3]&&t==qipan[i+4][j+4])
{
rx=i;
ry=j;
return qipan[i][j];
}
}
if(i<19-4&&j>3){
if(t==qipan[i+1][j-1]&&t==qipan[i+2][j-2]&&t==qipan[i+3][j-3]&&t==qipan[i+4][j-4])
{
rx=i;
ry=j;
return qipan[i][j];
}
}
}
}
}
return 0;
}
int main(int argc, char* argv[])
{
int qipan[19][19];
int i,j;
for(i=0;i<19;i++)
for(j=0;j<19;j++)
scanf("%d",&qipan[i][j]);
int result=panduan(qipan,i,j);
if(result==0)printf("no");
else {
printf("%d:(%d,%d)",result,i,j);
}
return 0;
}
3.排版题。输入若干行字符,表示某电影的演职员表,每行只有一个冒号,冒号前面是职位,冒号后面是姓名,要求把各行冒号对齐,删除多余空格后输出。先输入一个数字,表示排版要求的冒号位置,该位置号保证比各行冒号前的最大字符数还要大。再输入若干行字符,最多50行,每行最多100个字符,除空格、制表符和回车之外都是有效字符,要求每行的冒号处于格式要求的位置,冒号两边与有效单词之间各有一个空格,冒号前面的单词之间只有一个空格(删除多余的空格和制表符),在冒号左边右对齐,前面全由空格填充,冒号后面的单词之间也只有一个空格,在冒号右边左对齐,最后一个单词后不加空格直接换行。
#include "stdafx.h"
#include <iostream>
#include <string>
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
int mao=50;
char c;
char s[50][100];
int maoindex[50];
int si=0,i=0,spaceflag=0;
scanf("%d",&mao);
getchar();
while((c=getchar())!=EOF){
if(c==' ') {
if(spaceflag==1||i==0) continue;
spaceflag=1;
}
if(c=='\n') {
if(spaceflag==0){
s[si++][i]=0;
i=0;
//printf("%s",s[si-1]);
continue;
}else{
s[si++][i-1]=0;
i=0;
//printf("%s",s[si-1]);
continue;
}
}
if(c==':') {
if(spaceflag==0){
s[si][i++]=' ';
}
maoindex[si]=i;
}
s[si][i++]=c;
if(c==':') {
s[si][i++]=' ';
}
if(c!=' ') {
spaceflag=0;
}
}
for(int j=0;j<si;j++){
for(int k=0;k<mao-maoindex[j];k++){
printf(" ");
}
printf("%s\n",s[j]);
}
return 0;
}