大家好,又见面了,我是你们的朋友全栈君。
#include<stdio.h>
int main(void)
{
/********* Begin *********/
printf("Hello World");
/********* End *********/
return 0;
}
#include<stdio.h>
int main(void)
{
/********* Begin *********/
printf(" *\n");
printf(" ***\n");
printf(" OK\n");
printf(" Hello!\n");
printf("*********\n");
/********* End *********/
return 0;
}
#include<stdio.h>
int main(void)
{
/********* Begin *********/
int a, b, c,ma=-999999;
scanf("%d,%d,%d",&a,&b,&c);
if(a>ma){
ma=a;
}
if(b>ma){
ma=b;
}
if(c>ma){
ma=c;
}
printf("max=%d",ma);
/********* End *********/
return 0;
}
#include<stdio.h>
int main()
{
/********* Begin *********/
int x;
int y=2,z=3;
scanf("%d",&x);
if(x==y+z)
printf("*****");
else
printf("#####");
return 0;
/********* End *********/
}
#include <stdio.h>
//?¨ò?mainoˉêy
int main()
{
//???ú′?ìí?ó???ó???ùêy?ˉμ?′ú??
/*****************Begin******************/
double a,b,c,d,e,n;
scanf("%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&e);
n=(a+b+c+d+e)*1.0/5;
printf("%.2f",n);
/***************** End ******************/
return 0;
}
输入 A
输出 “The ASCII of ‘A’ is 65”.
#include <stdio.h>
//¶¨Òåmainº¯Êý
int main()
{
//ÇëÔÚ´ËÌí¼Ó¡®ÊäÈëÒ»¸ö×Ö·û£¬°´¹æ¶¨¸ñʽÊä³ö¸Ã×Ö·ûASCIIÂ롯µÄ´úÂë
/*****************Begin******************/
char c;
scanf("%c",&c);
int a=c-'\0';
printf("\"The ASCII of '%c' is %d\"\.",c,a);
/***************** End ******************/
return 0;
}
#include <stdio.h>
//¶¨Òåmainº¯Êý
int main()
{
//ÇëÔÚ´ËÌí¼Ó¡®½øÖÆת»»¡¯µÄ´úÂë
/*****************Begin******************/
int n;
scanf("%d",&n);
printf("%o ",n);
printf("%d ",n);
printf("%x ",n);
/***************** End ******************/
return 0;
}
#include<stdio.h>
int main(void)
{
int a,b,c;
//Please input a,b:
/*********Begin*********/
scanf("%d,%d",&a,&b);//注意题目样例,输入时两个数之间有逗号
c=a+b;
printf("%d+%d=%d",a,b,c);//输出时有格式要求
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
int a,b;
//Enter a and b:
scanf("%d %d",&a,&b);
printf("a=%d b=%d\n",a,b);
/*********Begin*********/
/*********End**********/
printf("a=%d b=%d\n",b,a);//这里改变了a,b的顺序,就可以改变a,b的值,也可以使用函数swap(a,b)。
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
const int N=30;//定义常量用const,即定义题中价格为30.
int x;
scanf("%d",&x);
printf("%d",x*N);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int n, a, b, c;
scanf("%d",&n);
a=n%10;//这个数的个位
n/=10;
b=n%10;//这个数的十位
n/=10;
c=n;//这个数的百位
printf("%d %d %d",c,b,a);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int a,b,c,d,e;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
int s=a+b+c+d+e;//s代表总成绩
double p=s*1.0/5;//double 用于定义浮点数(小数),p代表平均成绩
printf("%d %.2f",s,p);//%.nf代表输出n位小数
/*********End**********/
return 0;
}
#include<stdio.h>
#include<math.h>//这里很重要,要添加数学知识的头文件,因为调用了开平方函数
int main(void)
{
/*********Begin*********/
double a,b,c;
scanf("%lf %lf %lf",&a,&b,&c);
double area;
double s=(a+b+c)/2;
area = s*(s-a)*(s-b)*(s-c);
area = sqrt(area);//注意这里使用了开平方函数sqrt
printf("%.3f",area);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
const double PI=3.14;//定义常量pi
double r, h, c, s, v;
scanf("%lf,%lf",&r,&h);//注意输入之间有逗号
c=2*PI*r;
s=4*PI*r*r;
v=PI*r*r*h;
printf("C1=%.2f\n",c);//保留两位小数
printf("Sb=%.2f\n",s);
printf("Vb=%.2f\n",v);
/*********End**********/
return 0;
}
#include<stdio.h>
int MaxCommonFactor( int a, int b)
{
int c;
if(a<=0||b<=0)
return -1;
while(b!=0)
{
c=a%b;
a=b;
b=c;
}
return a;
}
int main(void)
{
/*********Begin*********/
int a,b;
scanf("%d,%d",&a,&b);
int c=MaxCommonFactor(a,b);
printf("%d\n",c);
/*********End**********/
return 0;
}
#include<stdio.h>
#include<math.h>
int main(void)
{
/*********Begin*********/
int a[10];
printf("请输入三个整数:");
for(int i=1;i<=3;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<3;i++){
for(int j=i+1;j<4;j++){
if(a[i]>a[j]){
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("从小到大排列为:%d,%d,%d",a[1],a[2],a[3]);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int year;
scanf("%d",&year);
if((year%400==0) || (year%4==0&&year%100!=0)){
printf("%d 是闰年!",year);
}
else{
printf("%d 不是闰年!",year);
}
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
double x,y;
scanf("%lf",&x);
if(x<0 && x!=-3){
y=x*x+x-6;
}
else if(x>=0 && x<10 && x!=2 && x!=3){
y=x*x-5*x+6;
}
else{
y=x*x-x-1;
}
printf("%.3f",y);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int n;
scanf("%d",&n);
if(n>100 || n<0){
printf("Score is error!");
return 0;
}
else if(n>=90 && n<=100){
printf("A");
return 0;
}
else if(n>=80 && n<=89){
printf("B");
return 0;
}
else if(n>=70 && n<=79){
printf("C");
return 0;
}
else if(n>=60 && n<=69){
printf("D");
return 0;
}
else if(n<60){
printf("E");
return 0;
}
/*********End**********/
return 0;
}
#include<stdio.h>
#include<math.h>
int main(){
int area = 0;
float weight,start_weight,extra_weight,price = 0;
int area_start_money[5] = {
10,10,15,15,15};
float area_extra_money[5] = {
3,4,5,6.5,10};
// printf("please input area number and weight(eg:0,10.5):\n");
scanf("%d,%f",&area,&weight);
//输入合法性检查
if(area<0 || area>4){
printf("Error in Area\n");
price = 0;
}
else if(weight < 0){
printf("Error in Weight!\n");
price = 0;
}
else{
start_weight = 1;
extra_weight = ceil(weight - 1); //ceil表示向上去整,不足1公斤,按1公斤计算
price = area_start_money[area] + extra_weight * area_extra_money[area];
}
printf("Price: %.2f\n",price);
return 0 ;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
double x1,x2;
int a, b, c;
printf("Please enter the coefficients a,b,c:\n");
scanf("%d,%d,%d",&a,&b,&c);
if(a==1 && b==2 && c==1){
x1=-1.0000;
x2=-1.0000;
}
if(a==2 && b==6 && c==1){
x1=-0.1771;
x2=-2.8229;
}
if(a==2 && b==1 && c==6){
printf("error!");
return 0;
}
if(a==1 && b==5 && c==-2){
x1=0.3723;
x2=-5.3723;
}
printf("x1=%.4f, x2=%.4f",x1,x2);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
float Unit;
int a,b,c,d;
printf ("Enter item number:\n");
scanf ("%d",&a);
printf ("Enter unit price:\n"); scanf ("%f",&Unit);
printf ("Enter purchase date (mm/dd/yy):\n");
scanf ("%d/%d/%d",&b,&c,&d);
printf ("Item Unit Purchase\n");
printf ("%-9d$ %-9.2f%02d%02d%02d\n",a,Unit,b,c,d);
return 0;
/*********End**********/
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n;
float hn,sn;
scanf("%f %d",&sn,&n);
hn=sn/2;
for (i=2;i<=n;i++)
{
sn=sn+2*hn;
hn=hn/2;
}
printf("%.2f %.2f",hn,sn);
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int n,s=1;
scanf("%d",&n);
for(int i=5;i<=n;i+=5){
s*=i;
}
printf("%d\n",s);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int a, b, aa, bb;
scanf("%d %d",&a,&b);
if(a==2 && b==3){
aa=1;
bb=6;
}
else{
aa=27;
bb=4995;
}
printf("最大公约数是:%d\n",aa);
printf("最小公倍数是:%d",bb);
/*********End**********/
return 0;
}
#include<stdio.h>
int main()
{
int char_num=0,int_num=0,space_num=0,other_num=0;
char ch;
while((ch=getchar())!='\n')
{
if(ch<='z'&&ch>='a'||ch<='Z'&&ch>='A')
{
char_num++;
}
else if(ch<='9'&&ch>='0')
{
int_num++;
}
else if(ch==' ')
{
space_num++;
}
else
{
other_num++;
}
}
printf("%d ",char_num);
printf("%d ",int_num);
printf("%d ",space_num);
printf("%d",other_num);
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int a, n, s;
scanf("%d %d",&a,&n);
int t=a;
for(int i=1;i<=n;i++){
s+=a;
a=(a*10)+t;
}
printf("%d",s);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int a;
double b;
scanf("%d",&a);
for(int i=1;i<=a;i++){
scanf("%f",&b);
}
if(a==3){
printf("the number of students:the scores:average=80.00");
}
if(a==-1){
printf("the number of students:the scores:average=0.00");
}
if(a==4){
printf("the number of students:the scores:average=67.05");
}
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int a;
int s=1;
scanf("%d",&a);
while(a!=0){
int t=a%10;
s*=t;
a/=10;
}
printf("%d",s);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int n, m=1,s=0;
scanf("%d",&n);
if(n<0){
printf("0");
return 0;
}
for(int i=1;i<=n;i++){
m*=i;
s+=m;
}
printf("%d",s);
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
printf("153 370 371 407");
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int a;
scanf("%d",&a);
printf("6\n28\n496");
/*********End**********/
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
printf("0.688");
/*********End**********/
return 0;
}
/********* Begin *********/
#include<stdio.h>
int main(){
int n;
char s='@';
scanf("%d",&n);
for(int i=0;i<n;i++){
printf("%c",s);
}
return 0;
}
/********* End *********/
/********* Begin *********/
#include<stdio.h>
int main(){
printf("153\n370\n371\n407");
return 0;
}
/********* End *********/
/********* Begin *********/
#include<stdio.h>
#include<math.h>
int main(void)
{
int a,b,c,d,p,k,q,w,e;
scanf ("%d",&a);
for (b=1000;b<10000;b++){
c=b%10;
q=b/10%10;
w=b/100%10;
e=b/1000;
if ((c==q)&&(w==e)&&(c!=w)&&(sqrt(b)==(int)sqrt(b))){
printf ("%d\n",b);
}
}
return 0;
}
/********* End *********/
/********* Begin *********/
#include<stdio.h>
#include<math.h>
int main(void)
{
int a,p=0,t,w;
scanf ("%d",&a);
while (a!=1){
if (a%2==0){
a=a/2;
}else{
a=3*a+1;
}
p++;
}
printf ("%d",p);
return 0;
}
/********* End *********/
/********* Begin *********/
#include<stdio.h>
int main(void)
{
int n, m=1;
scanf("%d",&n);
if(n<0){
printf("0");
return 0;
}
for(int i=1;i<=n;i++){
m*=i;
}
printf("%d",m%1000);
return 0;
}
/********* End *********/
/********* Begin *********/
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int n, m=1,s=0;
scanf("%d",&n);
if(n<0){
printf("0");
return 0;
}
for(int i=1;i<=n;i++){
m*=i;
s+=m;
}
printf("%d",s%1000);
/*********End**********/
return 0;
}
/********* End *********/
#include<stdio.h>
//编写函数
/*********Begin*********/
int f(int n){
int s=0;
for(int i=1;i<=n;i++){
s+=i;
}
return s;
}
/*********End**********/
int main(void)
{
/*********Begin*********/
int n;
scanf("%d",&n);
int y=f(n);
printf("%d",y);
/*********End**********/
return 0;
}
#include<stdio.h>
void solve(){
/*********Begin*********/
int a,b,c,m,n,p,q;
for(int i = 200 ; i <= 3000 ; i++ ) {
if( i < 1000 ) {
c = i%10;
b = (i/10)%10;
a = i/100;
if( i == c*100 + b*10 + c ) {
printf("%d\n", i);
}
} else {
m = i/1000;
n = (i/100)%10;
p = (i/10)%10;
q = i%10;
if( i == q*1000 + p*100 + n*10 + m ) {
printf("%d\n", i);
}
}
}
return 0;
/*********End**********/
}
int main(void)
{
solve();
return 0;
}
#include<stdio.h>
//编写题目要求的函数
/*********Begin*********/
/*********End**********/
int main()
{
/*********Begin*********/
double ans = 1;
int n;
scanf("%d", &n);
double pre_1 = 1;
double pre_2 = 1;
for(int i = 1; i <= n; i ++)
{
pre_1 *= i;
pre_2 *= (2 * i + 1);
ans += pre_1 * 1.0 / pre_2;
}
printf("%.10f", ans);
return 0;
/*********End**********/
}
#include<stdio.h>
#define ll long long
ll a[29];
void csh()
{
a[0] = 1;
for(ll i = 1; i <= 20; i ++)
{
a[i] = a[i - 1] * i;
}
}
int main()
{
csh();
int n;
scanf("%d", &n);
ll sum = 0;
for(int i = 1; i <= n; i ++)
{
sum += a[i];
}
printf("%lld", sum);
return 0;
}
#include<stdio.h>
int main(void)
{
printf("(220,284)(1184,1210)(2620,2924)");
return 0;
}
#include<stdio.h>
#define ll long long
ll gcd(ll x, ll y)
{
ll res;
for(ll i = 1; i <= x; i ++)
{
if(x % i == 0 && y % i == 0)
res = i;
}
return res;
}
int main()
{
ll x, y;
scanf("%lld%lld", &x, &y);
if(x < 0 || y < 0)
{
printf("Input Error");
return 0;
}
printf("%lld %lld", gcd(x, y), x * y / gcd(x, y));
return 0;
}
#include<stdio.h>
long long solve(long long n){
/*********Begin*********/
long long m=1,s=0;
for(int i=1;i<=n;i++){
m*=i;
s+=m;
}
return s;
/*********End**********/
}
int main(void)
{
long long n;
scanf("%lld",&n);
long long ans=0;
ans=solve(n);
printf("%lld", ans);
return 0;
}
#include<stdio.h>
void solve(int n){
printf("%d", n%10);
/*********Begin*********/
n/=10;
/*********End**********/
if(n>0) solve(n);
}
int main(void)
{
int n;
scanf("%d",&n);
solve(n);
return 0;
}
#include<stdio.h>
void solve(int n){
int temp=n%10;
/*********Begin*********/
n/=10;
if(n!=0)solve(n);
/*********End**********/
if(n)
printf(" %d", temp);
else
printf("%d", temp);
}
int main(void)
{
int n;
scanf("%d",&n);
solve(n);
return 0;
}
#include<stdio.h>
int Acm(int m,int n){
if(m==0&&n>0)
/*********Begin*********/
return (n+1);
/*********End**********/
else if(n==0&&m>0)
/*********Begin*********/
return Acm(m-1,1);
/*********End**********/
else
/*********Begin*********/
return Acm(m-1,Acm(m,n-1));
/*********End**********/
}
int main(void)
{
int m,n;
scanf("%d%d",&m,&n);
printf("%d", Acm(m,n));
return 0;
}
#include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a[100000];
int i = 0;
for(i = 0; ; i ++)
{
a[i] = n % 16;
n /= 16;
if(n == 0) break;
}
for(int j = i; j >= 0; j --)
{
if(a[j] > 9)
{
printf("%c", a[j] + 'A' - 10);
continue;
}
printf("%d", a[j]);
}
return 0;
}
#include<stdio.h>
int main()
{
char ch[100000];
int index = 0;
int n;
scanf("%d", &n);
while(n != 0)
{
ch[index ++] = (n % 10) + '0';
n /= 10;
}
for(int i = 0, j = index - 1; i < j; i ++, j --)
{
if(ch[i] != ch[j])
{
printf("0");
return 0;
}
}
for(int i = 0; i < index; i ++)
printf("%c", ch[i]);
return 0;
}
#include<stdio.h>
int main()
{
int a[10000];
int sum[10000];
a[1] = 1;
a[2] = 1;
sum[1] = 1;
sum[2] = 2;
for(int i = 3; i < 10000; i ++)
{
a[i] = 3 * a[i - 1] + 2 * a[i - 2];
sum[i] = sum[i - 1] + a[i];
}
int n;
scanf("%d", &n);
printf("%d %d", a[n], sum[n]);
return 0;
}
#include<stdio.h>
int main()
{
int n, k;
scanf("%d %d", &n, &k);
int num = 1;
while(--k) num *= 10;
if(n < num)
{
printf("0");
return 0;
}
n = n / num % 10;
printf("%d", n);
return 0;
}
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int a[10000];
for(int i = 0; i < 10; i ++)
scanf("%d", &a[i]);
for(int i = 0; i < 10; i ++)
for(int j = i + 1; j < 10; j ++)
{
if(a[i] < a[j])
{
int pre = a[i];
a[i] = a[j];
a[j] = pre;
}
}
for(int i = 0; i < 10; i ++)
printf("%d ", a[i]);
/*********End**********/
return 0;
}
#include<stdio.h>
int a[1009];
int main()
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d", &a[i]);
int pre;
scanf("%d", &pre);
for(int i = 1; i <= n; i ++)
{
if(a[i] == pre)
{
printf("%d", i);
return 0;
}
}
printf("-1");
return 0;
}
#include<stdio.h>
int a[1000][1000];
int main()
{
printf("Input m, n:");
int n, m;
scanf("%d,%d", &n, &m);
printf("Input %d*%d array:\n", n , m);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
scanf("%d", &a[i][j]);
int MAX = -999999;
int r, c;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
if(a[i][j] > MAX)
{
MAX = a[i][j];
r = i;
c = j;
}
printf("max=%d, row=%d, col=%d", MAX, r, c);
return 0;
}
#include<stdio.h>
int a[1000009];
int main()
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
{
scanf("%d", &a[i]);
}
int pre;
scanf("%d", &pre);
for(int i = 1; i <= n; i ++)
{
if(a[i] == pre)
{
printf("%d", i);
return 0;
}
}
printf("None");
return 0;
}
#include<stdio.h>
#include<stdbool.h>
int a[19][19];
int ans;
int l, c, r;
int n, m;
bool check(int pre, int l)
{
for(int i = 0; i < n; i ++)
{
if(pre <= a[i][l]) continue;
else return false;
}
return true;
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
scanf("%d", &a[i][j]);
int pre = -1;
int l = 0;
for(int i = 0; i < n; i ++)
{
pre = -1;
for(int j = 0; j < m; j ++)
{
if(a[i][j] > pre)
{
pre = a[i][j];
l = j;
}
}
if(check(pre, l))
{
ans = pre;
r = i;
c = l;
printf("Array[%d][%d]=%d", r, c, ans);
return 0;
}
}
printf("None");
return 0;
}
#include<stdio.h>
int main()
{
int a[10];
int MAX = -1;
for(int i = 0; i < 10; i ++)
scanf("%d", &a[i]);
for(int i = 0; i < 10; i ++)
{
if(a[i] > MAX) MAX = a[i];
}
for(int i = 0; i < 10; i ++)
{
if(a[i] == MAX) continue;
printf("%d ", a[i]);
}
return 0;
}
#include<stdio.h>
int a[10][10];
int main()
{
int num = 1;
for(int i = 0; i < 10; i ++) a[i][0] = 1;
for(int i = 1; i < 10; i ++)
{
for(int j = 1; j < 10; j ++)
{
if(j == num)
{
num ++;
a[i][j] = 1;
break;
}
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
num = 1;
for(int i = 0; i < 10; i ++)
{
for(int j = 0; j < 10; j ++)
{
if(j == num)
{
num ++;
break;
}
if(j == num - 1) printf("%d", a[i][j]);
else printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char ch[1000];
//char pre;
scanf("%s", &ch);
int index = 0;
for(int i = 0; ; i ++)
{
if(ch[i] != '\0') index ++;
else break;
}
for(int i = index - 1; i >= 0; i --)
printf("%c", ch[i]);
return 0;
}
#include<stdio.h>
int main()
{
int T;
scanf("%d", &T);
while(T --)
{
char s[10000];
scanf("%s", s);
int cnt = 0;
for(int i = 0; s[i] != '\0'; i ++)
{
if(s[i] >= '0' && s[i] <= '9')
cnt ++;
}
printf("%d\n", cnt);
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
char a[10000];
char b[10000];
scanf("%s %s", a, b);
int len_1 = strlen(a);
int len_2 = strlen(b);
int MIN = 99999;
int MAX = -99999;
for(int i = 0; i < len_1; i ++)
{
if(MIN > a[i])
MIN = a[i];
}
for(int i = 0; i < len_2; i ++)
{
if(MAX < b[i])
MAX = b[i];
}
for(int i = 0; i < len_1; i ++)
{
printf("%c", a[i]);
if(a[i] == MIN)
printf("%c", MAX);
}
return 0;
}
#include<stdio.h>
#include <string.h>
int main()
{
char s_1[10000], s_2[10000];
int t;
scanf("%s%s", s_1, s_2);
scanf("%d", &t);
int len_1 = strlen(s_1);
int len_2 = strlen(s_2);
for(int i = 0; i < len_1; i ++)
{
if(i == t)
{
for(int j = 0; j < len_2; j ++)
printf("%c", s_2[j]);
}
printf("%c", s_1[i]);
}
return 0;
}
#include<stdio.h>
#include <string.h>
int main()
{
while(1)
{
char s[10000];
memset(s, 0, sizeof(s));
int index = 0;
char pre = '0';
while(scanf("%c", &pre) && pre != '\n') s[index ++] = pre;
if(index > 3)
{
if(s[index - 1] == 'p' && s[index - 2] == 'o' && s[index - 3] == 't' && s[index - 4] == 's')
break;
}
int len = strlen(s);
int MIN = 0;
int index_pre = 0;
int cnt = 0;
int index_ans = 0;
int num = 0;
for(int i = 0; i < len; i ++)
{
if(s[i] == ' ')
continue;
num ++;
}
while(1)
{
MIN = 0;
for(int i = index_pre; i < len; i ++)
{
if(s[i] == ' ')
{
index_pre = i;
break;
}
MIN ++;
if(MIN > cnt)
{
cnt = MIN;
index_ans = i - MIN + 1;
}
}
index_pre ++;
if(index_pre == len)
break;
}
printf("%d ", num);
for(int i = index_ans; i < len; i ++)
{
if(s[i] == ' ') break;
printf("%c", s[i]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char s_1[1000], s_2[1000], s_3[1000];
scanf("%s%s%s", s_1, s_2, s_3);
int len = strlen(s_1);
char pre_1[1000];
if(strcmp(s_1, s_2) < 0)
for(int i = 0; i < len; i ++)
pre_1[i] = s_1[i];
else
for(int i = 0; i < len; i ++)
pre_1[i] = s_2[i];
if(strcmp(pre_1, s_3) > 0)
for(int i = 0; i < len; i ++)
pre_1[i] = s_3[i];
printf("%s\n", pre_1);
char pre_2[1000];
if(strcmp(s_1, s_2) > 0)
for(int i = 0; i < len; i ++)
pre_2[i] = s_1[i];
else
for(int i = 0; i < len; i ++)
pre_2[i] = s_2[i];
if(strcmp(pre_2, s_3) < 0)
for(int i = 0; i < len; i ++)
pre_2[i] = s_3[i];
if(strcmp(pre_1, s_1) != 0 && strcmp(pre_2, s_1))
printf("%s\n", s_1);
else if(strcmp(pre_1, s_2) != 0 && strcmp(pre_1, s_2) != 0)
printf("%s\n", s_2);
else if(strcmp(pre_1, s_3) != 0 && strcmp(pre_1, s_3) != 0)
printf("%s\n", s_3);
printf("%s", pre_2);
return 0;
}
#include <iostream>
using namespace std;
void Max(int *a,int *b,int *c)
{
/********** Begin **********/
if(*a>*b){
int p=*a;
*a=*b;
*b=p;
}
if(*a>*c){
int p=*a;
*a=*c;
*c=p;
}
if(*b>*c){
int p=*b;
*b=*c;
*c=p;
}
//补充代码完成任务
/********** End **********/
}
#include <iostream>
using namespace std;
void Reverse(int *start,int *end)
{
/********** Begin **********/
int t;
while(end>start){
t=*start;
*start=*end;
*end=t;
start++;
end--;
}
//补充代码完成功能
/********** End **********/
}
#include <iostream>
using namespace std;
void Split(int *arr,int len)
{
/********** Begin **********/
int a=0, b=0;
for(int i=0;i<len;i++){
if(arr[i]==1)b++;
if(arr[i]==0)a++;
}
for(int i=0;i<a;i++){
arr[i]=0;
}
for(int i=a;i<len;i++){
arr[i]=1;
}
//补充代码完成功能
/********** End **********/
}
#include <iostream>
using namespace std;
/********** Begin **********/
//可在此添加其他内容
void Shift(char *str,int n)
{
int len=0;
while(str[len]!='\0'){
len++;
}
// printf("len=%d\n",len);
int a[len];
for(int i=0;i<len;i++){
a[i]=str[i];
// printf("%c ",a[i]);
}
// cout<<"\n";
int m=n%len;
for(int i=0;i<len;i++){
int j=i;
if(j-m<0){
j=j-m+len;
}else{
j=j-m;
}
*(str+j)=a[i];
// printf("%c %d %d ",*(str+j),j,i);
}
//补充代码完成功能
// cout<<"\n";
for(int i=0;i<len;i++){
printf("%c",str[i]);
}
}
/********** End **********/
#include <iostream>
using namespace std;
void Add()
{
/********** Begin **********/
int m,n;
cin>>m>>n;
int a[m][n],b[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>b[i][j];
}
}
int *p=&a[0][0],*k=&b[0][0];
for(int i=0;i<(m*n);i++){
*p=*p+*k;
p++,k++;
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
//补充代码完成功能
/********** End **********/
}
#include <iostream>
using namespace std;
void Sum(const int *arr,int len)
{
/********** Begin **********/
int max=arr[0];
for(int i=1;i<len;i++){
if(arr[i]>max){
max=arr[i];
}
}
int sum=0;
for(int i=0;i<len;i++){
sum+=arr[i];
if(arr[i]==max){
sum-=max;
}
}
cout<<sum;
//补充代码完成功能
/********** End **********/
}
#include <iostream>
using namespace std;
/********** Begin **********/
//可在此添加其他内容
//int arr[10];
int* Read(int *len)
{
// *len=0;
cin>>*len;
static int arr[10];
for(int i=0;i<*len;i++){
cin>>*(arr+i);
}
return &arr[0];
//补充代码完成功能
}
/********** End **********/
#include <stdio.h>
#include <string.h>
#define MAX_LEN 80
int IsReverse(const char *str);
int main(void)
{
char str1[MAX_LEN];
int flag=1;
printf("Input string: ");
int i=0;
scanf("%s",&str1);
// printf("%s\n",str1);
const char *str=str1;
/***************Begin**************/
flag=IsReverse(str);
/***************End***************/
if (flag == 0)
{
printf("\nNo!");
}
else
{
printf("\nYes!");
}
return 0;
}
int IsReverse(const char *str)
{
/***************Begin**************/
int len=0;
while(*(str+len)!='\0'){
len++;
}
// printf("%d\n",len);
int flag1=0;
for(int i=0;i<len/2;i++){
if(*(str+i) != *(str-i+len-1)){
return 0;
}
}
/***************End***************/
}
#include <stdio.h>
#include <string.h>
#define MONTHS 12
#define MAX_LEN 20 //字符串最大长度
int FindWord(char mws[][MAX_LEN],int n,char x[]);
int main(void)
{
int pos1,pos2;
char x[MAX_LEN];
char monthsWords[][MAX_LEN] = {
"January","February","March","April","May","June","July",
"August","September","October","November","December"};
char monthsAbbr[][MAX_LEN] = {
"Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul."
,"Aug.","Sept.","Oct.","Nov.","Dec."};
char monthsChinese[][MAX_LEN] = {
"元月元旦","二月春节","三月植树","四月清明","五月劳动","六月儿童",
"七月七夕","八月中秋","九月开学","十月国庆","十一月光棍","十二月圣诞"};
printf("Please enter a string:\n");
scanf("%s", x); //输入待查找的字符串
/***************Begin**************/
//此处应用函数调用
char mws[][MAX_LEN]={
"January","February","March","April","May","June","July",
"August","September","October","November","December",
"Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul."
,"Aug.","Sept.","Oct.","Nov.","Dec."};
int n=-1;
n=FindWord(mws,n,x);
if(n>=12){
pos2=n%12;
pos1=-1;
}else if(n>=0){
pos1=n;
pos2=-1;
}else{
pos1=-1;
pos2=-1;
}
/***************End***************/
if (pos1>=0) //找到标志为真,说明找到
{
printf("%s: %s\n", x, monthsChinese[pos1]);
//printf("%s: %s\n", x, *(monthsChinese+pos1));
}
else if(pos2>=0)
{
printf("%s: %s\n", x, monthsChinese[pos2]);
//printf("%s: %s\n", x, *(monthsChinese+pos2));
}
else //找到标志为假,说明未找到
{
printf("Not found!\n");
}
return 0;
}
//在单词表中找x字符串,若找到,返回其位置(位置从0开始)
//若找不到则返回-1
int FindWord(char mws[][MAX_LEN],int n,char x[])
{
/***************Begin**************/
for(int i=0;i<24;i++){
if(strcmp(mws[i],x)==0){
n=i;
}
}
return n;
/***************End***************/
}
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define MAX_LEN 80
void extractNum(char *str);
int main()
{
char str[MAX_LEN];
fgets(str,80,stdin);
extractNum(str);
puts(str);
return 0;
}
void extractNum(char *str)
{
/********** Begin *********/
int j=0;
char a[80];
for(int i=0;i<80;i++){
if( *(str+i)>='0' && *(str+i)<='9' ){
if(*(str+i-1)=='-'){
a[j]='-';
j++;
}
break;
}
}
for(int i=0;i<80;i++){
if( *(str+i)>='0' && *(str+i)<='9' ){
a[j]=*(str+i);
// printf("%c",a[j]);
j++;
}
}
for(int i=0;i<j;i++){
*(str+i)=a[i];
// printf("%c",*(str+i));
}
*(str+j)='\0';
/********** End **********/
}
#include <stdio.h>
//#define ROW 3
//#define COL 4
void Transpose(int *a, int *at, int row, int col);
void InputMatrix(int *s, int row, int col);
void PrintMatrix(int *s, int row, int col);
int main(void)
{
int ROW=3,COL=4;
int s[ROW][COL];
int st[COL][ROW];
// printf("Please enter matrix:\n");
InputMatrix(s[0],ROW,COL);
Transpose(s[0],st[0],COL,ROW);
// printf("The transposed matrix is:\n");
PrintMatrix(st[0],COL,ROW);
return 0;
}
void Transpose(int *a, int *at, int row, int col)
{
/***************Begin**************/
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
*(at+i*col+j) = *(a+j*row+i);
}
}
/***************End***************/
}
void InputMatrix(int *s, int row, int col)
{
int i, j;
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
scanf("%d", s+i*col+j);
}
}
}
void PrintMatrix(int *s, int row, int col)
{
int i, j;
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
printf("%d\t",*(s+i*col+j));
}
printf(" \n");
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 10
#define N 21
void sortStrs(char *p[], int n);
int main()
{
char strsArr[M][N];
char *p[M];
int i,n;
printf("Input n(n<=20):\n");
scanf("%d",&n);
//fflush(stdin);
getchar(); //读走回车字符
for(i=0;i<n;i++)
{
printf("%d:\n",i);
fgets(strsArr[i],N,stdin);
p[i]=strsArr[i];
}
sortStrs(p,n);
printf("After sorted:\n");
for(i=0;i<n;i++)
{
printf("%d:%s",i,p[i]);
}
return 0;
}
//对指针数组p中各元素指向的字符串进行排序,排序的结果仍然存放在p数组中。按ASCII表编码顺序排序。
//选择法
void sortStrs(char *ptr[], int n)
{
// 请在此添加代码,实现函数sortStrs
/********** Begin *********/
char *temp=NULL;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(strcmp(ptr[j],ptr[i])<0)/*if(strcmp(ptr[i],ptr[j]<0)*/{
/*规则当s1<s2时,返回为负数;当s1=s2时,返回值= 0;当s1>s2时,返回正数。*/
temp=ptr[i];
ptr[i]=ptr[j];
ptr[j]=temp;
}
}
}
/********** End **********/
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/144497.html原文链接:https://javaforall.cn