수조 연습 문제
138403 단어 배열
//
// main.m
//
//
// Created by zhangxueming on 14/12/26.
// Copyright (c) 2014 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
//
// main.c
//
//
// Created by zhangxueming on 14/12/24.
// Copyright (c) 2014 zhangxueming. All rights reserved.
//
#include <stdio.h>
//*****************************/
// */
// */
//*****************************/
#include <stdio.h>
//1. , , “123fdd” 3 。
//int main(int argc, const char * argv[]) {
// char str[100]={};
// int cnt=0;
// int len=0;//
// for (int i=0; i<100; i++) {
// str[i] = getchar();
// if (str[i]=='
') {
// str[i]='\0';// '\0'
// break;
// }
// cnt++;
// }
// for (int i=0; i<cnt; i++) {
// if ((str[i]>='A' && str[i]<='Z') || (str[i]>='a'&& str[i]<='z')) {
// len++;
// }
// }
// printf("len = %d
" , len);
// return 0;
//}
//3. 5 , ,
// , :{‘1’,’2’,’3’,’3’,’2’} 12332。
//#include <stdlib.h>
//#include <ctype.h>
//
//int main(int argc,const char *argv[])
//{
// //atoi("123")// "123" ==> 123
// //printf("%d
", atoi("-12345adc"));
// //printf("%d
",digittoint('9'));// 0~f --> 0 ~ 15
// char ch[5]={};
// int num=0;
// for (int i=0; i<5; i++) {
// ch[i]=getchar();
// ch[i]=ch[i]-48;
// num=num*10+ch[i];
// }
// printf("num = %d
", num);
// return 0;
//}
//5. , (
// )。
//int main(int argc,const char *argv[])
//{
// char ch[100]={};
// int cnt =0;
// for(int i=0; i<100; i++){
// ch[i]=getchar();
// if(ch[i]=='
')
// {
// ch[i]='\0';
// break;
// }
// cnt++;
// }
//
// for (int i=0; i<cnt; i++) {
// if (!(i%2) && (ch[i]>='a' && ch[i]<='z')) {
// ch[i]-=32;
// }
// printf("%c", ch[i]);
// }
// printf("
");
// return 0;
//}
//6. , , ‘Z’ ‘z’
// , ASCII 1 , ‘A’ ‘B’。‘Z’
// ‘z’ ‘A’ ‘a’。
//int main(int argc, const char *argv[])
//{
// char ch[100]={};
// int cnt=0;
// for (int i=0; i<100; i++) {
// ch[i]=getchar();
// if (ch[i]=='
') {
// ch[i]='\0';
// break;
// }
// cnt++;
// }
//
// for (int i=0; i<cnt; i++) {
// if ((ch[i]>='A' && ch[i]<'Z')||(ch[i]>='a'&&ch[i]<'z')) {
// ch[i]+=1;
// }
// else if(ch[i]=='Z')
// {
// ch[i] ='A';
// }
// else if(ch[i]=='z')
// {
// ch[i]='a';
// }
//
// printf("%c", ch[i]);
// }
// printf("
");
// return 0;
//}
//7. 、 ,
//1cm, 0.5cm、 0.8cm。
float lengthChar(char ch)
{
if ((ch>='A'&&ch<='Z') || (ch>='a'&&ch<='z')) {
return 1.0;
}
else if(ch>='0'&&ch<='9')
{
return 0.5;
}
else
{
return 0.8;
}
}
//int main(int argc,const char *argv[])
//{
// char ch[100]={};
// int cnt=0;
// float len=0;
// for ( int i=0; i<100; i++) {
// ch[i]=getchar();
// if (ch[i]=='
') {
// ch[i]='\0';
// break;
// }
// cnt++;
// }
// for (int i=0; i<cnt; i++) {
// len+=lengthChar(ch[i]);
// }
// printf("len = %.2f
", len);
//
// return 0;
//}
//8. , 10cm, 50 , 10cm 。 。
//1234asd!@#$rtyukl;fghjk
//int main(int argc,const char *argv[])
//{
// char ch[100]={};
// char str[100]={};
// int cnt=0;
// float len=0;
// for ( int i=0; i<100; i++) {
// ch[i]=getchar();
// if (ch[i]=='
') {
// ch[i]='\0';
// break;
// }
// cnt++;
// }
//
// for (int i=0; i<cnt; i++) {
// len+=lengthChar(ch[i]);
// if (len>10) {
//
// break;
// }
// str[i]=ch[i];
// printf("%c", str[i]);
// }
// printf("
");
// return 0;
//}
//9. , 。
//10. , , 3 1, 5
// 2, 7 3, 3、5、7 3
// 8, 0.
//int main(int argc,const char *argv[])
//{
// int a[100];
// for (int i=0; i<10; i++) {
// if (i%3==0) {
// a[i]=1;
// if (i%5==0||i%7==0) {
// a[i]=8;
// }
// }
// else if(i%5==0)
// {
// a[i]=2;
// if (i%7==0) {
// a[i]=8;
// }
// }
// else if(i%7==0)
// {
// a[i]=3;
// }
// else
// {
// a[i]=0;
// }
// printf("%d " ,a[i]);
// }
// printf("
");
// return 0;
//}
//11. 10 ,
// , ,
// 。
#include <stdio.h>
//int main(int argc,const char *argv[])
//{
// int a[10];
// for (int i=10-1; i>=0; i--) {
// scanf("%d", &a[i]);
// }
// for (int i=0; i<10; i++) {
// printf("%d ", a[i]);
// }
// printf("
");
// return 0;
//}
//13. 5 , 0-9 ,
// 5 , int a[5] = {1,2,2,3,7}; 73221。
//int main(int argc, const char *argv[])
//{
// int a[5];
// int num=0;
// for (int i=0; i<5; i++) {
// scanf("%d", &a[i]);
// }
// for (int i=4; i>=0; i--) {
// num = num*10+a[i];
// }
// printf("%d
", num);
// return 0;
//}
//17. 10 , 5 5 ,
//{1,1,1,1,1,2,3,2,2,2}->{2,3,2,2,2,1,1,1,1,1}。
//int main(int argc, const char *argv[])
//{
// int a[10];
// for (int i=0; i<10; i++) {
// scanf("%d", &a[i]);
// }
// for (int i=0; i<5; i++) {
// int temp = a[i];
// a[i]=a[i+5];
// a[i+5]=temp;
// }
// for (int i=0; i<10; i++) {
// printf("%d ", a[i]);
// }
// return 0;
//}
//18. , {1,2,3,3,2,1} {1,6,8,1,8,6,1} 。
//int main(int argc,const char *argv[])
//{
// int a[100]={};
// int cnt = 0;
// int flag =0;//
//
// for (int i=0; i<100; i++) {
// scanf("%d", &a[i]);
// cnt++;
// if (getchar()=='
') {
// break;
// }
// }
//
// for (int i=0; i<cnt/2; i++) {
// if (a[i]!=a[cnt-i-1]) {
// flag =1;
// }
// }
//
// if (flag) {
// printf("
");
// }
// else
// {
// printf("
");
// }
// return 0 ;
//}
//int main(int argc,const char *argv[])
//{
// int a[5];
// int b[5];
// for (int i=0; i<5; i++) {
// scanf("%d", &a[i]);
// }
// for (int i=0; i<5; i++) {
// scanf("%d", &b[i]);
// }
// for (int i=0; i<5; i++) {
// a[i]=b[i]=a[i]+b[i];
// printf("%d ", a[i]);
// }
// printf("
");
// return 0;
//}
//21. 10 , 9 , 5
// 88, 。
//int main(int argc, const char *argv[])
//{
// int a[10]={};
// for (int i=0; i<9; i++) {
// scanf("%d", &a[i]);
// }
//
// for (int j=8; j>=4; j--) {
// a[j+1]=a[j];
// }
// a[4]=88;
// for (int i=0; i<10; i++) {
// printf("%d ", a[i]);
// }
// return 0;
//}
//22. 10 , 2 , 。
//int main(int argc,const char *argv[])
//{
// int a[10]={};
// for (int i=0; i<10; i++) {
// scanf("%d", &a[i]);
// }
// for (int i=1; i<9; i++) {
// a[i]=a[i+1];
// }
// for (int i=0; i<9; i++) {
// printf("%d ",a[i]);
// }
// return 0;
//}
//25. , 。
//int main(int argc,const char *argv[])
//{
// int a[20];
// int cnt=0;
// int max;
// for (int i =0; i<20; i++) {
// scanf("%d", &a[i]);
// cnt++;
// if (getchar()=='
') {
// break;
// }
// }
// max=a[0];
// for (int i=1; i<cnt; i++) {
// if (a[i]>max) {
// max = a[i];
// }
// }
// int k=-1;//
// int temp=0;
// for (int i=0; i<cnt; i++) {// max temp
// if (a[i]==max) {
// continue;
// }
// temp = a[i];
// k=i;
// break;
// }
// if (k==-1) {//
// return -1;
// }
//
// for (int i=0; i<cnt; i++) {// ,
// if (max==a[i]) {
// continue;
// }
// if (temp<a[i]) {
// temp = a[i];
// k=i;
// }
// }
// printf("k =%d
", k);
// return 0;
//}
//30. , 1 , 2 。
//“Professor du comes from Korea” 10。
//int main(int argc,const char *argv[])
//{
// char str[100];
// int cnt=0;
// int index=0;
// for (int i=0; i<100; i++) {
// str[i]=getchar();
// if (str[i]=='
') {
// str[i]='\0';
// break;
// }
// cnt++;
// }
// for (int i=0; i<cnt; i++) {
// if (str[i]==' ') {
// index = i;
// break;
// }
// }
// printf("index = %d
", index+1);
// return 0 ;
//}
//32. , ( ),
// “abc” “123” “abc123”。
#include <string.h>
//int main(int argc,const char *argv[])
//{
// char str1[100]={};
// char str2[50]={};
// scanf("%s%s",str1,str2);
// int len1= (int)strlen(str1);// "qianfeng"
// int len2= (int)strlen(str2);
//
// for (int i=len1; i<len1+len2; i++) {
// str1[i]=str2[i-len1];
// }
// printf("%s
", str1);
// return 0 ;
//}
//34. , N(N>3), 3
// , 。
//12345
//
//int main(int argc,const char *argv[])
//{
// int a[100];
// int cnt = 0;
// int max;
// for (int i=0; i<100; i++) {
// scanf("%d", &a[i]);
// cnt++;
// if (getchar()=='
') {
// break;
// }
// }
// if (cnt<=3) {
// return -1;
// }
// max = a[0]+a[1]+a[2];
// int k=0;
// for (int i=1; i<cnt-2; i++) {
// if (max<a[i]+a[i+1]+a[i+2]) {
// max=a[i]+a[i+1]+a[i+2];
// k=i;
// }
// }
// printf("k = %d
", k);
//
// return 0 ;
//}
//35. , , “ ” ,“ ” , :a[0] 1112,b[0] 23, “ ”。
int sumBit(int num)
{
int sum=0;
while (num) {
sum+=num%10;
num/=10;
}
return sum;
}
//int main(int argc, const char *argv[])
//{
// int a[5];
// int b[5];
// for (int i=0; i<5; i++) {
// scanf("%d", &a[i]);
// }
// for (int i=0; i<5; i++) {
// scanf("%d", &b[i]);
// }
//
// for (int i=0; i<5; i++) {
// if (sumBit(a[i])!=sumBit(b[i])) {
// printf("
");
// return -1;
// }
// }
// printf("
");
// return 0;
//}
//36. , , ASCII , 。
//int main(int argc,const char *argv[])
//{
// char str1[100];
// char str2[100];
// scanf("%s%s",str1,str2);
// int sum1=0,sum2=0;
// int len1 = (int)strlen(str1);
// int len2 = (int)strlen(str2);
// for (int i=0; i<len1; i++) {
// sum1+=str1[i];
// }
// for (int i=0; i<len2; i++) {
// sum2+=str2[i];
// }
// if (sum1 < sum2) {
// printf("str1 < str2
");
// }
// else if(sum1 == sum2)
// {
// printf("str1 == str2
");
// }
// else
// {
// printf("str1 > str2
");
// }
//
// return 0;
//}
// ( "." ), ( , )。
//int main(int argc,const char *argv[])
//{
// //aaabbabbccccc
// //4004000050000
// //
// char str[100];
// int cnt[100];
// int len=0;
// for (int i=0; i<100; i++) {
// str[i]=getchar();
// if (str[i]=='.') {
// str[i]='\0';
// break;
// }
// len++;
// cnt[i]=1;
// }
// for (int i=0; i<len; i++) {
// if (cnt[i]!=0) {
// for (int j=i+1; j<len; j++) {
// if (cnt[j]!=0 && str[i]==str[j]) {
// cnt[i]++;
// cnt[j]=0;
// }
// }
// }
// }
//// for (int i=0; i<len; i++) {
//// printf("%d ", cnt[i]);
//// }
// for (int i=0; i<len; i++) {
// if (cnt[i]) {
// printf("char = %c cnt = %d
", str[i],cnt[i]);
// }
// }
//
// return 0;
//}
//41. n*n , :(****)
//1 2 3 4 1 5 3 4
//5 6 7 8 -> 2 6 2 7
//3 2 5 9 3 7 5 2
//4 7 2 3 4 8 9 3
//*/
//int main(int argc,const char *argv[]){
// int a[4][4]={{1,2,3,4},
// {5,6,7,8},
// {3,2,5,9},
// {4,7,2,3}};
//
// for (int i=0; i<4; i++) {
// for (int j=i; j<4; j++) {
// int temp=a[i][j];
// a[i][j]=a[j][i];
// a[j][i]=temp;
// }
// }
// for (int i=0; i<4; i++) {
// for (int j=0; j<4; j++) {
// printf("%4d",a[i][j]);
// }
// printf("
");
// }
// return 0;
//}
//3. , , ,
// :
// :1 5 9 8 12 21 3 0 -1 9
// :
//1 5 9
//9 8
//8 12 21
//21 3 0 -1
//-1 9
//
// : 3 9 8 -11 4 21 8 -3 0 2
// :
//3 9
//9 8 -11
//-11 4 21
//21 8 -3
//-3 0 2
//int main(int argc, const char *argv[])
//{
// int a[10];
// for (int i=0; i<10; i++) {
// scanf("%d", &a[i]);
// }
//
// printf("%d ", a[0]);
// for (int i=1; i<=8; i++) {
// printf("%d ",a[i]);
// if ((a[i]>a[i-1] && a[i]>a[i+1]) || (a[i]<a[i-1] && a[i]<a[i+1])) {
// printf("
%d ",a[i]);
// }
// }
// printf("%d
",a[9]);
//
// return 0;
//}
//1. m , , n, , 。( 1 )
// :
// :5 3
// :
//4
//
// : 6 2
// :
//5
//0 0 0 4 0
//
//int main(int argc, const char *argv[])
//{
// int a[100];
// int m, n;
// int cnt=0;//
// int k=0;
// int i;
// scanf("%d%d", &m,&n);
// if (m>100) {
// return -1;
// }
// for (i=0; i<m; i++) {
// a[i]=i+1;
// }
// i=0;
// while (cnt<m-1) {
// if (a[i]) {//
// k++;
// }
// if (k==n) {//
// k=0;
// a[i]=0;
// cnt++;
// }
// i++;
// if (i==m) {//
// i=0;
// }
// }
// i=0;
// while (!a[i++]);
//
// printf("%d
", a[i-1]);
//
// return 0;
//}
//2. , nXn , 1 ,
// :
// :5 18
// :p q
//1 2 3 4 5
//16 17 18 0 6
//15 0 0 0 7
//14 0 0 0 8
//13 12 11 10 9
//
// : 4 12
// :
//1 2 3 4
//12 0 0 5
//11 0 0 6
//10 9 8 7
//#define RIGHT 1
//#define DOWN 2
//#define LEFT 3
//#define UP 4
//
//int main(int argc, const char * argv[]) {
// int a[20][20]={};
// int n, m;
// scanf("%d%d", &n,&m);
// if (n<1||m<1||m>n*n||n>20) {
// return -1;
// }
// int type=RIGHT;//1: 2: 3: 4:
// int p=0,q=0;
// int s1=n-1;
// int s2=n-1;
// int s3=0;
// int s4=1;
// int i=1;
// while (i<=m) {
// a[p][q]=i;
// switch (type) {
// case RIGHT:
// if (++q==s1) {//
// type = DOWN;
// s1--;
// }
// break;
// case DOWN:
// if (++p==s2) {
// type = LEFT;
// s2--;
// }
// break;
// case LEFT:
// if (--q==s3) {
// type = UP;
// s3++;
// }
// break;
// case UP:
// if (--p==s4) {
// type=RIGHT;
// s4++;
// }
// break;
// default:
// break;
// }
// i++;
// }
//
// for (int i=0; i<n; i++) {
// for (int j=0; j<n; j++) {
// printf("%4d", a[i][j]);
// }
// printf("
");
// }
// return 0;
//}
//4.. 10 , ( , )
// :
// :1 2 2 3 4 5 6 7 8 9
// :2
// : int count[10] , 1
//
// :
//(1) , , , +1,
//(2) , , , , +1, 0,
//
// :
//
//
//
//
// , 0
// +1, 0
//
//
//a[10]
//1 2 2 3 4 3 4 5 8 5
//count[10]
//1 2 0 4 2 0 0 0 1 0
//
//int main(int argc,const char *argv[])
//{
// int a[10];
// int count[10];
// for (int i=0; i<10; i++) {
// scanf("%d", &a[i]);
// count[i]=1;
// }
//
// for (int i=0; i<10; i++) {
// if (count[i]) {
// for (int j=i+1; j<10; j++) {
// if (a[j]==a[i]) {
// count[i]++;
// count[j]=0;
// }
// }
// }
// }
//// for (int i=0; i<10; i++) {
//// printf("%d ", count[i]);
//// }
// //
// int max = count[0];
// for (int i=0; i<10; i++) {
// if (max<count[i]) {
// max=count[i];
// }
// }
// // cnt
// for (int i=0; i<10; i++) {
// if (max==count[i]) {
// printf("%d ", a[i]);
// }
// }
// printf("
");
// return 0;
//}
//5. , m*m 1~m^2 (m ), 、 、 。 m, m*m 。
// :
// :3
// :
//6 1 8 i=0 i=n-1 j--
//7 5 3 j=n-1 j=0 i--
//2 9 4 i++;
//(1) 1 ;
//(2) 2 n×n ; 1, 1/ 1( ,5 4 );
//(3) 1, n( ); 1 , 2 , 1;
//(4) 1 , n, 1。 2 3 , 3 ;
//(5) , n , 。 ,4 1 2 , , 4 3 ;
//int main(int argc,const char *argv[])
//{
// int a[19][19]={};
// int n;
// scanf("%d", &n);
// if (!(n%2) || n>19 || n<3) {
// return -1;
// }
// int k=1;
// int i=0,j=n/2;
// int tempi,tempj;//
// while (k<=n*n) {
// a[i][j]=k;
// tempi =i;
// tempj =j;
// i--;
// j--;
// if (tempi==0) {
// i=n-1;
// }
// if (tempj==0) {
// j=n-1;
// }
// if (a[i][j]) {
// i=tempi+1;
// j=tempj;
// }
// k++;
// }
//
// for (i=0; i<n; i++) {
// for (j=0; j<n; j++) {
// printf("%4d", a[i][j]);
// }
// printf("
");
// }
// return 0;
//}
//
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
/*int main(int argc,const char *argv[])
{
//void srand(unsigned);
//int rand(void);
while (1) {
//
//time_t time(time_t *);
//time(NULL)
//srand((unsigned)time(NULL));//
int num = rand()%101;
printf("num = %d
" , num);
sleep(1);
//usleep(1000);
}
// int a[100];
// srand((unsigned)time(NULL));
// for (int i=0; i<50; i++) {
// a[i]=rand()%100;
// }
// for (int i=0; i<50; i++) {
// printf("%d ", a[i]);
// }
return 0;
}
*/
//atoi
// , , , main 。
// :
// :134a231b
// :134
// :-129cde
// :-129
/*#include <stdlib.h>
int myatoi(char *src)
{
char *pstr=src;
int num=0;
int flag=1;
while (*pstr==' ') {
pstr++;
}
if (*pstr=='+') {
pstr++;
}
else if (*pstr=='-') {
flag=-flag;
pstr++;
}
while (*pstr>='0' && *pstr<='9') {
num =num*10+(*pstr-48);
pstr++;
}
num*=flag;
return num;
}
int main(int argc, const char * argv[]) {
printf("%d
", myatoi("123abe"));
return 0;
}*/
// , 10 , 0 , 0 ( ), main 。
// :
// : 5 9 -1 0 2 8 0 3 7 0
//5 9 -1 2 8 0 3 7 4 0
// : 5 9 -1 2 8 3 7 4 0 0
//void func(int *arr, int len)
//{
// //int *p = arr;
// int cnt = 0;// 0
// for (int i=0; i<len-cnt-1; i++) {
// if (*(arr+i)==0) {
// for (int j=i; j<len-cnt-1; j++) {
// *(arr+j) = *(arr+j+1);
// }
// *(arr+len-cnt-1)=0;
// cnt++;
// i--;
// }
// }
//}
//void func(int *arr, int len)
//{
// int *p = arr;
// int cnt = 0;// 0
// for (int i=0; i<len-cnt-1; i++) {
// if (!(*p)) {
// for (int j=0; j<len-cnt-1-i; j++) {
// *(p+j) = *(p+j+1);
// }
// *(p+len-cnt-i-1)=0;
// cnt++;
// p--;
// i--;
// }
// p++;
// }
//}
//
//int main(int argc,const char *argv[])
//{
// int a[10]={5,0,-1,0,2,8,0,3,7,0};
// func(a, 10);
// for (int i=0; i<10; i++) {
// printf("%d ", a[i]);
// }
// printf("
");
// return 0;
//}
//*****************************************/
//
//*****************************************/
// : sscanf sprintf , ,
#include <string.h>
// , , 。
// :
// :
//abcdfewabcssaba
//abc
// :2
//int main(int argc, const char *argv[])
//{
// char *str1="abcdfewabcssaba";
// char *str2="abc";
// int cnt = 0;
// char *pstr=str1;
//
// while ((pstr = strstr(pstr, str2))) {
// cnt++;
// pstr+=strlen(str2);
// }
// printf("cnt = %d
", cnt);
//
// return 0;
//}
// 2 1
// :
//
//asdfwd
//df
//
//3
//
//
//hhff
//hf
//
//2
#include <stdlib.h>
#include <string.h>
/*
int main(int argc, const char * argv[]) {
char *str = (char *)malloc(100*sizeof(char));
char *substr = (char *)malloc(100*sizeof(char));
if (!str || !substr) {
return -1;
}
scanf("%s%s", str,substr);
int index=0;
char *pstr = strstr(str,substr);
if (pstr) {
index = (int)(pstr-str+1);
}
printf("%d
", index);
return 0;
}*/
//int main(int argc,const char *argv[])
//{
// char *str = (char *)malloc(100*sizeof(char));
// if (!str) {
// return -1;
// }
//
// //
//// gets(str);
//// printf("%s
", str);
// //
// //scanf("%[^
]",str);
// scanf("%[A-Z,a-z,0-9]",str);// A-Z
// printf("%s
", str);
// return 0;
//}
//int main(int argc,const char *argv[])
//{
//// char str[100]={};
//// scanf("%s", str);
//// char ch;
//// //fflush(stdin);
//// getchar();
//// scanf("%c", &ch);
//// if (ch =='
') {
//// printf("hello world
");
//// }
//// printf("%s %c
", str,ch);
//
// char ch1 ;
// ch1 = getchar();
// printf("%c
", ch1);
//
// return 0;
//}
// 2 1
// :
//
//asdfdfdfwd
//df
//
//3 5 7
//
//
//hhfhf
//hf
//
//2
//4
//int searchStringIndex(char *src, char *substr, int *index)
//{
// int count = 0;
// int len = (int)strlen(substr);
// char *pstr = src;
// while ((pstr = strstr(pstr, substr))) {
// index[count++] = (int)(pstr-src)+1;
// pstr+=len;
// }
// return count;
//}
//int main(int argc,const char *argv[])
//{
// char *str = malloc(100*sizeof(char));
// char *substr = malloc(100*sizeof(char));
// int index[100]={};
// if (!str || !substr) {
// exit(-1);
// }
// scanf("%s %s", str,substr);
//
// int cnt = searchStringIndex(str,substr,index);
//
// for (int i=0; i<cnt; i++) {
// printf("%d ", index[i]);
// }
// printf("
");
//
// return 0;
//}
//int main(int argc,const char *argv[])
//{
// int len = (int)strlen(NULL);// NULL
// printf("len = %d
", len);
// return 0;
//}
// 。 :“eeeeeaaaff" "e5a3f2"。
// , s res
//
// :
//
//aaaaeefggg
//
//a4e2f1g3
//
//
//hhfhhhhff
//
//h2f1h4h2
//char * compress(char *src, char *buf)
//{
// char *pstr = src;
// int cnt = 1;
// char *pbuf = buf;
// while (*pstr) {
// if (*pstr == *(pstr+1)) {
// cnt++;
// }
// else
// {
// pbuf += sprintf(pbuf,"%c%d", *pstr,cnt);
// cnt = 1;
// }
// pstr++;
// }
// return buf;
//}
//
//int main(int argc,const char *argv[])
//{
// char str[100]={};
// char buf[200]={};
// scanf("%s",str);
//
// printf("%s
", compress(str, buf));
// return 0;
//}
//int main(int argc,const char *argv[])
//{
// int a=100;
// char *str = "hello world";
// float f = 3.14;
//
// char buf[100]={};
// int len = sprintf(buf, "%f",f);
// printf("%s
", buf);
// printf("len = %d
", len);
//
// return 0;
//}
// 。 :"e5a3f2" “eeeeeaaaff"。
// , s res
//
// :
//
//a14e2f1g3
//
//aaaaeefggg
//
//
//h2f1h4h2
//
//hhfhhhhff
//#include <ctype.h>
//
//int main(int argc,const char *argv[])
//{
// char str[100]={};
// char buf[1000]={};
//
// char ch;
// int cnt=0;
// scanf("%s", str);
//
// char *pbuf = buf;
// char *pstr = str;
// while (*pstr) {
// sscanf(pstr,"%c%d",&ch,&cnt);
// memset(pbuf, ch, cnt);
// pbuf+=cnt;
// pstr++;
// while (isdigit(*pstr)) {
// pstr++;
// }
// }
// printf("%s
",buf);
//
// return 0;
//}
// s 。
//
//
// :
//
//f123fffwf3256789:abcd
//
//123
//
//
//abcd345bbw1357f123
//
//123
//#include <ctype.h>
//
//int main(int argc,const char *argv[])
//{
// char str[100]={};
// scanf("%s", str);
// char *pstr = str;
// int max=0;
// char *pmax = NULL;
// int cnt=0;
// while (*pstr) {
// if (isdigit(*pstr)) {
// cnt = 1;
// while ((*pstr == *(pstr+1)-1) && (*pstr!='9')) {
// cnt++;
// pstr++;
// }
// pstr++;
// if (max < cnt) {
// max = cnt;
// cnt = 0;
// pmax = pstr-max;
// }
// }
// else
// {
// pstr++;
// }
// }
// if (pmax) {
// *(pmax+max)='\0';
// printf("%s
", pmax);
// }
// return 0;
//}
// 。 , 。
// :
//
//asdfwd
//ddrwf
//ffweff
//
//asdfwd
//ddrwf
//ffweff
//
//
//sgfgeasdfw
//aabbe
//wrwwdfaf
//
//aabbe
//sgfgeasdfw
//wrwwdfaf
/*
int main(int argc, const char *argv[])
{
char *pstr[20]={NULL};
int cnt = 0;
for (int i=0; i<20; i++) {
pstr[i] = calloc(100, sizeof(char));
if (pstr[i]) {
scanf("%s", pstr[i]);
cnt++;
}
if (getchar() == '
') {
break;
}
}
//
for (int i=0; i<cnt-1; i++) {
for (int j=0; j<cnt-i-1; j++) {
if (strcmp(pstr[j], pstr[j+1])>0) {
char *ptemp = pstr[j];
pstr[j]= pstr[j+1];
pstr[j+1] = ptemp;
}
}
}
for (int i=0; i<cnt; i++) {
printf("%s
", pstr[i]);
free(pstr[i]);
pstr[i]=NULL;
}
return 0;
}
*/
//memmem()
//void *memmem(const void *srcmem, size_t size1, const void *submem, size_t size2)
//srcmem:
//size1:
//submem:
//size2:
void *my_memmem(const void *srcmem,size_t len1,const void *submem,size_t len2)
{
char *psrc = (char *)srcmem;
for (int i=0; i<len1; i++) {
char *ptmp = psrc;
char *psub = (char *)submem;
int j=0;
while (*psrc == *psub) {
psrc++;
psub++;
j++;
if (j==len2) {
return ptmp;
}
}
psrc = ptmp+1;
}
return NULL;
}
//int main(int argc,const char *argv[])
//{
// char srcmem[100]="hello world qian feng";
// char submem[20]="world";
// printf("%s
", my_memmem(srcmem, 100, submem, 6));
//
// return 0;
//}
// ( 1 ),
//
//
// :
//
//adbAFEHHFS
//acwfagAFEf
//
//AFE
//
//
//qfdgJKlin
//qdfgJKwfo
//
//gJK
/*
int main(int argc,const char *argv[])
{
char str1[100]={};
char str2[100]={};
scanf("%s%s", str1,str2);
int len1 = (int)strlen(str1);
int len2 = (int)strlen(str2);
char *pstr = str2;
char *ptmp=NULL;
for (int i=0; i<len2-1; i++) {
if ((ptmp = (char *)my_memmem(str1, len1, pstr, 2))) {
//printf("%s
",ptmp);
int j=2;
while (*(ptmp+j) == *(pstr+j)) {
j++;
}
*(ptmp+j)='\0';
printf("%s
",ptmp);
break;
}
pstr++;
}
return 0;
}*/
//
// , ,
//
//
/*
#include <math.h>
int compare_int(void *a, void *b)
{
return *(int *)a-*(int *)b;
}
int compare_float(void *a, void *b)
{
if (fabs(*(float *)a-*(float *)b)<0.00005) {
return 0;
}
else if(*(float *)a>*(float *)b)
{
return 1;
}
else
{
return -1;
}
}
int compare_char(void *ch1, void *ch2)
{
return *(char *)ch1-*(char *)ch2;
}
//7 6 4 5 3
//
//6 7 4 5 3
//6 4 7 5 3
//6 4 5 7 3
//6 4 5 3 7
//
//4 6 5 3 7
//4 5 6 3 7
//4 5 3 6 7
void sort_data(int (*pfunc)(void *, void *), void *pdata,size_t len,size_t size)
{
char *p_i = (char *)pdata;
for (int i=0; i<len-1; i++) {
for (int j=0; j<len-i-1; j++) {
if (pfunc(p_i+j*size, p_i+(j+1)*size) > 0)
{
char temp[size];
memcpy(temp, p_i+j*size, size);
memcpy(p_i+j*size, p_i+(j+1)*size, size);
memcpy(p_i+(j+1)*size, temp, size);
}
}
}
}
int main(int argc,const char *argv[])
{
// int a[10]={7,6,4,5,3};
// sort_data(compare_int, a, 5, sizeof(int));
// for (int i=0; i<5; i++) {
// printf("%d ", a[i]);
// }
// float a[10]={7.8,6.7,4.3,5.2,3.0};
// sort_data(compare_float, a, 5, sizeof(float));
// for (int i=0; i<5; i++) {
// printf("%.2f ", a[i]);
// }
char a[10]="hello";
sort_data(compare_char, a, 5, sizeof(char));
for (int i=0; i<5; i++) {
printf("%c ", a[i]);
}
return 0;
}*/
// ,
//
// demo
//1,3,3,3,4,4,4,4,4,0,0,0,4,4,4,4
//, 5 4 , 44444.
//1,3,3,3,4,4,4,4,4,0,0,0,5,5,5,5 44444;
//1,3,3,3,5,5,5,5,5,4,4,4,4,4,0,0,0,0,0,0,4,4,4,4}, 000000;
//int main(int argc, const char * argv[]) {
// @autoreleasepool {
// char str[100]={};
// scanf("%s", str);
// char *pstr = str;
// while (*pstr) {
// if (*pstr == ',') {
// int len = (int)strlen(pstr+1);
// memmove(pstr, pstr+1, len);
// *(pstr+len)='\0';
// pstr--;
// }
// pstr++;
// }
// //printf("%s
", str);
// pstr = str;
// int cnt = 1;
// int max =0;
// char *pmax = NULL;
// while (*pstr) {
// while(*pstr == *(pstr+1)) {
// cnt++;
// pstr++;
// }
// if (cnt>max) {
// max = cnt;
// pmax = pstr-cnt+1;
// }
// cnt = 1;
// pstr++;
// }
// *(pmax+max) = '\0';
// printf("%s
", pmax);
// }
// return 0;
//}
// ( 10 ), , , ;
// :
// :
//I am Optimus Prime!
//:
//
//I:am:Optimus:Prime!
// :
//Hi welcome to qianfeng
//#@
//
//Hi#@welcome#@to#@qianfeng
//
//abc def ghi jkl heihei haha mygod
//**
//
//abc**def**ghi**jkl**heihei**haha**mygod
//int main(int argc,const char *argv[])
//{
// char *pstr[10]={NULL};
// char demi[10]={};
// char *pbuf = (char *)malloc(1000*sizeof(char));
// int cnt = 0;
// for (int i=0; i<10; i++) {
// pstr[i]=(char *)malloc(100*sizeof(char));
// scanf("%s", pstr[i]);
// cnt++;
// if (getchar() =='
') {
// break;
// }
// }
// scanf("%s", demi);
// char *p = pbuf;
// int length =(int)strlen(demi);
// for (int i=0; i<cnt; i++) {
// strcat(p, pstr[i]);
// p+=(int)strlen(pstr[i]);
// if (i<cnt-1) {
// strcat(p, demi);
// p+=length;
// }
// }
// printf("%s
", pbuf);
//
// return 0;
//}
// , , 。
// :
// :
//I:am:Optimus:Prime!
//:
// :
//I
//am
//Optimus
//Prime!
// :
//Hi#@welcome#@to#@qianfeng#@
//#@
//int main(int argc, const char *argv[])
//{
// char str[100]={};
// char substr[10]={};
// scanf("%s%s", str,substr);
// char *p,*q;
// p = q = str;
// int len = (int)strlen(substr);
// while ((p = strstr(p, substr))) {
// *p = '\0';
// printf("%s
",q);
// p += len;
// q = p;
// }
// if(*q!='\0')
// {
// printf("%s
", q);
// }
//
// return 0;
//} 이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
PHP 배열에서 요소의 값이 최대 값인 키 이름을 가져옵니다.Qiita 에 " "@ PHP 매뉴얼 데이터 최대값이 나타나는 순서대로 획득 결과 키를 정렬한 후 가져오기 결과 @ paiza.IO PHP v5.6.40, v7.1.33, v7.4.4 " "@ StackOverflo...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.