标签:水题
第一次是直接建一个10^7的数组 结果 内存大的要死!!
是不是可以不建数组 这下好了
1 9 1 1 1 2 3 3 3 3 3
3 1 1 2 5 3
第一次的代码:
<span style="font-family:Consolas, Courier New, DejaVu Sans Mono, Droid Sans Mono, monospace;color:#464646;"><span style="font-size: 14px; line-height: 1.5em;"> </span></span><pre name="code" class="cpp">#include<stdio.h> int a[10000005]; int main() { int t, n, i, count; scanf( "%d", &t ); while( t -- ) { count = 1; scanf( "%d", &n ); for( i = 0; i < n; i ++ ) scanf( "%d", &a[i] ); for( i = 1; i < n; i ++ ) { if( a[i]==a[i-1] ) ++count; else { printf( "%d %d ", count, a[i-1] ); count = 1; } } if( a[n-1] == a[n-2] ) printf( "%d %d\n", count, a[n-1] ); else printf( "1 %d\n", a[n-1] ); } }
第二次的<pre name="code" class="cpp"> #include<stdio.h> int main() { int n, t, a, b, c, i; scanf( "%d", &t ); while( t -- ) { scanf( "%d", &n ); scanf( "%d", &a ); c = 1; for( i = 1; i < n; i ++ ) { scanf( "%d", &b ); if( b == a ) ++c; else { printf( "%d %d ", c, a ); a = b; c = 1; } } printf( "%d %d\n", c, a ); } }
nyoj 628 小媛在努力 【搜索】,布布扣,bubuko.com
标签:水题
原文地址:http://blog.csdn.net/shengweisong/article/details/29797641