65,211
社区成员
发帖
与我相关
我的任务
分享
#include <conio.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
int main()
{
int i=0/*1初始化i,否则不能直接a[i]访问*/,s,t,j,p;
char a[1000];
cout <<"请输入一篇文章" <<endl;
gets(a);
puts(a);
// if(a[i]>='a'&&a[i]>='A'&&a[i] <='z'&&a[i] <='Z')//确定第一个字符是否为标点
if (a[i]>='a'&&a[i]<='z'|| a[i]>='A'&&a[i] <='Z')//2判断分小写和大写
i=0;
else
i=1;
t=i;//第一个单词起始位置
s=0;
// cout <<t <<endl;
for(;i<=strlen(a);i++)
{
if(a[i]>'z'&&a[i]>'Z'||a[i] <'a'&&a[i] <'A')//确定一个单词结束 /*3和2同样的问题*/
{
s=s+1;
j=i;//记录结束时位置
}
else continue;//未遇到空格或标点(单词没结束)进入下一次循环
for(p=t;p <j;p++)//输出刚确定的单词
{
cout <<a[p];
}
t=j+1;//下一个单词的起始位置
cout <<endl;
}
// if(a[i-1]>='a'&&a[i-1] <='z'||a[i-1]>='A'&&a[i-1] <='Z') //这句注释掉后如果最后一个标点多于1个就会出现问题
cout <<"共有" <<s-1 <<"个单词" <<endl;
return 0;
}
#include <stdio.h>
// // #include<conio.h>
// #include <windows.h>
#include <iostream.h>
// #include <string>
//
// #define Step 10 //空间增加的步长.
//
// char * getstr() //任意长度的字符串输入,返回字符串的首地址.
// {
// char *temp, *str=(char *)malloc(10);
// int c=0, len=0, times=1, number=0;
// if(!str)
// {
// printf("内存不够,无法开辟字符串空间!");
// return (char *)NULL;
// }
// number+=times*Step;
// while((c=getche())!='\r') //遇到回车则输入结束。
// {
// if(len==number)
// {
// times++;
// number=times*Step;
// temp=str;
// str=(char *)realloc(str,number);
// if(str==NULL)
// {
// printf("内存不够,字符串输入受限!");
// str=temp;
// break;
// }
// }
// *(str+len)=c;
// len++;
// }
// str=(char *)realloc(str,len+1); //字符串的实际长短调整空间.
// *(str+len)='\0';
// return str;
// }
//
// int main()
// {
// char *str=NULL;
// str=getstr(); //字符串输入
// printf("\nstr=%s\n",str);
// free(str);
// return 0;
// }
// #include <iostream>
// #include <list>
// using namespace std;
// class Person
// {
// public:
// char*name;
// int gender;
// };
//
// class Student:public Person
// {
// public:
// int grade;
// Student(char *Name,int Gender,int Grade)
// {
// name=Name;
// gender=Gender;
// grade=Grade;
// }
// };
//
// class Teacher:public Person
// {
// public:
// Teacher(char *n,int g)
// {
// name=n;
// gender=g;
// }
// public:
// list <Student> student;
// };
//
// class Printer
// {
// public:
// void printStudent(Student s)
// {
// cout <<"student:" <<endl;
// cout <<"\t Name:" <<s.name <<endl;
// if(s.gender==0)
// cout <<"\t Gender:" <<"female" <<endl;
// else
// cout <<"\t Gender:" <<"male" <<endl;
// cout <<"\t Grade:" <<s.grade <<endl;
// }
// void printTeacher(Teacher s)
// {
// cout <<"Teacher:" <<endl;
// cout <<"\t Name:" <<s.name <<endl;
// if(s.gender==0)
// cout <<"\t Gender:" <<"female" <<endl;
// else
// cout <<"\t Gender:" <<"male" <<endl;
// }
// };
//
// int main()
// {
// Teacher teacher("Johnny",1);
// Student student1("Catherine",0,1);
// Student student2("peter",1,2);
//
// teacher.student.push_back(student1); //从后面向list容器中添加数据
//
// teacher.student.push_back(student2);
//
// student1.grade=2;
// student2.grade=3;
//
// Printer printer;
// printer.printTeacher(teacher);
// list <Student>::iterator itr=teacher.student.begin();
// for(;itr!=teacher.student.end();itr++)
// {
// printer.printStudent(*itr);
// }
// return 0;
// }
// #include <iostream.h>
//
// void jiaohuan(int x,int y)
// {
// int temp;
// temp=x;
// x=y;
// y=temp;
// cout<<x<<'\t'<<y<<endl;
// }
//
// void zhizhen(int *x,int *y)
// {
// int temp;
// temp=*x;
// *x=*y;
// *y=temp;
// cout<<*x<<'\t'<<*y<<endl;
// }
//
// void shengming(int &x,int &y)
// {
// int temp;
// temp=x;
// x=y;
// y=temp;
// cout<<x<<'\t'<<y<<endl;
// }
//
// void shuzu(int a[],int b[])
// {
// int temp[1];
// temp=a;
// a=b;
// b=temp;
// cout<<a[0]<<'\t'<<b[0]<<endl;
// }
// void main()
// {
// int a=5,b=6;
// jiaohuan(a,b);
// cout<<a<<'\t'<<b<<endl;
// zhizhen(&a,&b);
// cout<<a<<'\t'<<b<<endl;
// shengming(a,b);
// cout<<a<<'\t'<<b<<endl;
// int c[1],d[1];
// c[0]=5;d[0]=6;
// shuzu(c,d);
// cout<<c[0]<<'\t'<<d[0]<<endl;
// }
// #include <iostream>
//
// int ma(int);
//
// int main()
// {
// using namespace std;
// int lang;
//
// cout <<"Enter a namber for lang:_____\b\b\b\b";
// cin>>lang;
// cout <<lang <<" lang is" <<ma(lang) <<"ma\n";
// return 1;
// }
// int ma(int l)
// {
// using namespace std;
// // int l;
// int m;
// m=l*200;
// return m;
// }
// union
// {
// int i;
// char x[2];
// }a;
// #include <cstringt.h>
// void main()
// {
// unsigned int j;
// unsigned char mil=0x00,cs[6];
// float md,x=x=1095216660480.0;
//
// md=123.386;
// if(md==x)
// cs[0]=cs[1]=cs[2]=cs[3]=cs[4]=cs[5]=0xff;
// else
// {
// for(;md<x;)
// {
// md=md*2;
// mil++;
// }
// md=md/2;
// mil--;
// cs[5]=mil;
// j=(int)(md /(65536.0*65536.0));
// cs[0]=0x80&j;
// md=md-j*65536.0*65536.0;
// j=(int)(md/(256.0*65536.0));
// cs[1]=j;
// md=md-j*256.0*65536.0;
// j=(int)(md/65536.0);
// cs[2]=j;
// md=md-j*65536.0;
// j=(int)(md /256.0);
// cs[3]=j;
// md=md-j/256.0;
// j=(int)md;
// cs[4]=j;
// }
// printf("123.386的十六进制表示为");
// printf("%x%x%x%x%x%x%x%x%x%x",cs[0]/16,cs[0]%16,cs[1]/16,cs[1]%16,cs[2]/16,cs[2]%16,cs[3]/16,cs[3]%16/16,cs[4],cs[4]%16);
// printf("小数位数为%x%x",cs[5]/16,cs[5]%16);
// }
// #include <iostream>
// using namespace std;
//
// void main(void)
// {
// enum egg {a,b,c};
// egg test; //在这里你可以简写成egg test;
// test = c;
// cout<<test;
//
// }
#include <windows.h>
#include <iostream.h>
// DWORD WINAPI ThreadProc1(
// LPVOID lpParameter // thread data
// );
// HANDLE h_thread1;
// void main()
// {
//
// h_thread1=CreateThread(NULL,0,ThreadProc1,NULL,0,NULL);
// CloseHandle(h_thread1);
// }
//
// DWORD WINAPI ThreadProc1(
// LPVOID lpParameter // thread data
// )
// {
// WaitForSingleObject(h_thread1,INFINITE);
// cout<<"lihaia";
// return 0;
#include <conio.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
int main()
{
int i=0/*1初始化i,否则不能直接a[i]访问*/,s,t,j,p;
char a[1000];
cout <<"请输入一篇文章" <<endl;
gets(a);
puts(a);
// if(a[i]>='a'&&a[i]>='A'&&a[i] <='z'&&a[i] <='Z')//确定第一个字符是否为标点
if (a[i]>='a'&&a[i]<='z'|| a[i]>='A'&&a[i] <='Z')//2判断分小写和大写
i=0;
else
i=1;
t=i;//第一个单词起始位置
s=0;
// cout <<t <<endl;
for(;i<=strlen(a);i++)
{
if(a[i]>'z'&&a[i]>'Z'||a[i] <'a'&&a[i] <'A')//确定一个单词结束 /*3和2同样的问题*/
{
s=s+1;
j=i;//记录结束时位置
}
else continue;//未遇到空格或标点(单词没结束)进入下一次循环
for(p=t;p <j;p++)//输出刚确定的单词
{
cout <<a[p];
}
t=j+1;//下一个单词的起始位置
cout <<endl;
}
// if(a[i-1]>='a'&&a[i-1] <='z'||a[i-1]>='A'&&a[i-1] <='Z') //这句注释掉后如果最后一个标点多于1个就会出现问题
cout <<"共有" <<s-1 <<"个单词" <<endl;
return 0;
}
string fuck = "Fuck lady, lady fuck. Oh my fuck god! Give me a fuck!";
string[] Fuck = fuck.Split ( new char [] { ' ', ',', '.', '!' } );
Fuck.Length 就是单词的个数。