int main(void)
{
int s=1
char c,t
for (c=getchar(),t=getchar()c!='\n't=getchar() ) {
if (c==t)
{
s++
}
else {
printf("%d%c",s,c)
s=1
}
c=t
}
return 0
}
#include <stdio.h>#include <stdlib.h>
#include <memory.h>
#include <string.h>
#define MAXLINE 1024
#define DIM ","
typedef struct STRLINK
{
int v
int t
struct STRLINK *next
} LINK
static LINK *head = NULL
static int freelink()
{
LINK *tmp = NULL
if (head==NULL) return 0
while (head->next) {
tmp = head->next
free(head)
head = tmp
}
free(head)
return 0
}
static int inode(int v)
{
LINK *tmp, *newlink
tmp = head
newlink = (LINK*)malloc(sizeof(LINK))
if (newlink==NULL) return -1
newlink->v = v
newlink->t = 1
newlink->next = NULL
if (tmp==NULL) {
head = newlink
return 0
}
while (tmp->next!=NULL) {
if (tmp->v==v) {
tmp->t++
return 0
}
tmp = tmp->next
}
if (tmp->v==v) {
tmp->t++
return 0
} else {
tmp->next = newlink
return 0
}
}
static int prt2file(FILE *fout, int linenum)
{
LINK *tmp = head
if (head==NULL) return 0
while (tmp->next) {
fprintf(fout, "(%d,%d,%d),", tmp->v, tmp->t, linenum)
tmp = tmp->next
}
fprintf(fout, "(%d,%d,%d)\n", tmp->v, tmp->t, linenum)
return 0
}
int main(int argc, char *argv[])
{
FILE *fin, *fout
char line[MAXLINE+1], *str
int linenum, v
if (argc!=3) {
printf("USAGE: %s 输入文件 输出文件\n", argv[0])
}
fin = fopen(argv[1], "r")
if (fin==NULL) {
printf("input file[%s] can not open!\n", argv[1])
return -1
}
fout = fopen(argv[2], "a+")
if (fout==NULL) {
printf("output file[%s] can not open!\n", argv[2])
fclose(fin)
return -1
}
/*
fin = fopen("in.txt", "r")
fout = fopen("out.txt", "a+")
*/
memset(line, 0, sizeof(line))
linenum = 0
while (fgets(line, MAXLINE, fin)!=NULL) {
++linenum
freelink()
str = strtok(line, DIM)
if (str==NULL) break
v = atoi(str)
inode(v)
while((str=strtok(NULL, DIM))!=NULL)
{
v = atoi(str)
inode(v)
}
prt2file(fout, linenum)
}
fclose(fin)
fclose(fout)
return 0
}
#include<iostream>#include <stdio.h>
using namespace std
main(){
char c
char x
int n=0
printf("please input aaabbcd\n")
c = getchar()n=1
while(1){
x=getchar()
if (x=='\n'){ printf("%d%c",n,c)break}
if (x==c) n++else { printf("%d%c",n,c)c=xn=1}
}
输入aaabb 输出 3a2b
输入aaabbcd 输出 3a2b1c1d
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)